Package: matomo-api
Python wrapper for the Matomo Reporting APIRelease warning for users of versions 1.0b4 and beforeThis version is not backward compatible with earlier versions since it breaks on how to
import and use it.
Previous versions used the deprecatedfrom matomo_api import *to literally enter all names
that Matomo uses in their API into the receiving namespace.
That cluttered the receiving namespace more than was preferable and introduced naming
conflicts on identifiers such asformatanddate.This version departs from this approach and uses the standardimport matomo_apiinstead.
This necessitates qualifying all API identifiers with the name of the module,
or an alias as set by usingimport matomo_api as ma.
See the usage example below for further details.IntroductionThis Python wrapper is based on (scraped) information from Matomo'sdeveloperandglossarysites, together with the contents of thegetReportMetadataandgetGlossaryMetricsAPI Requests.The design goal for this package has been to provide API documentation from within the Python environment.
Classes, methods and their respective docstrings have been used to facilitate this,
thus enabling IDE popup/autocomplete options to aid in setting up an API Query.Names of the API Modules, Methods, and parameters in this package follow Matomo documentation.
Since this also holds for any capitalization, this diverts from Python naming conventions.Note on terminologyPython and the Matomo API clash on some terminology. Most prone to raise confusion are the terms module and method.
To distinguish in which context these terms are used, they will be capitalized when referring to the Matomo API,
while lowercase will be used for a Python context.To add to the confusion, Matomo uses the term Module in two interpretations:Group of related API Methods, e.g. 'Actions' or 'Events'. In API Queries it is the first
part of the 'method' parameter, such as 'Actions' in method=Actions.getPageUrls.Handler of all http API Requests (request parameter is module=API) as opposed
to e.g. the handler of the web-gui (module=CoreHome).In this documentation only the first interpretation is used:a Module is a collection of API Methods.General usage instructionsInstantiate an object of theMatomoApiclass, while specifying the server url and authorization token.Select (and instantiate) an API Module by using the autocomplete/popup of your IDE on thisMatomoApiobject.Select and use a specific API Method by again using the IDE autocomplete/popup features on the selected API Module.The parameter/value combinations for the API Query can be selected by typing the parameter name,
reading potential docstrings and sub-selecting attributes or methods via IDE popups/autocompletes.
Apply these parameters by bundling them via the union operator|and use this bundle (actually a library) as
argument for the selected API Method.Wherever columns need to be specified, select them using thecolclass and sub-select via dot-notation
using (again) the IDE popup/autocomplete.Typical usage example:importmatomo_apiasmaURL='https://matomoserver.somesite.int'TOKEN='0b1c64cb1de641e36de6bc9dd658d47ab'api=ma.MatomoApi(URL,TOKEN)pars=ma.format.json|ma.language.da|ma.translateColumnNames()\|ma.idSite.one_or_more(1)|ma.date.yesterday|ma.period.day\|ma.showColumns(ma.col.date,ma.col.label)qry_result=api.Actions().getExitPageUrls(pars)Elaboration of usage exampleInstantiate the APIapi=ma.MatomoApi(URL,TOKEN)Variableapiis assigned an instance of theMatomoApiclass with actual server url and token as arguments.Documentation of this class as popup:Select and set parameterspars=ma.format.json|ma.language.da|ma.translateColumnNames()\|ma.idSite.one_or_more(1)|ma.date.yesterday|ma.period.day\|ma.showColumns(ma.col.date,ma.col.label)Variableparsis assigned a union of API parameters that build the Query.
All parameters are available as either Python class or Python function.Autocompletion for an API parameter:In case the API parameter is represented by a Python class, values are set by selecting
a class attribute or method.
The documentation guides this selection:Autocomplete for setting the values of thisformatAPI parameter:TheidSiteAPI parameter uses a class method to set multiple site id's:Some API parameters require column specifications, e.g. theshowColumnsparameter:To specify these columns, use thecolclass:Complete the Queryqry_result=api.Actions().getExitPageUrls(pars)The methods of theMatomoApiclass represent Matomo API Modules.
Use method autocomplete on theapiobject to select the API Module:Popup documentation of an API method:Upon using aMatomoApiclass method, an object is instantiated representing an API Module with all its Methods.
These API Methods can be selected via autocompletion of this 'Module' object:Most Methods of an API Module have extensive documentation.Using a Method returns the result of the API Query asResponseobject.