Skip to content
This repository was archived by the owner on Jun 11, 2024. It is now read-only.

Commit da1b79a

Browse files
committed
added documentation
first release
1 parent 3905e3f commit da1b79a

8 files changed

Lines changed: 233 additions & 7 deletions

File tree

CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
0.1
1+
1.0
22
---
33

44
- First release

README.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ Python Atomx Api
22
================
33

44
Interface for the atomx rest api.
5-
`atomx wiki <http://wiki.atomx.com/doku.php?id=api>`_
5+
6+
For more information read the full
7+
`documentation online <http://atomx-api-python.readthedocs.org/en/latest/index.html>`_,
8+
report bugs in `github <https://github.com/atomx/atomx-api-python>`_
9+
or see the `atomx wiki <http://wiki.atomx.com/doku.php?id=api>`_
610

711

812
Example Usage

atomx/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def get(self, limit=None, sort=None):
213213
214214
:param int limit: limit the amount of lines to return (defaults to no limit)
215215
:param str sort: defines the sort order of the report content.
216-
``sort`` can be `column_name`[.asc|.desc][,column_name[.asc|.desc]]...
216+
``sort`` can be `column_name`[.asc|.desc][,column_name[.asc|.desc]]`...
217217
:return: report content
218218
"""
219219
if not self.is_ready:

atomx/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
VERSION = '0.1.0'
1+
VERSION = '1.0.0'
22
API_VERSION = 'v1'

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@
6161
# built documents.
6262
#
6363
# The short X.Y version.
64-
version = '0.1'
64+
version = '1.0'
6565
# The full version, including alpha/beta/rc tags.
66-
release = '0.1'
66+
release = '1.0'
6767

6868
# The language for content autogenerated by Sphinx. Refer to documentation
6969
# for a list of supported languages.

docs/front.rst

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
11
.. _front:
22

3-
.. include:: ../README.rst
3+
Front Matter
4+
============
5+
6+
:mod:`atomx` is a python interface for the `atomx`_ rest api.
7+
8+
With it you can easily query, create or update resources on `atomx`_.
9+
10+
11+
Project Info
12+
------------
13+
14+
The python `atomx` package is hosted on `github <https://github.com/atomx/atomx-api-python>`_.
15+
16+
Releases and project status are available on `Pypi <http://pypi.python.org/pypi/atomx>`_.
17+
18+
The most recent published version of this documentation is at
19+
`<http://atomx-api-python.readthedocs.org/en/latest/index.html>`_.
20+
21+
See the `atomx wiki <http://wiki.atomx.com/doku.php?id=api>`_
22+
for more general information about the `atomx api`.
23+
24+
25+
Installation
26+
------------
27+
28+
To install the python atomx api, simply:
29+
30+
.. code-block:: bash
31+
32+
$ pip install atomx
33+
34+
or if you want to use ipython notebook and reporting functionality:
35+
36+
.. code-block:: bash
37+
38+
$ pip install atomx[report]
39+
40+
41+
.. _atomx: https://www.atomx.com

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Contents:
1010
:maxdepth: 2
1111

1212
front
13+
usage
1314
api
1415
changelog
1516

docs/usage.rst

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
Usage
2+
=====
3+
4+
Creating a session
5+
------------------
6+
7+
To work with the api you need to get a user from
8+
`atomx <https://www.atomx.com>`_ and create a
9+
:class:`atomx.Atomx` session using your email and password:
10+
11+
.. code-block:: python
12+
13+
from atomx import Atomx
14+
15+
# create atomx session
16+
atomx = Atomx('user@example.com', 'password')
17+
18+
optionally you can specify a different api endpoint for testing:
19+
20+
.. code-block:: python
21+
22+
# create atomx session with sandbox endpoint
23+
atomx = Atomx('user@example.com', 'password',
24+
api_endpoint='https://sandbox.api.atomx.com/v1')
25+
26+
27+
Fetching resources
28+
------------------
29+
30+
Use :meth:`atomx.Atomx.get` to fetch any resource from the api.
31+
The first parameter is the resource you want to query and can be any
32+
string that the `atomx api <http://wiki.atomx.com/doku.php?id=api>`_ accepts.
33+
All additional keyword arguments are used to build the query string.
34+
35+
If the returned resource (or list of resources) is any of the
36+
:mod:`atomx.models` then that model instance will be returned so
37+
you can easily work with it.
38+
39+
40+
For example to get 10 creatives and then print some information about it:
41+
42+
.. code-block:: python
43+
44+
# get 10 creatives
45+
creatives = atomx.get('Creatives', limit=10)
46+
# the result is a list of `atomx.models.Creative` models
47+
# that you can easily inspect, manipulate and update
48+
for creative in creatives:
49+
print('Creative ID: {c.id}, state: {c.state}, '
50+
'name: {c.name}, title: {c.title}'.format(c=creative))
51+
52+
Or query all profiles of advertiser 42 ordered by last updated:
53+
54+
.. code-block:: python
55+
56+
profiles = atomx.get('advertiser/42/profiles', order_by='updated_at.desc')
57+
58+
59+
Or get all domains where the hostname contains `atom`:
60+
61+
.. code-block:: python
62+
63+
domains = atomx.get('domains', name='*atom*')
64+
65+
66+
Attributes that are not loaded in the model will be lazy loaded once you
67+
try to access them.
68+
E.g. if you want to access the `quickstats` for the creative
69+
we fetched earlier you don't have to to anything special,
70+
just access the `quickstats` attribute:
71+
72+
.. code-block:: python
73+
74+
creative = creatives[0]
75+
print(creative.quickstats)
76+
77+
Or to get the advertiser for a profile, just:
78+
79+
.. code-block:: python
80+
81+
advertiser = profiles[0].advertiser
82+
83+
84+
Updating models
85+
---------------
86+
87+
To change a :mod:`atomx.models` model you just change
88+
any attribute you want and call :meth:`atomx.models.AtomxModel.save`.
89+
90+
E.g.
91+
92+
.. code-block:: python
93+
94+
# update title for the first creative in list
95+
creative = creatives[0]
96+
creative.title = 'shiny new title'
97+
creative.save()
98+
99+
# update profile click frequency
100+
profiles[0].click_frequency_cap_per = 86400
101+
profiles[0].save()
102+
103+
104+
105+
Creating models
106+
---------------
107+
108+
To add a new entry in `atomx` just instantiate any :mod:`atomx.models`
109+
model with all attributes you want your newly created model to have
110+
and either call :meth:`atomx.models.AtomxModel.create` with your
111+
:class:`atomx.Atomx` session as parameter or use
112+
:meth:`atomx.Atomx.save`.
113+
114+
E.g. create a new profile entry:
115+
116+
.. code-block:: python
117+
118+
# create a new profile
119+
from atomx.models import Profile
120+
profile = Profile(advertiser_id=23, name='test profile')
121+
# Note that you have to pass it a valid `Atomx` session for create
122+
# or use `atomx.create(profile)`
123+
profile.create(atomx)
124+
125+
126+
Search
127+
------
128+
129+
Use :meth:`atomx.Atomx.search` to search fast for anything.
130+
131+
:meth:`atomx.Atomx.search` returns a `dict` with all found results for:
132+
'Advertisers', 'Campaigns', 'Creatives', 'Placements', 'Publishers', 'Sites'.
133+
134+
The resulting :mod:`.models` have only `id` and `name` loaded since that's
135+
what's returned from the api `/search` call, but attributes will be lazy loaded
136+
once you try to accessed them.
137+
Or you can just fetch everything with one api call with :meth:`.AtomxModel.reload`.
138+
139+
Example:
140+
141+
.. code-block:: python
142+
143+
search_result = atomx.search('atomx')
144+
145+
campaign = search_result['campaigns'][0]
146+
assert isinstance(campaign, models.Campaign)
147+
148+
# campaign has only `id` and `name` loaded but you
149+
# can still access (lazy load) all attributes
150+
print(campaign.budget)
151+
print(campaign.profile)
152+
153+
# or reload all attributes with one api call
154+
campaign.reload()
155+
156+
157+
Reports
158+
-------
159+
160+
See :meth:`atomx.Atomx.report` for a description of available parameters
161+
to create a report.
162+
163+
.. code-block:: python
164+
165+
# reporting example
166+
# get a report for a specific publisher
167+
report = atomx.report(scope='publisher', groups=['hour_formatted'], sums=['impressions', 'clicks'], where=[['publisher_id', '==', 42]], from_='2015-02-08 00:00:00', to='2015-02-09 00:00:00', timezone='America/Los_Angeles')
168+
# check if report is ready
169+
print(report.is_ready)
170+
# if pandas is installed you can get the pandas dataframe with `report.pandas`
171+
# you can also get the report csv in `report.content` without pandas
172+
df = report.pandas
173+
# set index to datetime
174+
import pandas as pd
175+
df.index = pd.to_datetime(df.pop('hour_formatted'))
176+
# calculate mean, median, std per hour
177+
means = df.resample('H', how=['mean', 'median', 'std'])
178+
# and plot impression and clicks per day
179+
means['impressions'].plot()
180+
means['clicks'].plot()
181+
182+
For more general information about atomx reporting visit the
183+
`reporting atomx knowledge base entry <https://wiki.atomx.com/doku.php?id=reporting>`_.

0 commit comments

Comments
 (0)