python-addthis
A Python wrapper for the AddThis Analytics API.
Requirements
Python 2.6, 2.7 or 3.2+
python-requests library
Installation
Install from PyPI:
pip install addthis
Usage
from addthis import Addthis # create an AddThis instance using userid and password from your AddThis account and optionally provide a pubid addthis = Addthis(userid="YOUR_USER_ID", password="YOUR_PASSWORD", pubid="YOUR_PUB_ID") # get the number of shares for the last day print addthis.shares.day() # get the number of shares by day for the last week print addthis.shares.day(period="week")
You can see a full description of all supported metrics and dimensions at http://support.addthis.com/customer/portal/articles/381264-addthis-analytics-api
A few more examples
How many times was my content shared on Twitter, by day, over the last week?
>>> addthis.shares.day(period="week", service="twitter")
What were my top shared urls for the pubid=”MY_PUB_ID”?
>>> addthis.shares.url(pubid="MY_PUB_ID")
How many users shared my content this month, broken down by their interests?
>>> addthis.sharers.interest(period="month")
Which sharing services sent the most clicks back to my site this week?
>>> addthis.clicks.service(period="week")
Exceptions
AddthisValidationError
Addthis object expects to be called with 2 parameters - “metric” and “dimension”:
addthis.<metric>.<dimension>()
For example:
>>> addthis.shares.day() # "shares" is a metric and "day" is a dimension
If it gets another number of parameters (e.g. addthis.shares() or addthis.shares.day.week()) it will raise an AddthisValidationError.
from addthis import Addthis, AddthisValidationError
addthis = Addthis(userid="YOUR_USER_ID", password="YOUR_PASSWORD", pubid="YOUR_PUB_ID")
try:
addthis.shares()
except AddthisValidationError as e:
print e # "Incorrect number of parameters are given. Expected 2 but got 1."
AddthisError
AddthisError is raised when AddThis service returns a response with a HTTP status code other than 200. The exception object has 4 attributes:
status_code: Code from the HTTP response.
code, message, attachment: Error attributes from the AddThis response body. (see the “Error” section in the AddThis Analytics API documentation for more information).
from addthis import Addthis, AddthisError
addthis = Addthis(userid="INCORRECT_USER_ID", password="INCORRECT_PASSWORD", pubid="INCORRECT_PUB_ID")
try:
addthis.shares.day()
except AddthisError as e:
print e # "401 Error (code = '80', message='authentication failed', attachment='{u'nonce': None, u'realm': u'AddThis', u'opaque': None})'."
print e.status_code # 401
print e.code # 80
print e.message # "authentication failed"
print e.attachment # {u'nonce': None, u'realm': u'AddThis', u'opaque': None}
Metadata
Release files for addthis 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| addthis-0.1.2.tar.gz | 6.4 kB | Without provenance | Details |
Release files / addthis-0.1.2.tar.gz
| Download URL | addthis-0.1.2.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1098f5649845fadaf245243f30e8d2f802dbfd897d5452dc1455de5e5d09bf45
|
|
BLAKE2b-256 checksum How to use checksums |
8da3a624317e26c7bf2643ca18c5d10761d6be30eb83a851adfcb0a12dd617d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for addthis 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.