py-analytics

Library for efficiently adding analytics to your project
Download

py-analytics Ranking & Summary

Advertisement

  • Rating:
  • License:
  • The Apache License 2.0
  • Price:
  • FREE
  • Publisher Name:
  • Numan Sachwani
  • Publisher web site:
  • https://github.com/numan/

py-analytics Tags


py-analytics Description

py-analytics is a Python 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.analytics.create_analytic_backendCreates 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': >>> },>>> })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 Usagefrom analytics import create_analytic_backendimport datetimeanalytics = create_analytic_backend({ "backend": "analytics.backends.redis.Redis", "settings": { "hosts": },})year_ago = datetime.date.today() - datetime.timedelta(days=265)#create some analytics dataanalytics.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 counteranalytics.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(, year_ago, group_by="day")>> #retrieve a countanalytics.get_count("user:1245", "login")#retrieve countsanalytics.get_counts()Product's homepage


py-analytics Related Software