Skip to main content

Library for efficiently adding analytics to your project.

Project description

Py-Analytics is a library designed to make it easy to provide analytics as part of any project.

The project’s goal is to make it easy to store and retrieve analytics data. It does not provide any means to visualize this data.

Currently, only Redis is supported for storing data.

Requirements

Required

Requirements should be handled by setuptools, but if they are not, you will need the following Python packages:

  • nydus

  • redis

  • dateutil

Optional

  • hiredis

analytics.create_analytic_backend

Creates an analytics object that allows to to store and retrieve metrics:

>>> from analytics import create_analytic_backend
>>>
>>> analytics = create_analytic_backend({
>>>     'backend': 'analytics.backends.redis.Redis',
>>>     'settings': {
>>>         'defaults': {
>>>             'host': 'localhost',
>>>             'port': 6379,
>>>             'db': 0,
>>>         },
>>>         'hosts': [{'db': 0}, {'db': 1}, {'host': 'redis.example.org'}]
>>>     },
>>> })

Internally, the Redis analytics backend uses nydus to distribute your metrics data over your cluster of redis instances.

There are two required arguements:

  • backend: full path to the backend class, which should extend analytics.backends.base.BaseAnalyticsBackend

  • settings: settings required to initialize the backend. For the Redis backend, this is a list of hosts in your redis cluster.

Example Usage

from analytics import create_analytic_backend
import datetime

analytics = create_analytic_backend({
    "backend": "analytics.backends.redis.Redis",
    "settings": {
        "hosts": [{"db": 5}]
    },
})

year_ago = datetime.date.today() - datetime.timedelta(days=265)

#create some analytics data
analytics.track_metric("user:1234", "comment", year_ago)
analytics.track_metric("user:1234", "comment", year_ago, inc_amt=3)

#retrieve analytics data:
analytics.get_metric_by_day("user:1234", "comment", year_ago, limit=20)
analytics.get_metric_by_week("user:1234", "comment", year_ago, limit=10)
analytics.get_metric_by_month("user:1234", "comment", year_ago, limit=6)

#create a counter
analytics.track_count("user:1245", "login")
analytics.track_count("user:1245", "login", inc_amt=3)

#retrieve multiple metrics at the same time
#group_by is one of ``month``, ``week`` or ``day``
analytics.get_metrics([("user:1234", "login",), ("user:4567", "login",)], year_ago, group_by="day")
>> [....]

#retrieve a count
analytics.get_count("user:1245", "login")

#retrieve counts
analytics.get_counts([("user:1245", "login",), ("user:1245", "logout",)])

TODO

  • Add more backends (riak, …)?

  • Add an API so it can be deployed as a stand alone service (http, protocolbuffers, …)

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

analytics-0.3.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

analytics-0.3.0.linux-x86_64.tar.gz (16.5 kB view details)

Uploaded Source

File details

Details for the file analytics-0.3.0.tar.gz.

File metadata

  • Download URL: analytics-0.3.0.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for analytics-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d46cb1180ba375ce386faac63351aaa71ba6f1134719f983261babbfa26495ac
MD5 9325c1acb980a8cadb8b6eb1aa76c17c
BLAKE2b-256 42f87e3332330259b5d6189b8f876a2ba9c9ba3b5f527b65cde0809facffebb5

See more details on using hashes here.

File details

Details for the file analytics-0.3.0.linux-x86_64.tar.gz.

File metadata

File hashes

Hashes for analytics-0.3.0.linux-x86_64.tar.gz
Algorithm Hash digest
SHA256 290e29f277adea02fa382a58b41eeb414d747da18a46d8b93a481ab0969de912
MD5 9748e154e14553739861e562facfe939
BLAKE2b-256 261e760bf575bedf49cfe228b4d8e8263a99369f426edd0d6ce89d9a57478fb1

See more details on using hashes here.

Supported by

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