Skip to main content
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.

Metadata

Release files for usagestats 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for usagestats 1.0.1
File Size Uploaded
usagestats-1.0.1.tar.gz 16.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for usagestats 1.0.1
File Interpreter ABI Platform
usagestats-1.0.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 27.1 kB

Release files / usagestats-1.0.1.tar.gz

Download URL usagestats-1.0.1.tar.gz
Size 16.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d8887aa0f65769b1423b784e626ec6fb6ba6ed1432667e10d6115b783571be6d
BLAKE2b-256 checksum
How to use checksums
f32e76ff088361f73d09612fb9d7e64cf5b6e19a734a459828fe5f080a83709a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

Release files / usagestats-1.0.1-py2.py3-none-any.whl

Download URL usagestats-1.0.1-py2.py3-none-any.whl
Size 10.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
fc240f95c11fa06dca41d307e444b2f5e2c584e5ca0a755f63c91f697c7309db
BLAKE2b-256 checksum
How to use checksums
26a2b2a0c746d8518d7daad5800ddf25ce24b6760ca266e12b3479fdd2078d11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.5

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0

2 release files

0.8

2 release files

0.7

2 release files

0.6

2 release files

0.5

2 release files

0.4

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page