Skip to main content

runlight

Runlight is privacy friendly web analytics that runs inside your own Python app. It counts visitors without cookies and without storing anyone’s IP address. The numbers stay in your database, and the dashboard is served from your domain at /runlight.

This package is the Python version of Runlight. It works in Django, Flask, FastAPI, or any WSGI or ASGI app on Python 3.11 or later, and it can also run on its own domain as a standalone server. It answers every request the way the TypeScript library does and uses the same tables, so either one can read the other’s database.

Get started

Install it with pip.

pip install runlight

SQLite comes with Python. For Postgres, install runlight[postgres], and for MySQL or MariaDB, runlight[mysql]. On Windows, add the tzdata extra for time zones.

Create one instance for your app.

from runlight import Runlight
from runlight.store import Stores

rl = Runlight(
    store=Stores.sqlite("data/runlight.db"),
    site={"name": "example.com", "hostnames": ["example.com"], "timezone": "Europe/London"},
)

Runlight reads the visitor's address from X-Forwarded-For and similar headers only when the request comes from this computer or a private network, where proxies and load balancers connect from, so a visitor who reaches your app straight from the internet cannot pick their own address. Behind a CDN that connects from public addresses, such as Cloudflare in front of your server, add trust_proxy="cf-connecting-ip" (the header it sets) or trust_proxy=True. Runlight logs a warning once when a public address sends forwarding headers that the default did not believe. trust_proxy=False never reads them.

Put it in front of your app. In Flask that is one line.

import runlight.flask

runlight.flask.init_app(app, rl)

Add the script to every page, just before </head>.

<script defer src="/runlight/s.js"></script>

Set RUNLIGHT_TOKEN to a long random string, then open /runlight/?token= followed by that string to sign in.

A token passed to rl.routes() works the same way. None counts as not given, so os.environ.get() of a variable that is not set falls back to RUNLIGHT_TOKEN and never opens the dashboard. To leave it open on purpose, behind your own sign-in, pass token=runlight.OPEN.

The Python guide has the code for Django, FastAPI, and plain WSGI or ASGI apps, the Postgres, MySQL, and MariaDB stores, the scheduled check, and the standalone server.

Slow request bodies

A client that sends a request body slowly, or says how long it is and then stops, is given up on wherever Runlight reads the body: after a minute in all the answer is 408 and the connection is closed.

  • The standalone server (runlight) reads every request on one thread before it gets a worker, so a slow body never takes one. The head has 10 seconds; the body then has 60 seconds in all and must keep up 8 KB a second after its first 5 seconds. A body with no Content-Length is answered 411.
  • Under ASGI (FastAPI, Starlette, and any ASGI app through runlight.asgi) the minute holds whatever the server does, for Runlight's own paths.
  • Under WSGI (Flask, Django, and any WSGI app through runlight.wsgi) the minute is checked each time the server hands over a piece of the body. A server whose reads never time out can still be held by a client that stops sending: gunicorn's sync worker ends such a request itself after its --timeout, but its gthread and gevent workers, and uWSGI without socket-timeout or harakiri, do not.
  • Django under ASGI reads the whole body before any middleware runs, and your app's own routes read their bodies themselves, so there the limits are the server's.

For the last two, put a proxy that buffers request bodies in front (nginx does by default), or set the server's own timeout.

License

Runlight is MIT licensed.

Metadata

Release files for runlight 0.5.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 runlight 0.5.1
File Size Uploaded Provenance Actions
runlight-0.5.1.tar.gz 591.8 kB Without provenance Details for runlight-0.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for runlight 0.5.1
File Interpreter ABI Platform Actions
runlight-0.5.1-py3-none-any.whl Python 3 none any Details for runlight-0.5.1-py3-none-any.whl

Total release size: 1.2 MB

Release files / runlight-0.5.1.tar.gz

Download URL runlight-0.5.1.tar.gz
Size 591.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2601cca454e9bc9b596bc2a9d205827196cd9cf8f9c033108c8e4fd19130354f
BLAKE2b-256 checksum
How to use checksums
736aa745f3539311c84748357e5d6ed7e2c9e92887329b74497d24bb7f068156
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / runlight-0.5.1-py3-none-any.whl

Download URL runlight-0.5.1-py3-none-any.whl
Size 638.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fca4702d5258b5d5426b76ca777a4981042c8c16912d145fd407f97c09e56a40
BLAKE2b-256 checksum
How to use checksums
79181ec1208bbbbecfdfeebb1a5d38719f2921f5d5b519d2e1786de9ab96ec43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for runlight 0.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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