# Django, FastAPI and Flask analytics

> Live analytics for Python apps: middleware for Django, FastAPI, Starlette and Flask sends sign-ins, crawler visits, 404s, errors, response times and your events.

Source: https://mettr.app/integrations/python

## Install

```bash
pip install mettr
```

Python 3.10 or later, no dependencies.

### Django

```python
INSTALLED_APPS = [..., "mettr.django"]
MIDDLEWARE = [..., "mettr.django.MettrMiddleware"]
```

```django
{% load mettr %}
<head>{% mettr_script %}</head>
```

### FastAPI and Starlette

```python
app.add_middleware(MettrMiddleware, mettr=Mettr())
```

### Flask

```python
mettr = MettrFlask(app)
```

## What you get without writing code

- **Page views and who is online**, from the [browser script](/docs/browser-script), served from `/_live` on your own domain, so ad blockers mostly let it through.
- **Sign-ins and sign-ups** in Django, as `login` and `signup`; staff (`is_staff`) send nothing.
- **Crawler visits**, with their page and status: only your server sees them.
- **404s and exceptions**, the latter by class only, never the message.
- **Response times** of one request in twenty, by route.

Sync and async views alike. Events go from a background thread, never in the request's way.

## Your own events

```python
mettr.event("signup", {"plan": "pro"}, Visitor(user_id="42"))
```

## Revenue from your own billing

[Stripe](/integrations/stripe), [Paddle](/integrations/paddle) and [Polar](/integrations/polar) are read by mettr itself. Billing of your own? `mettr.subscription()` sends each subscription as it changes, and MRR, churn and revenue by source follow.

## Open source

`mettr` is MIT licensed, on [GitHub](https://github.com/mettrhq/mettr-python) and [PyPI](https://pypi.org/project/mettr/). [The full guide](/docs/python).
