Skip to main content

Infinario Python SDK

Project description

Infinario Python SDK
====================

.. image:: https://travis-ci.org/Infinario/python-sdk.svg
:target: https://travis-ci.org/Infinario/python-sdk
:alt: Travis CI

The `infinario.Infinario` class provides access to the Infinario Python tracking API,
supporting both synchronous and asynchronous modes.

You can install the SDK using `pip`::

pip install infinario

In order to track events, instantiate the class at least with your project token
(can be found in Project Management in your Infinario account), for example:

.. code-block:: python

from infinario import Infinario

client = Infinario('12345678-90ab-cdef-1234-567890abcdef') # PRODUCTION ENVIRONMENT
# client = Infinario('12345678-90ab-cdef-1234-567890abcdef', silent=False) # DEVELOPMENT ENVIRONMENT

We recommend to set the `silent` parameter to `False` in a development environment, as it will cause the Infinario API
to throw exceptions if something goes wrong. When left to the default value `True`, all errors will be logged
(also see the `logger` parameter).


Identifying the customer
------------------------

When tracking events, you have to specify which customer generated
them. This can be either done right when calling the client's
constructor.

.. code-block:: python

python
client = Infinario('12345678-90ab-cdef-1234-567890abcdef', customer='john123')

or by calling `identify`.

.. code-block:: python

client.identify('john123')

Tracking events
---------------

To track events for the currently selected customer, simply
call the `track` method.

.. code-block:: python

client.track('purchase')

You can also specify a dictionary of event properties to store
with the event.

.. code-block:: python

client.track('purchase', {'product': 'bottle', 'amount': 5})

Specify the POSIX timestamp of the event using:

.. code-block:: python

timestamp = time.time()

# .. time passes ..

client.track('purchase', timestamp=timestamp)

Updating customer properties
----------------------------

You can also update information that is stored with a customer.

.. code-block:: python

client.update({'first_name': 'John', 'last_name': 'Smith'})

Getting HTML from campaign
--------------------------

.. code-block:: python

client.get_html('Banner left')

will return::

'<img src="/my-awesome-banner-1.png" />'

Transport types
---------------

By default the client uses a simple non-buffered synchronous transport. The three available transport types are:
* `NullTransport` - No requests, useful for disabling tracking in the Infinario constructor.
* `SynchronousTransport` - Most operations are blocking for the time of a request to the Infinario API
* `AsynchronousTransport` - Most operations are non-blocking (see the code for more information),
buffered and using a single worker thread. Infinario client must be closed when no more data is to be tracked.

Example of choosing a transport:

.. code-block:: python

from infinario import Infinario, AsynchronousTransport

client = Infinario('12345678-90ab-cdef-1234-567890abcdef',
transport=AsynchronousTransport)

# ...

client.close()

Using on the command line
-------------------------

The python client also has a command-line interface that allows to call its essential functions:

.. code-block:: sh

TOKEN='12345678-90ab-cdef-1234-567890abcdef'
CUSTOMER='john123'

# Track event
./infinario.py track "$TOKEN" "$CUSTOMER" purchase --properties product=bottle amount=5

# Update customer properties
./infinario.py update "$TOKEN" "$CUSTOMER" first_name=John last_name=Smith

# Get HTML from campaign
./infinario.py get_html "$TOKEN" "$CUSTOMER" "Banner left"

Infinario Python Authenticated API client
=========================================

The `infinario.AuthenticatedInfinario` class provides access to the Infinario
synchronous Python authenticated API. In order to export analyses you have to instantiate client
with username and password of user that has ExtAPI access:

.. code-block:: python

from infinario import AuthenticatedInfinario

client = AuthenticatedInfinario('username', 'password')

Exporting analyses
------------------

First argument is type of analysis (funnel, report, retention, segmentation),
second argument is JSON. In case that authenticated customer has access to multiple companies use keyword argument
`token=token_of_company_with_given_analysis`

.. code-block:: python

client.export_analysis('funnel', {
'analysis_id': '2f86608f-24f5-11e3-9950-c48508494cf5'
})

will return

.. code-block:: python

{
"success": true,
"name": "Conversion funnel",
"steps": ["First visit", "Registration", "First log in", "Purchase", "Payment"],
"total": {
"counts": [48632, 24120, 20398, 1256, 1250],
"times": [-1, 680, 4502, 45, 540, 300],
"metric": 1987562
},
"drill_down": {
"type": "none",
"series": []
},
"metric": {
"step": 4,
"property": "price"
}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

infinario-1.0.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

infinario-1.0.0-py2.py3-none-any.whl (6.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file infinario-1.0.0.tar.gz.

File metadata

  • Download URL: infinario-1.0.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for infinario-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d2ca1d5d84135b44c75ed6d3634cd5a1323075ec3249a5b34ef04268a6951b21
MD5 f72414a8852d1989a65778aaa36d07ea
BLAKE2b-256 f45cfcb87fdae038aae7147aca76fafca379828248575f94acc531083c2cfd40

See more details on using hashes here.

File details

Details for the file infinario-1.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for infinario-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b144f5902f4182312d502d8fcdff21f800b37988dec3ad0a620bdf690ee3fbf4
MD5 91a9e3a61dbb76c30fa3c35fee26a8d3
BLAKE2b-256 d1159a4329e4708225d4177c9fef30fb90a9969b049bc899f3a8eb74ddae257e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page