Skip to main content

Anonymous usage statistics collector

Project description

https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg

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 explicitly 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 len(sys.argv) < 2:
        pass
    elif 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.PYTHON_VERSION,    # Python version info
        usagestats.SESSION_TIME,      # Time since Stats object was created
    )


if __name__ == '__main__':
    main()

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.

Server

To collect the reports, any server will do; the reports are uploaded via POST as a LF-separated list of key:value pairs. A simple script for mod_wsgi is included; it writes each report to a separate file. Writing your own implementation in your language of choice (PHP, Java) with your own backend should be fairly straightforward.

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-1.0.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

usagestats-1.0-py2.py3-none-any.whl (10.6 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: usagestats-1.0.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/41.1.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.7.5

File hashes

Hashes for usagestats-1.0.tar.gz
Algorithm Hash digest
SHA256 e52b1d9a08dd57fdde88882e3c2dc24d792ab7b898dbdf2f47a57a7daaa7c322
MD5 579fd0e4bd1e644cf57743d49af572a1
BLAKE2b-256 b55e2a8c3dd96f143dd566468eda0defcc4ec61dc628d3339d269f147641a052

See more details on using hashes here.

File details

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

File metadata

  • Download URL: usagestats-1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/41.1.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.7.5

File hashes

Hashes for usagestats-1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b5b4dd984299cc4d4d76da59f776ea10c80f9346859e524785909e12f9c7e476
MD5 e1ba1e8f7aca57e18733aca36f4ff1ee
BLAKE2b-256 5d920ed84a211cd9869e9e1e3643ccf47d429ebd594f5f43111d42712ff6516b

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