API¶
Session¶
-
class
atomx.Atomx(email, password, totp=None, api_endpoint='https://api.atomx.com/v3', save_response=True, expiration=None)¶ Interface for the api on api.atomx.com.
To learn more about the api visit the atomx wiki
Parameters: - email (str) – email address of your atomx user
- password (str) – password of your atomx user
- totp (str) – 6 digit auth token if the account has 2-factor authentication enabled.
- api_endpoint (str) – url for connections to the api (defaults to https://api.atomx.com/{API_VERSION})
- save_response (bool) – If True save the last api response meta info
(without the resource payload) in
Atomx.last_response. (default: True)
Returns: Atomxsession to interact with the api-
create(model)¶ Alias for
models.AtomxModel.create()with session argument.
-
delete(resource, *args, **kwargs)¶ Send HTTP DELETE to
resource.Parameters: - resource – Name of the resource to DELETE.
- args – All non-keyword arguments will be used to compute the final
resource. - kwargs – Optional keyword arguments will be passed as query string to the delete request.
Returns: message or resource returned by the api.
-
get(resource, *args, **kwargs)¶ Returns a list of models from
modelsif you query for multiple models or a single instance of a model frommodelsif you query for a specific idParameters: - resource (str) –
Specify the resource to get from the atomx api.
Examples:
Query all advertisers:
>>> atomx = Atomx('apiuser@example.com', 'password') >>> advertisers = atomx.get('advertisers') >>> assert isinstance(advertisers, list) >>> assert isinstance(advertisers[0], atomx.models.Advertiser)
Get publisher with id 23:
>>> publisher = atomx.get('publisher/23') >>>> # or get the same publisher using the id as parameter >>> publisher = atomx.get('publisher', 23) >>>> # or use an atomx model >>> publisher = atomx.get(atomx.models.Publisher(23)) >>> assert publisher.id == 23 >>> assert isinstance(publisher, atomx.models.Publisher)
Get all profiles for advertiser 42:
>>> profiles = atomx.get('advertiser/42/profiles') >>> assert isinstance(profiles, list) >>> assert isinstance(profiles[0], atomx.models.Profile) >>> assert profiles[0].advertiser.id == 42
- args –
All non-keyword arguments will get used to compute the
resource. This makes it easier if you want to work with a variable resource path.advertiser_id = 42 attribute = 'profiles' profiles = atomx.get('advertiser', advertiser_id, attribute) # is equivalent to atomx.get('advertiser/42/profiles')
- kwargs –
Any argument is passed as URL parameter to the respective api endpoint. See API URL Parameters in the wiki.
Example: Get the first 20 domains that contain
atom:>>> atom_domains = atomx.get('domains', hostname='*atom*', limit=20) >>> assert len(atom_domains) == 20 >>> assert 'atom' in atom_domains[1].hostname
Returns: a class from
modelsor a list of models depending on param resource- resource (str) –
-
last_response= None¶ Contains the response of the last api call, if save_response was set True
-
login(email, password, totp=None, expiration=None)¶ Gets new authentication token for user
email.This method is automatically called in
__init__()so you rarely have to call this method directly.Parameters: Returns: None
Raises: exceptions.InvalidCredentialsifemail/passwordis wrong
-
logout()¶ Removes authentication token from session.
-
post(resource, json, **kwargs)¶ Send HTTP POST to
resourcewithjsoncontent.Used by
models.AtomxModel.create().Parameters: - resource – Name of the resource to POST to.
- json – Content of the POST request.
- kwargs – URL Parameters of the request.
Returns: dictwith the newly created resource.
-
put(resource, id, json, **kwargs)¶ Send HTTP PUT to
resource/idwithjsoncontent.Used by
models.AtomxModel.save().Parameters: - resource – Name of the resource to PUT to.
- id – Id of the resource you want to modify
- json – Content of the PUT request.
- kwargs – URL Parameters of the request.
Returns: dictwith the modified resource.
-
remove(model)¶ Alias for
models.AtomxModel.delete()with session argument.
-
report(scope=None, groups=None, metrics=None, where=None, from_=None, to=None, daterange=None, timezone='UTC', emails=None, when=None, interval=None, name=None, sort=None, limit=None, offset=None, save=True, editable=False)¶ Create a report.
See the reporting atomx wiki for details about parameters and available groups, metrics.
Parameters: - scope (str) – Specifies the report type. Should be one of: ‘advertiser’, ‘publisher’, ‘inventory’, ‘dsp’, ‘network_managed’, ‘network_buy’, ‘network_sell’. If undefined it tries to determine the scope automatically based on the access rights of the api user.
- groups (list) – columns to group by.
- metrics (list) – columns to sum on.
- where (list) –
is a list of expression lists. An expression list is in the form of
[column, op, value]:columncan be any of thegroupsormetricsparameter columns.opcan be any of==,!=,<,>,inornot inas a string.valueis either a number or in case ofinandnot ina list of numbers.
- from (datetime.datetime) –
datetime.datetimewhere the report should start (inclusive). (Defaults to last week) - to (datetime.datetime) –
datetime.datetimewhere the report should end (exclusive). (Defaults to datetime.now() if undefined) - daterange (str) – Use :param:`daterange` to automatically set the reports
from and to parameters relativ to the current date. Both :param:`from_` and :param:`to` have to be
Nonefor it. Dateranges are: today, yesterday, last7days, last14days, last30days, monthtodate,lastmonth, yeartodate, lifetime. (Defaults toNone)Parameters: - timezone (str) – Timezone used for all times. (Defaults to UTC) For a supported list see https://wiki.atomx.com/timezones
- emails (str or list) – One or multiple email addresses that should get notified once the report is finished and ready to download.
- when (str) – When should the scheduled report run. (daily, monthly, monday-sunday)
- interval (str) – Time period included in the scheduled report (‘N days’ or ‘N month’)
- name (str) – Optional name for the report.
- or list sort (str) – List of columns to sort by.
- limit (int) – Number of rows to return
- offset (int) – Number of rows to skip.
- save (bool) – Should the report appear in the users report history (defaults to True).
- editable (bool) – Should other users be able to change the date range of this report.
Returns: A
atomx.models.Reportmodel
-
save(model)¶ Alias for
models.AtomxModel.save()with session argument.
-
search(query, index=None)¶ Search for
query.Returns a dict with all found results for: ‘Advertisers’, ‘Campaigns’, ‘Creatives’, ‘Placements’, ‘Publishers’, ‘Sites’.
The resulting
modelshave only id and name loaded since that’s what’s returned from the api /search call, but attributes will be lazy loaded once you try to accessed them. Or you can just fetch everything with one api call withAtomxModel.reload().Example:
>>> atomx = Atomx('apiuser@example.com', 'password') >>> search_result = atomx.search('atomx') >>> assert 'campaigns' in search_result >>> campaign = search_result['campaigns'][0] >>> assert isinstance(campaign, models.Campaign) >>> # campaign has only `id` and `name` loaded but you >>> # can still access (lazy load) all attributes >>> assert isinstance(campaign.budget, float) >>> # or reload all attributes with one api call >>> campaign.reload()
Parameters: Returns: dict with list of
modelsas values
Models¶
-
class
atomx.models.AtomxModel(id=None, session=None, **attributes)¶ A generic atomx model that the other models from
atomx.modelsinherit from.Parameters: - id (int) – Optional model ID. Can also be passed in via attributes as id.
- session (atomx.Atomx) – The
atomx.Atomxsession to use for the api requests. - attributes – model attributes
-
create(session=None)¶ POST the model to the api and populates attributes with api response.
Parameters: session – The atomx.Atomxsession to use for the api call. (Optional if you specified a session at initialization)Returns: selfReturn type: AtomxModel
-
delete(session=None)¶ DELETE the model in the api. A deleted attribute is to
Trueonselfso you can check if aAtomxModelis deleted or not.Warning
Calling this method will permanently remove this model from the API.
Parameters: session – The atomx.Atomxsession to use for the api call. (Optional if you specified a session at initialization)Returns: A dictof all models that the API removed. Keys are the model names and values are a list of IDs.Return type: dict
-
history(session=None, offset=0, limit=100, sort='date.asc')¶ Show the changelog of the model.
Parameters: - session – The
atomx.Atomxsession to use for the api call. (Optional if you specified a session at initialization) - offset (int) – Skip first
offsethistory entries. (default: 0) - limit (int) – Only return
limithistory entries. (default: 100) - sort (str) – Sort by date.asc or date.desc. (default: ‘date.asc’)
Returns: list of dict`s with `date, user and the attributes that changed (history).
Return type: - session – The
-
reload(session=None, **kwargs)¶ Reload the model from the api and update attributes with the response.
This is useful if you have not all attributes loaded like when you made an api request with the attributes parameter or you used
atomx.Atomx.search().Parameters: session – The atomx.Atomxsession to use for the api call. (Optional if you specified a session at initialization)Returns: selfReturn type: AtomxModel
-
save(session=None)¶ PUT the model to the api and update attributes with api response.
Parameters: session – The atomx.Atomxsession to use for the api call. (Optional if you specified a session at initialization)Returns: selfReturn type: AtomxModel
-
update(session=None)¶ Alias for
AtomxModel.save().
-
class
atomx.models.AccountManager(id=None, session=None, **attributes)¶ AtomxModelfor AccountManager
-
class
atomx.models.Advertiser(id=None, session=None, **attributes)¶ AtomxModelfor Advertiser
-
class
atomx.models.App(id=None, session=None, **attributes)¶ AtomxModelfor App
-
class
atomx.models.Appstore(id=None, session=None, **attributes)¶ AtomxModelfor Appstore
-
class
atomx.models.Bidder(id=None, session=None, **attributes)¶ AtomxModelfor Bidder
-
class
atomx.models.Browser(id=None, session=None, **attributes)¶ AtomxModelfor Browser
-
class
atomx.models.CampaignDebugReason(id=None, session=None, **attributes)¶ AtomxModelfor CampaignDebugReason
-
class
atomx.models.Campaign(id=None, session=None, **attributes)¶ AtomxModelfor Campaign
-
class
atomx.models.Category(id=None, session=None, **attributes)¶ AtomxModelfor Category
-
class
atomx.models.ConnectionType(id=None, session=None, **attributes)¶ AtomxModelfor ConnectionType
-
class
atomx.models.City(id=None, session=None, **attributes)¶ AtomxModelfor City
-
class
atomx.models.ConversionPixel(id=None, session=None, **attributes)¶ AtomxModelfor ConversionPixel
-
class
atomx.models.Country(id=None, session=None, **attributes)¶ AtomxModelfor Country
-
class
atomx.models.Creative(id=None, session=None, **attributes)¶ AtomxModelfor Creative
-
class
atomx.models.CreativeAttribute(id=None, session=None, **attributes)¶ AtomxModelfor CreativeAttribute
-
class
atomx.models.Datacenter(id=None, session=None, **attributes)¶ AtomxModelfor Datacenter
-
class
atomx.models.DeviceType(id=None, session=None, **attributes)¶ AtomxModelfor DeviceType
-
class
atomx.models.Domain(id=None, session=None, **attributes)¶ AtomxModelfor Domain
-
class
atomx.models.Dma(id=None, session=None, **attributes)¶ AtomxModelfor Dma
-
class
atomx.models.Dsp(id=None, session=None, **attributes)¶ AtomxModelfor Dsp
-
class
atomx.models.Fallback(id=None, session=None, **attributes)¶ AtomxModelfor Fallback
-
class
atomx.models.Isp(id=None, session=None, **attributes)¶ AtomxModelfor Isp
-
class
atomx.models.Languages(id=None, session=None, **attributes)¶ AtomxModelfor Languages
-
class
atomx.models.Network(id=None, session=None, **attributes)¶ AtomxModelfor Network
-
class
atomx.models.OperatingSystem(id=None, session=None, **attributes)¶ AtomxModelfor OperatingSystem
-
class
atomx.models.Placement(id=None, session=None, **attributes)¶ AtomxModelfor Placement
-
class
atomx.models.PlacementType(id=None, session=None, **attributes)¶ AtomxModelfor PlacementType
-
class
atomx.models.PriceModel(id=None, session=None, **attributes)¶ AtomxModelfor PriceModel
-
class
atomx.models.Profile(id=None, session=None, **attributes)¶ AtomxModelfor Profile
-
class
atomx.models.Publisher(id=None, session=None, **attributes)¶ AtomxModelfor Publisher
-
class
atomx.models.Reason(id=None, session=None, **attributes)¶ AtomxModelfor Reason
-
class
atomx.models.Report(id, query=None, name=None, emails=None, length=None, totals=None, columns=None, created_at=None, data=None, user_id=None, session=None, is_scheduled_report=False, to=None, from_=None, **kwargs)¶ Represents a report you get back from
atomx.Atomx.report().-
delete(session=None)¶ Delete report
-
pandas¶ Returns the content of the report as a pandas data frame.
-
save(session=None)¶ Update report name and emails
-
-
class
atomx.models.Segment(id=None, session=None, **attributes)¶ AtomxModelfor Segment
-
class
atomx.models.SellerProfile(id=None, session=None, **attributes)¶ AtomxModelfor SellerProfile
-
class
atomx.models.Site(id=None, session=None, **attributes)¶ AtomxModelfor Site
-
class
atomx.models.Size(id=None, session=None, **attributes)¶ AtomxModelfor Size
-
class
atomx.models.Ssp(id=None, session=None, **attributes)¶ AtomxModelfor Ssp
-
class
atomx.models.SspResultType(id=None, session=None, **attributes)¶ AtomxModelfor SspResultType
-
class
atomx.models.SspSuspicious(id=None, session=None, **attributes)¶ AtomxModelfor SspSuspicious
-
class
atomx.models.Timezone(id=None, session=None, **attributes)¶ AtomxModelfor Timezone
-
class
atomx.models.User(id=None, session=None, **attributes)¶ AtomxModelfor User
-
class
atomx.models.Visibility(id=None, session=None, **attributes)¶ AtomxModelfor Visibility
-
class
atomx.models.Zipcode(id=None, session=None, **attributes)¶ AtomxModelfor Zipcode
-
class
atomx.models.Report(id, query=None, name=None, emails=None, length=None, totals=None, columns=None, created_at=None, data=None, user_id=None, session=None, is_scheduled_report=False, to=None, from_=None, **kwargs) Represents a report you get back from
atomx.Atomx.report().-
delete(session=None) Delete report
-
pandas Returns the content of the report as a pandas data frame.
-
save(session=None) Update report name and emails
-
Exceptions¶
-
exception
atomx.exceptions.APIError¶ Raised when the atomx api returns an error that is not caught otherwise.
-
exception
atomx.exceptions.InvalidCredentials¶ Raised when trying to login with the wrong e-mail or password.
-
exception
atomx.exceptions.MissingArgumentError¶ Raised when argument is missing.
-
exception
atomx.exceptions.ModelNotFoundError¶ Raised when trying to (re-)load a model that is not in the api.
-
exception
atomx.exceptions.NoPandasInstalledError¶ Raised when trying to access
report.pandaswithoutpandasinstalled.
-
exception
atomx.exceptions.NoSessionError¶ Raised when a model from
modelswants tocreate/updatebut it doesn’t have anatomx.Atomxsession yet.