Skip to content

Latest commit

 

History

History
92 lines (74 loc) · 2.77 KB

README.md

File metadata and controls

92 lines (74 loc) · 2.77 KB

Python Mozscape API

For more information on the Mozscape API in general, please consult the Mozscape API Help.

The current module supports both Python 2 and 3.

Installation instructions

git clone https://github.com/seomoz/SEOmozAPISamples.git
cd SEOmozAPISamples/python
pip install . # or alternatively python setup.py install

Alternatively, you can install directly from GitHub using this invocation:

pip install git+https://github.com/seomoz/SEOmozAPISamples.git#egg=mozscape&subdirectory=python

General

The Mozscape class is initialized with your access id and your secret key, and then can be used to make API calls:

from mozscape import Mozscape
client = Mozscape('my_access_id', 'my_secret_key')
# Now I can make API calls!

All calls in this class return the deserialized json objects that the API returns. Typically these are either dictionaries, or lists of dictionaries. For the meaning of each of the resultant keys, and the bit flags for the columns you can request, consult the Help.

URL Metrics

The first API call exposed is URL Metrics. It can provide summary information on a single (via a GET) or multiple (via a POST) url or urls.

# Let's get some URL metrics. Results are now an array of
# dictionaries the i'th dictionary is the results for the i'th URL
metrics = client.urlMetrics(['www.moz.com', 'www.moz.com'])
# Now let's say we only want specific columns in the results
authorities = client.urlMetrics(
    ['www.moz.com'],
    Mozscape.UMCols.domainAuthority | Mozscape.UMCols.pageAuthority)
# Or if you just need results for one URL
mozMetrics = client.urlMetrics('www.moz.com')

Anchor Text

Next exposed is the Anchor Text call, which returns a set of anchor text terms of phrases aggregated across links to a page or domain.

# Now for some anchor text results
anchorResults = client.anchorText('www.moz.com/blog')
# Or for just specific columns
anchorTermResults = client.anchorText(
    'www.moz.com/blog', cols=Mozscape.ATCols.term)

Links

Lastly, we have the Links call, which returns a set of links to a page or domain.

# Now for some links results
links = client.links('www.moz.com')
# The links API has more columns to specify, as well as sort, scope, etc.
links = client.links(
    'wwww.moz.com', scope='domain_to_domain', sort='domain_authority',
    filters=['external', 'nofollow'], targetCols = Mozscape.UMCols.url)