A middleware for your ASGI application that enables Umami analytics.
Project description
ASGI Middleware for Umami Analytics
This project provides a middleware for your ASGI-compatible app (e.g. FastAPI, Starlette) that automatically sends access events to your umami instance. If you want to track your API clients in a GDPR-friendly way, then this middleware is for you.
Usage
For this middleware, you need the following information:
- The URL of your Umami API (e.g.
https://umami.example.com/api - The website GUID (e.g.
12345678-1234-1234-1234-123456789012)
Install the package via pip:
pip install umami-asgi
Then, you can add the umami middleware to your ASGI app. Here is an example for FastAPI:
from fastapi import FastAPI
from umami_asgi import UmamiMiddleware
app = FastAPI()
app.add_middleware(
UmamiMiddleware,
api_url="https://umami.example.com/api",
website_id="12345678-1234-1234-1234-123456789012"
)
For more extensive examples, see the examples directory.
Try it out
In the examples directory, you can find examples for FastAPI and Starlette
that you can try out easily. First, create a .env file in the examples
directory with the following content:
UMAMI_API_ENDPOINT="https://example.com/api"
UMAMI_SITE_ID="your-site-id"
Then, install the necessary dependencies and run the example:
pip install uvicorn python-dotenv fastapi starlette
# FastAPI:
python -m uvicorn examples.fastapi_app:app --env-file examples/.env
# Starlette:
python -m uvicorn examples.starlette_app:app --env-file examples/.env
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file umami_asgi-0.2.0.tar.gz.
File metadata
- Download URL: umami_asgi-0.2.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1f9d7c414bb4b496c44cbaeba33cab4134dacdefb355402e988395adaf74ba2
|
|
| MD5 |
dd117092b5a9a42906b57756d68d6d3f
|
|
| BLAKE2b-256 |
9c5ef51a754e9a6245e06b7a653076a453af59438dd0187d0a82d3ceb293b8a2
|
File details
Details for the file umami_asgi-0.2.0-py3-none-any.whl.
File metadata
- Download URL: umami_asgi-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db5c894770b0e31118c7eb0b9dbe1b71f9f07eb038eec3520cdb176af61b2be7
|
|
| MD5 |
ff957beb7d75497dfec30752c6a750b4
|
|
| BLAKE2b-256 |
06ba6ac191cab558443d331ff8a5a6d7f07cdb279167aa2ce3d5c43a0a5b6e02
|