FastAPI vocabulary
50 FastAPI terms, from Novice to Master. Start with the basics or jump to a level.
Updated
Novice
- Endpoint
- One address of an API that a client can call.
- FastAPI
- A modern Python framework for building APIs using type hints.
- fastapi dev
- Runs the app locally with auto-reload for development.
- Interactive Docs
- Automatic API docs at `/docs` where you can try every endpoint.
- Path Operation
- A URL path plus HTTP method, and the function that handles it.
- Uvicorn
- The server that runs FastAPI apps.
Apprentice
- async def
- Declares an endpoint that can `await` slow work without blocking the server.
- Automatic Validation
- Bad input is rejected with a clear 422 error before your code runs.
- BaseModel
- The Pydantic base class for data models.
- EmailStr
- Pydantic's type for an email address: text that must have the shape of one, an @ and a domain after it, though it can't tell whether the mailbox exists.
- HTTPException
- Raised to send an error response with a status code and message.
- OpenAPI
- The standard API description FastAPI generates at `/openapi.json`.
- Path Parameter
- A changing part of the URL, converted and checked using its type hint.
- Pydantic
- The library FastAPI uses to define and check data shapes.
- Query Parameter
- Function parameters read from the `?key=value` query string.
- Request Body
- The JSON a client sends, read into a Pydantic model.
- Response Model
- The shape an endpoint returns; extra fields are filtered out.
- Status Code in FastAPI
- Set with `status_code=` on the decorator, such as 201 for created.
- Type Hints in FastAPI
- Type annotations FastAPI uses to check input and write docs.
Journeyman
- Annotated
- Attaches extra info like `Query` or `Depends` to a type hint.
- APIRouter
- Groups related endpoints so the app can be split into files.
- Background Tasks
- Work that runs after the response is sent, like sending an email.
- CORS Middleware
- Lets web pages on other domains call the API.
- Dependency Injection in FastAPI
- FastAPI running helper functions and passing their results into endpoints.
- Depends()
- Marks a parameter whose value comes from calling a dependency function.
- Exception Handler
- A function registered with @app.exception_handler(SomeError) that FastAPI calls whenever that exception reaches it from any route, and that returns the answer to send.
- Field Validation
- Rules on a model field, like min, max or length, added with `Field()`.
- File Upload
- Accepts uploaded files with `UploadFile`.
- Form Data
- Reads HTML form fields instead of JSON.
- Middleware
- Code that runs around every request, before and after the endpoint.
- Nested Model
- A Pydantic model used as the type of another model's field, so a JSON object inside a request body is checked by its own model, such as home: Home.
- Settings with pydantic-settings
- Loads environment variables into a typed settings class.
- SQLModel
- A library where one class is both a database table and an API model.
- Tags
- Labels that group endpoints under headings in the docs.
- TestClient
- Sends requests to the app in tests without a server.
Freelancer
- Custom Validator
- Your own Pydantic validation rule for a field or the whole model.
- Dependency Override
- Replacing a real dependency with a fake one in tests.
- Dependency with yield
- A dependency that yields a value and then runs cleanup after the response.
- JWT in FastAPI
- A signed token carrying user info, created and checked with a library like PyJWT.
- Lifespan Events
- Setup and cleanup code that runs when the app starts and stops.
- OAuth2 Password Flow
- A login flow that trades a username and password for a token.
- RequestValidationError
- The exception FastAPI raises before a route runs when a request breaks its model's rules; a handler for it can reshape the 422 answer.
- Security Dependencies
- Dependencies that check credentials and return the current user.
- slowapi
- A package that adds rate limits to FastAPI routes, such as 5 sign-in tries a minute from one address, and raises RateLimitExceeded for the rest.
- Streaming Response
- Sends data in pieces as it is produced.
- WebSocket
- A connection that stays open for two-way messages, such as chat.
Master
- ASGI
- The async standard interface between Python web apps and servers.
- Event Loop and Blocking Calls
- Blocking calls inside async endpoints freeze the shared event loop.
- Serialization Aliases
- Letting JSON field names differ from Python attribute names.
- Starlette
- The ASGI framework underneath FastAPI.