Skip to main content

Implements a powerful analytics library using Redis bitmaps.

Project description

bitmapist

Implements a powerful analytics library using Redis bitmaps.

This library makes it possible to implement real-time, highly scalable analytics that can answer following questions:

  • Has user 123 been online today? This week? This month?

  • Has user 123 performed action “X”?

  • How many users have been active have this month? This hour?

  • How many unique users have performed action “X” this week?

  • How many % of users that were active last week are still active?

  • How many % of users that were active last month are still active this month?

This library is very easy to use and enables you to create your own reports easily.

Using Redis bitmaps you can store events for millions of users in a very little amount of memory (megabytes). You should be careful about using huge ids (e.g. 2^32 or bigger) as this could require larger amounts of memory.

Now with Cohort charts! Read more here:

If you want to read more about bitmaps please read following:

Requires Redis 2.6+ and newest version of redis-py.

Examples

Setting things up:

from datetime import datetime, timedelta
from bitmapist import setup_redis, delete_all_events, mark_event,                          MonthEvents, WeekEvents, DayEvents, HourEvents,                          BitOpAnd, BitOpOr

now = datetime.utcnow()
last_month = datetime.utcnow() - timedelta(days=30)

Mark user 123 as active and has played a song:

mark_event('active', 123)
mark_event('song:played', 123)

Answer if user 123 has been active this month:

assert 123 in MonthEvents('active', now.year, now.month)
assert 123 in MonthEvents('song:played', now.year, now.month)
assert MonthEvents('active', now.year, now.month).has_events_marked() == True

How many users have been active this week?:

print len(WeekEvents('active', now.year, now.isocalendar()[1]))

Perform bit operations. How many users that have been active last month are still active this month?:

active_2_months = BitOpAnd(
    MonthEvents('active', last_month.year, last_month.month),
    MonthEvents('active', now.year, now.month)
)
print len(active_2_months)

# Is 123 active for 2 months?
assert 123 in active_2_months

Work with nested bit operations (imagine what you can do with this ;-)):

active_2_months = BitOpAnd(
    BitOpAnd(
        MonthEvents('active', last_month.year, last_month.month),
        MonthEvents('active', now.year, now.month)
    ),
    MonthEvents('active', now.year, now.month)
)
print len(active_2_months)
assert 123 in active_2_months

# Delete the temporary AND operation
active_2_months.delete()

As something new tracking hourly is disabled (to save memory!) To enable it as default do:

import bitmapist
bitmapist.TRACK_HOURLY = True

Additionally you can supply an extra argument to mark_event to bypass the default value:

mark_event('active', 123, track_hourly=False)

Copyright: 2012 by Doist Ltd.

Developer: Amir Salihefendic ( http://amix.dk )

License: BSD

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

bitmapist-3.107.tar.gz (16.3 kB view details)

Uploaded Source

Built Distribution

bitmapist-3.107-py3-none-any.whl (46.2 kB view details)

Uploaded Python 3

File details

Details for the file bitmapist-3.107.tar.gz.

File metadata

  • Download URL: bitmapist-3.107.tar.gz
  • Upload date:
  • Size: 16.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for bitmapist-3.107.tar.gz
Algorithm Hash digest
SHA256 ade0a22b98118929e99f3d19c5a3be34ce256c57cd093c8273ead7460212a488
MD5 45447001a906f027b601b8747db40d7b
BLAKE2b-256 411739ca702131fb91f344b1cb80a7680095a12b7786a1543c5e549fba79dee2

See more details on using hashes here.

Provenance

File details

Details for the file bitmapist-3.107-py3-none-any.whl.

File metadata

  • Download URL: bitmapist-3.107-py3-none-any.whl
  • Upload date:
  • Size: 46.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.9.16 Linux/5.15.0-1036-azure

File hashes

Hashes for bitmapist-3.107-py3-none-any.whl
Algorithm Hash digest
SHA256 ad4945e34fd637bd4ed4739d351a01c167c3ea0561e8a4e392432933e5dd54f0
MD5 70ddc01fb693e6e5881d814ff31dc7bc
BLAKE2b-256 e7fef4a1970b9f8d1c6655f64ce1268afbb859fb55a4d9f77aad1626f22c3d60

See more details on using hashes here.

Provenance

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