Source: https://seerepo.com/docs/python
Markdown source: https://seerepo.com/docs/python.md
Description: What SeeRepo reads in a Python web app: Django, Flask and FastAPI routes, Celery tasks, your models, and who has to sign in.

# SeeRepo with Python

SeeRepo reads Python with cables: it follows which file uses which, like it does for TypeScript and JavaScript.

## What SeeRepo reads

**FastAPI and Flask**

- Every route decorator (`@app.get`, `@app.post`, `@app.route`, `@router.api_route`, `@app.websocket`…) is a part, with its full path: the prefix of its `APIRouter` or `Blueprint` included.
- A route that renders a page (`render_template`, `TemplateResponse`…) is a **screen**; one that answers data is an **action**; a webhook, a sitemap or a feed is an **API** door for machines.
- The file that starts the app (`FastAPI()`, `Flask(__name__)`, `app.run()`, or `app = create_app()`) is where your routes start.

**Django**

- A `views.py` that renders a page is a **screen**; one that answers JSON or uses Django REST framework is an **action**.
- Your `urls.py` files are doors, and your `templates/` are **pieces** of the interface.

**Celery**

- `@shared_task` and `@app.task` are things that **run on their own**.

**Your models**

- Django models (`models.Model`, `AbstractUser`), SQLAlchemy (declarative classes, Flask-SQLAlchemy's `db.Model`, Core `Table("…")`) and SQLModel (`table=True`) become **data models**. A pydantic `BaseModel` isn't a table, so it doesn't.

**Who comes in**

A route behind `@login_required` (and its cousins), `LoginRequiredMixin`, `Depends(get_current_user)` or Django REST framework's `IsAuthenticated` is for **Signed-in people**. The rest is for **Visitors**.

## An example from our test bank

- `miguelgrinberg/microblog` (Flask): 2 screens and 1 action, **6 data models** with SQLAlchemy (Message, Notification, Post, Task, User, followers), Redis and Postgres as services. Every route of `app/main/routes.py` requires a session (`@login_required`).
- `testdrivenio/django-celery` (Django): 1 screen and **1 task that runs on its own**, with Redis.
- `wsvincent/lithium` (Django): 1 data model, CustomUser, with Postgres.

## Good to know

- Your packages are read from every list Python uses: `requirements.txt` and the files of a `requirements/` folder (with the files they include), `pyproject.toml`, `Pipfile` and `setup.cfg`. A package you list but never import doesn't show up as a service; a database still does, because your code often reaches it without importing it.
