Skip to content
tezvyn:

Python & FastAPI

Python, Django, FastAPI, Flask, async Python

68 bites

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

Easy everything in Python & FastAPI

easy2 min read

Why use an ASGI server like Uvicorn instead of the dev server?

Tests: dev vs prod environment distinction. Answer: Uvicorn is a prod server program; contrast dev server's constant restart/break/fix cycle with prod needs for performance, stability, and uninterrupted access.

Walk me through a basic Dockerfile for a FastAPI app
easy2 min read

Walk me through a basic Dockerfile for a FastAPI app

Slim base, install deps before app code to cache layers, expose port, exec-form CMD for Uvicorn.

easy2 min read

What are startup and shutdown events in FastAPI?

Tests app lifespan hooks and resource lifecycle. Startup creates DB pools before traffic arrives; shutdown closes them after the last request. These decorators are deprecated; prefer lifespan context managers. Red flag: per-request middleware.

How do you define a WebSocket endpoint in FastAPI?
easy2 min read

How do you define a WebSocket endpoint in FastAPI?

Import WebSocket, use @app.websocket, await accept, receive_text, then send_text.

What are FastAPI's two default interactive documentation UIs and URL paths?
easy2 min read

What are FastAPI's two default interactive documentation UIs and URL paths?

This tests whether you know FastAPI's built-in auto-generated docs. A strong answer names Swagger UI at /docs and ReDoc at /redoc, then notes the OpenAPI schema at /openapi.json. A weak answer confuses these with external tools or custom routes.

Add summary and description to a FastAPI endpoint for Swagger UI
easy2 min read

Add summary and description to a FastAPI endpoint for Swagger UI

This tests FastAPI path operation decorator configuration. Pass summary and description to @app.get, or use function docstring for description. A red flag is setting metadata inside the function body or confusing docs with Pydantic Field descriptions.

How do you add a title, description, and version to FastAPI auto-docs?
easy2 min read

How do you add a title, description, and version to FastAPI auto-docs?

Tests if you know FastAPI's metadata kwargs for OpenAPI docs. Pass title, description, and version to the FastAPI() constructor; Swagger UI and ReDoc render them automatically.

easy2 min read

What is FastAPI's TestClient and how does it differ from requests?

Tests if you know TestClient runs pytest against the app directly without a live server. Good answers note its HTTPX-based Requests-like API, passing the FastAPI app into the client, and simple asserts. Red flag: saying you need a running server and real URLs.

easy2 min read

How do you test a FastAPI GET endpoint with pytest and TestClient?

Import TestClient and app, write a test_ function, call client.get("/items/1"), assert status_code == 200 and json() matches expected data.

easy2 min read

Purpose of await next(request) in FastAPI middleware and timing effects

Tests ASGI middleware lifecycle. await next(request) forwards the request downstream to the endpoint and returns the response. Pre-call code touches the request; post-call code touches the response.

easy2 min read

How do you send an email without blocking a FastAPI request?

Tests knowledge of FastAPI's BackgroundTasks for post-response work. Strong answer: import it, inject into the endpoint, define a task function, and call add_task before returning.

easy2 min read

Frontend on localhost:3000 gets errors calling FastAPI on localhost:8000. Name and fix?

This tests whether different ports mean different origins, causing CORS errors. A strong answer names CORS, notes ports are distinct origins, and outlines using CORSMiddleware with allow_origins.

easy2 min read

How should you store user passwords in a database?

Tests knowledge of slow salted hashing versus encryption. Strong answers pick Argon2id or bcrypt, require unique per-user salts, describe verification via re-hashing with constant-time comparison, and cite bcrypt or argon2-cffi.

What are the three components of a JWT?
easy2 min read

What are the three components of a JWT?

Tests if you know JWT structure beyond library usage. A strong answer lists header, payload, and signature; notes Base64Url encoding; and gives a registered claim like exp. A red flag is confusing signing with encryption.

How do you protect a FastAPI endpoint using Depends and OAuth2PasswordBearer?
easy2 min read

How do you protect a FastAPI endpoint using Depends and OAuth2PasswordBearer?

OAuth2PasswordBearer sets the token URL, Depends injects it into the endpoint, and FastAPI validates the Bearer header.

Explain SQLAlchemy ORM vs Pydantic models in FastAPI
easy2 min read

Explain SQLAlchemy ORM vs Pydantic models in FastAPI

This tests separation of database schema from API contracts. A strong answer distinguishes SQLAlchemy table rows from Pydantic validation and OpenAPI generation, and notes that create schemas exclude auto-generated IDs.

Describe SQLAlchemy setup in FastAPI from database config to endpoint
easy2 min read

Describe SQLAlchemy setup in FastAPI from database config to endpoint

Tests FastAPI dependency injection and SQLAlchemy session lifecycle. Good answers cover: engine with pooling, declarative models, a yield-based session dependency, and endpoint queries. Red flag: engine per request or global session shared everywhere.

Explain await's purpose, awaitable types, and event loop signaling
easy2 min read

Explain await's purpose, awaitable types, and event loop signaling

This tests whether you understand await as a yield point. A strong answer lists three awaitables (coroutines, Tasks, Futures), explains await yields control to the event loop until completion, and warns that a bare coroutine call does not run it.

What is the difference between async def and regular functions?
easy2 min read

What is the difference between async def and regular functions?

This tests async def call semantics. A strong answer contrasts regular functions, which execute immediately, with async def, which returns a coroutine object that does nothing until awaited or wrapped in create_task.

How do you include a router in your main FastAPI app?
easy2 min read

How do you include a router in your main FastAPI app?

Create APIRouter in another file, import it into main.py, then call app.include_router(router).

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