Skip to content
tezvyn:

Python & FastAPI

Python, Django, FastAPI, Flask, async Python

35 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 interview questions in Python & FastAPI, page 2

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.

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.

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.

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 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

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 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

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.

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.

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.

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.

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.

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.

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

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.

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