# Set up Relia in a Python app

> Add Relia to a FastAPI, Django or Flask app with one command, so its requests, errors and database calls show up in Relia.

Section: Set up your stack · Page: https://tryrelia.com/docs/python-setup · Last checked against the product: 2026-11-01
Video walkthrough: https://youtu.be/T7V5zFjMhjg

This page sets Relia up by hand from a terminal. To have your AI assistant do it instead, see [Set up Relia with your AI assistant](https://tryrelia.com/docs/setup-with-ai-assistant.md).

## Before you start

- A Relia account ([Create your account](https://tryrelia.com/docs/create-account.md)).
- Python 3.9 or newer.
- A terminal open in your app's folder, with your app's virtual environment active.

## Steps

1. **Install the package and run the setup:**

   ```bash
   pip install relia-sdk
   relia init
   ```

   `python -m relia` runs the same setup if the `relia` command isn't on your path.

2. **Sign in.** Choose the browser option, copy the token from the **CLI Authentication** page, and paste it back into the terminal.

3. **Choose what to monitor:** **API & Request APM (FastAPI / Flask / Django)**.

4. **Pick your Relia project**, or create one right there. Then pick a service, or create one. The service is the name your app shows under in Relia.

5. **Check what it wrote:**
   - Your `.env` gets `RELIA_PROJECT_ID`, `RELIA_KEY`, `RELIA_SERVICE_NAME` and `RELIA_OTLP_ENDPOINT`.
   - A new file, `relia_tracing.py`, starts Relia.
   - **FastAPI:** your entry file (for example `main.py`) gets two lines at the top that start Relia, and one line right after `app = FastAPI(...)`.
   - **Flask:** `ReliaFlask(app)` is added after your app is created.
   - **Django:** `relia.integrations.django.ReliaDjangoMiddleware` goes first in `MIDDLEWARE`, in `settings.py`.

6. **Answer "Tell Relia who your users are?"** Say yes if your app has sign-in. The setup prints the line to add; see [Identify your users](https://tryrelia.com/docs/identify-users.md).

   > **Tip:** watch [See which customers a bug hit: identify users in Relia](https://youtu.be/1mIOiHnI9nk) (2 min).

7. **Start your app** (for example with `uvicorn`) and call one of its endpoints.

> **Tip:** for the framework's own request tracing, install the matching extra: `pip install "relia-sdk[fastapi]"`, `"relia-sdk[flask]"` or `"relia-sdk[django]"`.

## Set it up by hand instead

At the very top of your entry module, before your framework is imported:

```python
import relia
relia.start(project_id="<your project id>", service_name="my-api")
```

Then, depending on your framework:

```python
# FastAPI: after app = FastAPI()
from relia.integrations.fastapi import instrument_fastapi
instrument_fastapi(app, project_id="<your project id>", service_name="my-api")

# Flask: after app = Flask(__name__)
from relia.integrations.flask import ReliaFlask
ReliaFlask(app)
```

For Django, add `"relia.integrations.django.ReliaDjangoMiddleware"` first in `MIDDLEWARE`. Put your project key in the server's environment as `RELIA_KEY`. Your project's id and key are on your project page under **Setup Guide & SDK**.

## What Relia records

- Every request with its route template (`/orders/{id}`, never one row per id), status and time.
- Errors with their stack traces.
- Outgoing calls made with `requests`, `httpx` and `aiohttp`.
- Database calls (PostgreSQL, MySQL, MongoDB, Redis, SQLAlchemy), with values removed.
- Celery tasks and AWS calls.
- Log records at WARNING and above. `RELIA_LOG_LEVEL` changes the level; `RELIA_LOGS=0` turns logs off.
- Calls to AI models in your product. See [Monitor AI calls in your app](https://tryrelia.com/docs/ai-calls-setup.md).

## Settings

| Variable | What it does | Default |
|---|---|---|
| `RELIA_PROJECT_ID` | Your project id | none |
| `RELIA_KEY` | Your project key | none |
| `RELIA_SERVICE_NAME` | The name your app shows under in Relia | `backend` |
| `RELIA_ENV` | Environment label | `production` |

On your laptop, set `RELIA_ENV=development` so test traffic stays apart from production.

## When you deploy

Copy the `RELIA_*` lines from `.env` into your host's environment variables (Render, Railway, Fly, a Dockerfile and so on).

## Check it worked

Open your project in Relia and go to the **Setup** tab. **Requests from your server** changes from *Not yet* to *Arriving*, usually within a minute. Your requests and errors appear under **APIs**, and your queries under **Database**.

## If something's wrong

- **Still "Not yet" after a few minutes:** make sure Relia starts before your framework is imported (the lines must be at the very top of the entry file), restart and call an endpoint again. Then see [Relia shows no data](https://tryrelia.com/docs/no-data.md).
- **The setup couldn't patch your entry file:** it prints the lines to add. Add them by hand as shown above.
- **Django middleware missing:** the setup looks for `settings.py` in common places. If yours is elsewhere, add the middleware line yourself.

## Next

- [Identify your users](https://tryrelia.com/docs/identify-users.md)
- [Watch your web app](https://tryrelia.com/docs/web-app-setup.md)
- [Teach Relia what matters](https://tryrelia.com/docs/teach-relia.md)

---
All Relia docs for AI assistants: https://tryrelia.com/llms.txt (index) · https://tryrelia.com/llms-full.txt (everything in one file)
