Advanced everything in Python & FastAPI, page 4
FastAPI `yield` Dependencies for Setup and Teardown
A yield dependency is a context manager for your endpoints. Code before yield runs setup, like getting a DB connection; code after yield runs teardown.

Pydantic Computed Fields: Serialize Derived Values
A Pydantic computed field makes a derived value, like an area from width and length, part of your model's serialized output. Use it to include calculated attributes when calling .model_dump().
Starlette's Request Object: A Clean API for ASGI
Starlette's Request object is a high-level wrapper around the raw ASGI scope, providing a clean API for request data. Use it in endpoints to read headers, query params, or parse the body. The footgun: the request body can only be read once.
FastAPI: Use HTTPException to Return Client Errors
FastAPI's HTTPException is your tool for stopping an operation and sending a clean HTTP error. Raise it when business logic fails, like a missing database record. The footgun is catching it yourself; just raise it and let FastAPI do the rest.

The Python GIL: One Thread at a Time
The Python Global Interpreter Lock (GIL) is a mutex ensuring only one thread executes Python bytecode at a time. This serializes CPU-bound threads, but the lock is released during I/O, making it effective for network-bound tasks.

Python Concurrency vs. Parallelism
Concurrency is juggling tasks; parallelism is doing them at once. In Python, use concurrency (threading/asyncio) for I/O-bound work like API calls, and parallelism (multiprocessing) for CPU-bound tasks.

Accessing Python Type Annotations Safely
Accessing an object's type hints isn't just obj.__annotations__. Use inspect.get_annotations() in Python 3.10+ for safe access. This is key for tools like FastAPI that introspect your code.
Top 10 FastAPI interview questions for senior roles
FastAPI interview questions rarely test syntax. They probe whether you understand its three pillars: ASGI powered async concurrency, Pydantic validation at the request boundary, and the Depends dependency injection graph that wires services together.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles