Skip to content
tezvyn:

All bites

The whole library, newest first. Filter by what you are here for, or pick a topic if you already know.

4330 bites

Newest first

Explain Python type hints and their importance in FastAPI
Python & FastAPI2 min read

Explain Python type hints and their importance in FastAPI

Define hints as declarations; explain FastAPI uses them with Pydantic to validate requests and OpenAPI docs.

What is the difference between def and async def in Python and FastAPI?
Python & FastAPI2 min read

What is the difference between def and async def in Python and FastAPI?

Tests event-loop boundaries: async def yields control via await for non-blocking I/O, def runs in a threadpool. Use async def only with async libraries; def covers blocking calls. Red flag: claiming async is automatically faster or awaiting inside def.

How does FastAPI leverage Pydantic for request validation and serialization?
Python & FastAPI2 min read

How does FastAPI leverage Pydantic for request validation and serialization?

This tests your understanding of FastAPI's declarative validation. Explain that type hints trigger auto-parsing, Pydantic enforces schemas and errors, and return types auto-serialize responses. Red flag: manually parsing request.body() or json.loads in routes.

Python & FastAPI2 min read

Write an async decorator that logs execution time for FastAPI

Use functools.wraps, wrap perf_counter around awaited call, log ms, and place decorator above path operation.

How do you structure concurrent API calls with asyncio.gather in FastAPI?
Python & FastAPI2 min read

How do you structure concurrent API calls with asyncio.gather in FastAPI?

Tests FastAPI async concurrency. Strong answer: async def endpoint with two async HTTP requests in asyncio.gather, cutting total latency from sum to max of the two. Red flag: using sync clients or threads instead of async I/O.

How does Uvicorn use asyncio to handle thousands of concurrent connections?
Python & FastAPI2 min read

How does Uvicorn use asyncio to handle thousands of concurrent connections?

Tests async concurrency and the GIL. Great answers cover the event loop suspending coroutines at await, Uvicorn interleaving connections, and multi-process workers for parallelism. Red flag: claiming asyncio uses threads per request or bypasses the GIL.

Python & FastAPI2 min read

Implement an async database session dependency using yield for setup and teardown

This tests async resource lifecycle management in FastAPI. A strong answer uses async def, yields a session inside try, closes in finally, and injects with Depends. A red flag is omitting finally or using sync def for async I/O, which leaks connections.

Create a generic Pydantic BaseModel for API response wrappers
Python & FastAPI2 min read

Create a generic Pydantic BaseModel for API response wrappers

Subclass BaseModel and Generic[T]; type data as T; use ResponseWrapper[User]; note unparametrized TypeVars validate as Any.

What is the purpose of @app.get("/") in FastAPI?
Python & FastAPI2 min read

What is the purpose of @app.get("/") in FastAPI?

Tests your understanding of FastAPI routing. A strong answer explains that the decorator binds an HTTP method and path to a Python function, registers it in the app's route table, and builds OpenAPI metadata.

How do you define and access a FastAPI path parameter?
Python & FastAPI2 min read

How do you define and access a FastAPI path parameter?

Tests FastAPI route-to-function binding. Good answer: curly-brace syntax in the decorator path, a matching typed function argument, and awareness that FastAPI auto-extracts and converts the value.

Python & FastAPI1 min read

How FastAPI uses type hints for validation

Hints drive parsing, validation, and conversion; a path declared int is coerced or returns 422; OpenAPI is auto-generated.

Python & FastAPI2 min read

What is the difference between a path parameter and a query parameter?

Tests REST API design and FastAPI binding. A strong answer states path params identify resources in the URL while query params filter after the question mark, then codes user_id in the route and q: str | None = None in the function.

Python & FastAPI2 min read

How does FastAPI distinguish required optional and default query parameters

Tests whether you know FastAPI infers query parameter optionality from Python signature defaults. Answer: no default means required, Optional[T] = None means optional, T = value sets a default, with all three in one signature.

Python & FastAPI2 min read

What standard and code elements power FastAPI's auto-generated API docs?

Tests whether you know FastAPI uses the OpenAPI standard and extracts metadata from Python type hints, Pydantic models, decorators, and docstrings to build interactive docs. Red flag: claiming you must manually maintain a separate schema file.

Python & FastAPI2 min read

FastAPI non-integer query param default behavior

Tests FastAPI's automatic Pydantic validation and default error contracts. Strong answer: 422 Unprocessable Entity with JSON detail array containing loc, msg, and type fields. Red flag: saying 400 Bad Request or manual validation is needed.

How do you type-hint repeated query params in FastAPI?
Python & FastAPI2 min read

How do you type-hint repeated query params in FastAPI?

Tests FastAPI's Annotated pattern for multi-value query strings. A great answer uses Annotated[list[str], Query()] = [] to collect repeated keys, and notes the old Query-as-default alternative. Red flag: manual parsing or typing it as str.

What is the :path converter in FastAPI?
Python & FastAPI2 min read

What is the :path converter in FastAPI?

Tests FastAPI routing semantics and URL segmentation. A strong answer states :path captures slashes across segments while plain str stops at the next slash, and cites file-serving as the use case.

How do you define a Pydantic model for FastAPI request body validation?
Python & FastAPI2 min read

How do you define a Pydantic model for FastAPI request body validation?

Subclass BaseModel with id int, email str, full_name str|None; pass it as a route param so FastAPI validates JSON and returns 422s.

How does Pydantic handle extra JSON fields, and how to configure it?
Python & FastAPI2 min read

How does Pydantic handle extra JSON fields, and how to configure it?

This tests Pydantic's data filtering behavior and configuration. By default, Pydantic ignores extra fields silently. Set model_config = ConfigDict(extra='forbid' or 'allow') to change it. A red flag is claiming FastAPI 422s by default on unknown fields.

What is the difference between a Pydantic default and Optional field?
Python & FastAPI2 min read

What is the difference between a Pydantic default and Optional field?

Both forms are non-required; str = 'guest' rejects None, Optional[str] = None accepts it.