Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

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 explicitly opt in or opt out.


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',

def main():
    if len(sys.argv) < 2:
    elif sys.argv.get(1) == '--enable-stats':
    elif sys.argv.get(1) == '--disable-stats':

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

    # Report things
        # 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__':

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.


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.

Release History

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
usagestats-0.7-py2.py3-none-any.whl (8.6 kB) Copy SHA256 Checksum SHA256 py2.py3 Wheel May 31, 2017
usagestats-0.7.tar.gz (13.8 kB) Copy SHA256 Checksum SHA256 Source May 31, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting