new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

FastAPI · Tutorial · all subjects

bigger-applications/imports

2 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Relative imports in Python modules

In a multi-file FastAPI app, use relative imports to avoid conflicts. A single dot (`.`) refers to the current package directory. Two dots (`..`) go up one level to the parent package. For example, in `app/routers/items.py`, use `from ..dependencies import get_token_header` to import from `app/dependencies.py`. Use `from .routers import items, users` in `app/main.py` to import from `app/routers/items.py` and `app/routers/users.py`.

Avoid name collisions when importing multiple routers

When importing multiple submodules that each have a variable named `router`, import the submodules themselves rather than the router variable. Use `from .routers import items, users` and access them as `items.router` and `users.router`. If you import like `from .routers.items import router` followed by `from .routers.users import router`, the second import overwrites the first.

Give your agent this brain