Skip to main content

Anonymous usage statistics collecter

Project description

This package is meant to easily get usage statistics from the users of your program.

Statistics will be collected but won’t be uploaded until the user opts in. A message will be printed on stderr asking the user to explicitely opt in or opt out.

Usage

You can easily collect information from your program by adding usagestats to your project’s requirements and using the library. Here is an example:

import usagestats
import sys


optin_prompt = usagestats.Prompt(enable='cool_program --enable-stats',
                                 disable='cool_program --disable-stats')

# Location where to store stats
# Also allocates a unique ID for the user
# The version is important, since the information you log (or the format)
# might change in later versions of your program
stats = usagestats.Stats('~/.myprog/usage_stats',
                         optin_prompt,
                         'https://usagestats.example.org/',
                         unique_user_id=True,
                         version='0.1')


def main():
    if sys.argv.get(1) == '--enable-stats':
        stats.enable_reporting()
        sys.exit(0)
    elif sys.argv.get(1) == '--disable-stats':
        stats.disable_reporting()
        sys.exit(0)

    if sys.version_info < (3,):
        # Stores some info, will be reported when submit() is called
        stats.note({'mode': 'compatibility'})

    # Report things
    stats.submit(
        # Dictionary containing the info
        {'what': 'Ran the program'},
        # Flags making usagestats insert more details
        usagestats.OPERATING_SYSTEM,  # Operating system/distribution
        usagestats.SESSION_TIME,      # Time since Stats object was created
    )

submit() will, by default, store the info in the specified directory. Nothing will be reported until the user opts in; a message will simply be printed to stderr:

Uploading usage statistics is currently DISABLED
Please help us by providing anonymous usage statistics; you can enable this
by running:
    cool_program --enable-stats
If you do not want to see this message again, you can run:
    cool_program --disable-stats
Nothing will be uploaded before you opt in.

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

usagestats-0.1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

usagestats-0.1-py2.py3-none-any.whl (6.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file usagestats-0.1.tar.gz.

File metadata

  • Download URL: usagestats-0.1.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for usagestats-0.1.tar.gz
Algorithm Hash digest
SHA256 021f42aa327575ff699a0d2aa31c5bfcdc1cd05610ee71beb7988fbb5ff95127
MD5 ee48aa6735ffee95cf5c03344fdee5c3
BLAKE2b-256 4b44744597916835bb1f228b89f9f213a2edc4aeb62fa1fc3eff7f994c38b74c

See more details on using hashes here.

File details

Details for the file usagestats-0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for usagestats-0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c21a5baf91d9ce88e8c47242d836f341cac8175d7f98ccf3f7154df2f261032c
MD5 01c797ad52350db85ebd855ad5d1a7fe
BLAKE2b-256 9bc8dad6a96e4003fbadebb2e0c9f854e10e88300e91164cbcb2c78ac2887296

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