The Analytics class from the module provides access to the Mapbox Analytics API. You can also import it directly from the mapbox module.

Note: This API is available only for premium and enterprise plans.

>>> from mapbox import Analytics

See for general documentation of the API.

Your Mapbox access token should be set in your environment; see the access tokens documentation for more information.

Analytics methods

The methods of Analytics class that provide access to the Analytics API return an instance of requests.Response. Analytics response also include the json() method which returns Python data parsed from API.


The Mapbox Analytics API is used to get API usage for services by resource. It returns counts per day for given resource and period.

>>> analytics = Analytics()

The input to analytics method are resource_type, username, id, period, access_token.

>>> response ='accounts', 'mapbox-sdk-py-user')
>>> response.status_code