Skip to content
tezvyn:

Python & FastAPI

Python, Django, FastAPI, Flask, async Python

32 bites

Test yourself: Top 30 easy Python & FastAPI concepts questionsMultiple choice, with the correct answer and why it is correct on every question. Free, no sign-in.

Easy concepts in Python & FastAPI

Python Type Hints: Documentation Your Linter Can Read
easy2 min read

Python Type Hints: Documentation Your Linter Can Read

Type hints describe expected values, but Python itself does not enforce them while running. Static checkers and IDEs use the annotations before execution; libraries such as FastAPI can also inspect them for validation and API documentation.

Python Data Classes: Write Less Boilerplate
easy2 min read

Python Data Classes: Write Less Boilerplate

Python's @dataclass decorator writes boilerplate code like __init__ and __repr__ for you, turning a class with type hints into a data container. Use it for API payloads or simple records.

Python Packages: Grouping Modules with __init__.py
easy2 min read

Python Packages: Grouping Modules with __init__.py

A Python package is a folder of modules treated as one unit. The __init__.py file marks the folder as a package and can run setup code. Use it to organize large codebases.

Python Enums: Give Names to Magic Numbers
easy2 min read

Python Enums: Give Names to Magic Numbers

Python's Enum gives meaningful names to "magic numbers" or strings. Use it for fixed sets of options like statuses or categories to make code self-documenting. The footgun: don't compare members to raw values; compare member to member for type safety.

FastAPI Application Instance: Your API's Central Hub
easy2 min read

FastAPI Application Instance: Your API's Central Hub

The FastAPI instance is your API's central switchboard, connecting incoming requests to your code. You create it once (e.g., app = FastAPI()) and use its decorators like @app.get to define all your endpoints. The footgun is creating multiple instances.

FastAPI: Configure Endpoints with Decorators
easy2 min read

FastAPI: Configure Endpoints with Decorators

FastAPI's path operation decorators configure an endpoint's metadata and behavior. Use them to set status codes (status_code=201), group endpoints with tags, or mark them as deprecated.

Path Parameters: Turning URL Parts into Variables
easy2 min read

Path Parameters: Turning URL Parts into Variables

Path parameters turn parts of a URL, like /users/123, into typed function arguments. FastAPI uses this to create endpoints for specific resources, like fetching a user by their ID. The footgun is forgetting type hints; without int, 123 is just a string.

easy2 min read

FastAPI Query Parameters: Beyond the URL Path

In FastAPI, function arguments not in the URL path become query parameters—the optional key-value pairs after a URL's ?. Use them for filtering or pagination, like /items?skip=0&limit=10. The footgun: omitting a default value makes the parameter required.

easy2 min read

Uvicorn Workers: Scaling Your FastAPI App

Uvicorn workers are like adding cashiers to a store. Instead of one process handling all requests, you run multiple, letting your FastAPI app use all CPU cores to serve more users concurrently.

Pydantic: Required vs. Optional Fields
easy2 min read

Pydantic: Required vs. Optional Fields

In Pydantic, a field is required by default. To make it optional, you must provide a default value, like name: str = "guest" or age: int | None = None. This is key for flexible API request bodies.

easy2 min read

FastAPI: Handling Form Data, Not Just JSON

FastAPI can handle classic HTML form data, not just JSON. Use Form to define expected fields in your endpoint, just like query parameters. It's ideal for login pages. The footgun: forgetting to pip install python-multipart will break form parsing.

easy1 min read

Declaring Request Headers in FastAPI

Treat request headers like any other parameter in FastAPI. Declare them in your function signature to access values like User-Agent or X-Token. FastAPI automatically converts hyphens to underscores, so User-Agent is accessed via the user_agent

easy1 min read

FastAPI: Reading Request Cookies

FastAPI treats request cookies like any other parameter. Declare them directly in your endpoint's function signature using Cookie(), and the framework will extract the value for you. Use this for reading session IDs or user preferences.

FastAPI: Returning HTML with HTMLResponse
easy2 min read

FastAPI: Returning HTML with HTMLResponse

Override FastAPI's default JSON output by using HTMLResponse to return a raw HTML string directly from an endpoint. It's for simple status pages or server-side rendered components.

FastAPI's Depends: Let the Framework Handle Setup
easy2 min read

FastAPI's Depends: Let the Framework Handle Setup

Think of Depends as a pre-flight checklist for your API endpoints. You list required setup tasks, like getting a user or a database session, and FastAPI runs them for you. This is key for sharing logic like auth or database connections across many routes.

FastAPI: Using Classes as Dependencies
easy2 min read

FastAPI: Using Classes as Dependencies

Bundle related request parameters into a class instead of repeating them in every endpoint. FastAPI automatically creates an instance for you, cleaning up your code. This is ideal for shared logic like pagination. The footgun: FastAPI injects into __init__.

easy2 min read

FastAPI's Dependency Caching: One Request, One Call

FastAPI dependencies are singletons for the life of a request. If multiple parts of your code ask for the same dependency (e.g., a database session), FastAPI runs it once, caches the result, and shares it. The footgun: this cache is per-request, not global.

easy2 min read

FastAPI's APIRouter: Grouping Routes into Modules

Think of APIRouter as a mini-FastAPI app for organizing endpoints. It lets you group related paths, like all user routes, into a separate file. This is crucial for keeping large applications maintainable.

FastAPI: Splitting Your App with `include_router`
easy1 min read

FastAPI: Splitting Your App with `include_router`

app.include_router is like plugging a pre-wired power strip of API endpoints into your main FastAPI app. It lets you organize a large app into smaller files by feature, then combine them. The footgun is forgetting to add a URL prefix for each router.

The asyncio Event Loop: One Thread, Many Tasks
easy2 min read

The asyncio Event Loop: One Thread, Many Tasks

The asyncio event loop is a manager for a single-threaded process, juggling tasks to prevent idleness during slow I/O. It's the core of apps like FastAPI, handling network requests efficiently. The footgun is interacting with it directly; use asyncio.run().

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