🌍 Python · flashcards

Python FastApi Flashcards

56 question-and-answer cards covering FastApi as it is examined in Python. 24 of them are printed below, taken from across the deck — no signup, no paywall on the preview.

56Cards in deck
24Free preview
16Syllabus topics
~155Chars per answer
FreePrice

24 sample cards from the FastApi deck

Sampled from the end of the deck, so these are different cards from the ones shown on the syllabus page.

  1. What is the recommended library and algorithm approach for password hashing in FastAPI security tutorials?

    Use passlib (commonly with bcrypt) to hash and verify passwords; never store plaintext passwords.

  2. In FastAPI's OAuth2 JWT flow, what does the server return after successful login and what does the client send afterward?

    The server returns a JWT access token (with token_type 'bearer'); the client then sends it in the Authorization: Bearer <token> header on subsequent requests.

  3. What is the purpose of BackgroundTasks in FastAPI?

    To run operations after returning the response, so the client isn't kept waiting — e.g. sending email notifications or writing logs.

  4. How do you add a background task in a FastAPI path operation?

    Declare a BackgroundTasks parameter and call background_tasks.add_task(func, *args, **kwargs); the task runs after the response is sent.

  5. When should you use Celery instead of FastAPI's built-in BackgroundTasks?

    For heavy, long-running, or CPU-intensive jobs needing a distributed task queue, retries, scheduling, or a separate worker process. BackgroundTasks suits light operations within the same process.

  6. What is middleware in FastAPI and when does its code run?

    Middleware is a function/class that processes every request before it reaches the path operation and every response before it's returned, enabling cross-cutting concerns like logging, timing, or headers.

  7. Write the signature pattern for a custom HTTP middleware function in FastAPI.

    @app.middleware("http") async def add_process_time(request: Request, call_next): response = await call_next(request) return response # call_next runs the rest of the app

  8. Which middleware do you add in FastAPI to allow requests from other origins (browsers)?

    CORSMiddleware (from fastapi.middleware.cors / starlette), configured with allow_origins, allow_methods, and allow_headers.

  9. Which ORM is traditionally used with FastAPI for relational databases, and which library does FastAPI's creator recommend that combines it with Pydantic?

    SQLAlchemy is traditional; SQLModel (by FastAPI's creator) combines SQLAlchemy and Pydantic in one model.

  10. In a FastAPI + SQLAlchemy setup, how is a database session typically provided to path operations?

    Through a dependency (get_db) that uses yield to create a SessionLocal, inject it, and close it afterward.

  11. What three core objects must you configure for SQLAlchemy in a FastAPI app?

    An engine (create_engine with the DB URL), a session factory (sessionmaker -> SessionLocal), and a declarative Base class for models.

  12. For SQLite specifically with FastAPI, what connect argument is required and why?

    connect_args={"check_same_thread": False}, because SQLite by default allows only the creating thread to use the connection, while FastAPI may use multiple threads.

  13. What is a NoSQL (non-relational) database, and name two types?

    A database that stores data without fixed relational tables/schemas. Types include document stores (MongoDB), key-value stores (Redis), wide-column (Cassandra), and graph databases (Neo4j).

  14. Give one key advantage and one trade-off of NoSQL vs SQL databases.

    Advantage: flexible schema and horizontal scalability for large/unstructured data. Trade-off: weaker ACID guarantees and limited multi-table JOINs/complex relational queries compared to SQL.

  15. Which async driver is commonly used to connect FastAPI to MongoDB?

    Motor (the async MongoDB driver), often paired with Beanie or ODMantic as a Pydantic-based ODM.

  16. Which HTTP client class does FastAPI use for writing tests, and from which library?

    TestClient from fastapi.testing (backed by Starlette/httpx) — instantiated as client = TestClient(app).

  17. Write a minimal FastAPI test using TestClient that checks the root endpoint.

    from fastapi.testclient import TestClient from main import app client = TestClient(app) def test_root(): response = client.get("/") assert response.status_code == 200 assert response.json() == {"Hello": "World"}

  18. How do you replace a real dependency (like a DB) with a fake one during FastAPI tests?

    Use app.dependency_overrides[original_dependency] = fake_dependency; this swaps the dependency only for tests without changing app code.

  19. Why is dependency override preferred over patching/monkeypatching for mocking dependencies in FastAPI?

    Because FastAPI's DI system is designed for it: overrides are explicit, scoped, and reset easily (clear the dict), keeping production code untouched and tests isolated/repeatable.

  20. List three common options for deploying a FastAPI application.

    (1) A container image (Docker) run on Kubernetes/cloud; (2) a managed/PaaS host (e.g., a cloud run service or platform); (3) a VM/server running Uvicorn behind a reverse proxy like Nginx, often managed by Gunicorn with Uvicorn workers.

  21. What is the recommended way to run FastAPI in production for multiple worker processes?

    Run Uvicorn with multiple workers (e.g. fastapi run --workers N or Gunicorn managing uvicorn.workers.UvicornWorker), typically behind a reverse proxy/load balancer.

  22. What is CI/CD and what does each part stand for?

    CI is Continuous Integration (automatically building and testing code on each change/merge); CD is Continuous Delivery/Deployment (automatically releasing/deploying validated code).

  23. What are the typical stages of a CI/CD pipeline for a FastAPI project?

    Lint/format check, install dependencies, run automated tests (pytest), build the artifact/Docker image, and deploy to the target environment.

  24. Why is a reverse proxy (e.g., Nginx) commonly placed in front of a deployed FastAPI/Uvicorn server?

    To handle TLS/HTTPS termination, serve static files, load-balance across workers, and add buffering/security — letting Uvicorn focus on the ASGI app.

What this deck covers

The FastApi deck follows the Python FastApi syllabus — 6 chapters and 16 topics — so questions land on material that is genuinely examinable rather than trivia around it. That works out to roughly 9.3 cards per chapter.

Answers are written to be recallable, not just readable — averaging about 155 characters, which is long enough to carry the reasoning and short enough to say out loud.

A deck like this earns its keep on the second and third pass. Read the syllabus first so you know the shape of the subject, then use the cards to find the specific facts that have not stuck.

FastApi flashcards FAQ

How many FastApi flashcards are in this Python deck?

56 cards. This page previews 24 of them, sampled evenly across the deck so you can judge the difficulty before installing anything.

Are these Python flashcards free?

Yes. The preview here is free to read with no signup, and the full 56-card deck is free inside the Examius app.

What do the FastApi cards cover?

They follow the Python FastApi syllabus — 6 chapters and 16 topics — so the questions track what is actually examinable.

How should I use these flashcards?

Read the syllabus first so you know the shape of the subject, then drill the deck. Examius schedules each card with spaced repetition, so cards you keep missing come back sooner and ones you know drift further apart.