Courses / Web apps & analytics / FastAPI Fundamentals

Free courseSelf-paced

FastAPI Fundamentals

Build a typed FastAPI service with Pydantic validation, SQLite persistence, an owner-scoped security boundary and an automated pytest suite.

  • Who it's for. Python developers who know REST basics and want to build tested APIs with FastAPI.
  • Before you start. Python Programming and REST API Design. Diagnostic: typed Python functions and classes, GET versus POST and 200/201/404/422, and a virtual environment with pip. No asyncio, FastAPI or Pydantic needed.
  • 29 to 51 hours of study with practice
  • 9 modules, 48 lessons
  • 5 guided projects and a final project

What you'll learn

  • Declare path, query and body inputs with type hints and Pydantic models.
  • Constrain inputs, add cross-field rules and return a uniform error envelope.
  • Persist data in SQLite with SQLModel and atomic multi-row operations.
  • Separate authentication from authorisation using fake tokens and owner checks.
  • Test with TestClient, isolated databases, dependency overrides and OpenAPI contract assertions.

Skills you'll gain

  • ASGI
  • workspace
  • Routes
  • schemas
  • Validation
  • errors
  • Dependencies
  • services
  • Persistence
  • transactions
  • Authentication boundaries
  • Async
  • lifecycle
  • API tests

Tools you'll use

  • Python
  • FastAPI
  • Pydantic
  • SQLModel
  • SQLite
  • pytest
  • ASGI server

Details to know

  • Certificate on completionIssued after your final project is reviewed
  • 9 module checkpointsA quiz and a practical task close each module
  • Self-pacedStudy any time; your progress is saved

How every lesson works

Each lesson follows the same four steps, so you always know what comes next.

  1. 01

    Watch & Learn

    A short animated video explains one idea at a time.

  2. 02

    Guided Practice

    Work through an example step by step and check the result.

  3. 03

    Quiz & Challenge

    Short questions check the idea has landed before you move on.

  4. 04

    Mini Project

    Build something useful from a project brief.

Learn at your own pace

This is a self-paced course. There are no live classes and no fixed timetable.

  • Start any timeStudy when it suits you. Lessons are short, so they fit around work or college.
  • Pick up where you left offYour progress is saved to your account.
  • Ask when you're stuckUse Ask Mentor inside the learning platform.

Your path in 4 phases

Each phase ends with something you have built and checked.

  1. 01

    Modules 1 to 3

    Routes and validation

    Run FastAPI on an ASGI server, declare routes and schemas, and validate input.

    You build: Equipment-loan API with typed routes and schemas.

  2. 02

    Modules 4 to 5

    Services and persistence

    Share logic with dependencies and a service layer, then persist data in SQLite.

    You build: Equipment-loan API with services and SQLite persistence.

  3. 03

    Modules 6 to 8

    Security, async and tests

    Add a security boundary, use async and lifespan correctly and build the test suite.

    You build: Identity, lifecycle and background work.

  4. 04

    Module 9

    Service integration

    Call upstream services safely, add middleware and rehearse a release.

    You build: Test suite, integration and release gate.

Full curriculum

9 modules and 48 lessons, 29 to 51 hours of study

01ASGI and workspace5 lessons, 2 to 4 hours

Lessons

  • Tracing a request from the ASGI server to a path operation function
  • Pinning a reproducible FastAPI workspace
  • Serving a first app with the fastapi dev command
  • Reading the generated OpenAPI document
  • Splitting an app into packages with APIRouter

After this module you can

  • Label which component owns the socket, which matches the route and which runs your function, then confirm the labels with TestClient responses for a known path, an unknown path and a wrong method.
  • Create a virtual environment, install fastapi with pytest and httpx, and write a version report script whose output you commit as evidence of exactly what was installed.
  • Move a group of routes into an APIRouter module with a prefix and tags, include it in the main app, and prove with the OpenAPI document that the final paths carry the prefix.
02Routes and schemas5 lessons, 2 to 4 hours

Lessons

  • Typed path parameters and automatic conversion
  • Query parameters: defaults, optional and required
  • JSON request bodies with Pydantic models
  • Response models that filter what leaves the API
  • Choosing HTTP methods and status codes for each operation

After this module you can

  • Declare a typed path parameter, predict conversion of valid and invalid segments, and assert the success value type and the failure status through TestClient.
  • Distinguish required, defaulted and optional query parameters from the signature alone and write tests that show missing, present and invalid cases.
  • Set status_code on creation and removal routes, return 204 with no body for a deletion, and assert code and body together.
03Validation and errors7 lessons, 3 to 5 hours

Lessons

  • Query() constraints: length, pattern and repeated values
  • Path() numeric constraints with ge, gt, le and lt
  • Field constraints and field_validator in body models
  • Cross-field rules with model_validator
  • Reading the structure of a validation failure response
  • Raising HTTPException for domain errors
  • Custom exception handlers for a uniform error body

After this module you can

  • Constrain a query parameter with Annotated and Query (min_length, max_length, pattern) and accept a repeated parameter as a list, with tests for each boundary.
  • Constrain a path parameter and a float query parameter with Path and Query numeric bounds and explain which boundary values each operator accepts.
  • Register a handler for RequestValidationError and for a custom domain exception so every failure in the service uses one error envelope, and test both paths.
04Dependencies and services5 lessons, 2 to 4 hours

Lessons

  • Sharing query logic with a Depends function
  • Dependency chains and per-request caching
  • Router-level and decorator-level dependencies
  • Typed settings with pydantic-settings and a cached dependency
  • Keeping business rules in a service layer the routes call

After this module you can

  • Extract duplicated pagination parameters into a dependency function used by two routes, and show with OpenAPI that both routes expose the same parameters.
  • Build a two-level dependency chain where a sub-dependency is shared by two parents, and predict and test how many times it runs per request.
  • Move an order-pricing rule into a plain Python service class, unit-test it without HTTP, and inject it into the route with Depends.
05Persistence and transactions6 lessons, 3 to 4 hours

Lessons

  • Table models versus API models in SQLModel
  • Engine, per-request session and yield dependencies
  • Creating and reading rows through a session
  • Partial updates with PATCH and exclude_unset
  • Listing with offset and limit, and deleting rows
  • All-or-nothing changes with commit and rollback

After this module you can

  • Define a base, a table model, a create model and a public model for one resource and explain which fields each may contain.
  • Create a SQLite engine and a get_session dependency using yield, and demonstrate that exit code runs after the route and that each request gets a fresh session.
  • Write a transfer-style operation that changes two rows, force a failure between the changes, and prove with a follow-up read that nothing was committed.
06Authentication boundaries5 lessons, 2 to 4 hours

Lessons

  • OpenAPI security schemes and what FastAPI's helpers declare
  • OAuth2PasswordBearer: extracting a bearer token without trusting it
  • A get_current_user dependency that resolves identity
  • Authorisation: owner checks and the 403 versus 404 decision
  • CORS middleware and what it does not protect

After this module you can

  • Name the four OpenAPI security scheme types, add a security dependency to one route and find its scheme in the generated document.
  • Use OAuth2PasswordBearer to extract a Bearer token and show with tests that a missing or malformed Authorization header is rejected before the route runs.
  • Configure CORSMiddleware with an explicit origin list, test a preflight request and a simple request, and explain why wildcard origins conflict with credentials.
07Async and lifecycle5 lessons, 2 to 4 hours

Lessons

  • Choosing async def or def from what the body calls
  • Observing a blocked event loop with concurrent requests
  • Overlapping awaitable work with asyncio.gather
  • Startup and shutdown with the lifespan parameter
  • BackgroundTasks: work after the response and its limits

After this module you can

  • Classify four handler bodies as async def or def using the documented rule, then confirm your classification by checking which functions the framework runs on a worker thread.
  • Measure total elapsed time for several concurrent requests to a def handler versus an async def handler that blocks, and report the difference with a stated tolerance.
  • Schedule a small task with BackgroundTasks, prove it runs after the response body is produced, and state why it is the wrong tool for heavy or distributed work.
08API tests5 lessons, 2 to 4 hours

Lessons

  • TestClient requests: json, headers, cookies and query strings
  • Parametrised boundary tables with pytest
  • Isolated SQLite state per test with a session override
  • Overriding dependencies for identity, settings and fakes
  • OpenAPI contract tests for routes, codes and schemas

After this module you can

  • Send each kind of input (json body, form data, headers, cookies, query) through TestClient to routes that read them, and assert the echoed values.
  • Replace repeated near-identical tests with a pytest.mark.parametrize table of inputs and expected status classes, with readable ids, covering both sides of each boundary.
  • Write contract tests that assert from the generated document the operations, their documented status codes and the property names of request and response schemas.
09Service integration5 lessons, 2 to 4 hours

Lessons

  • Calling an upstream HTTP service and mapping its failures
  • Testing outbound calls with httpx.MockTransport and an injected client
  • HTTP middleware for request ids and timing headers
  • Publishing accurate API documentation metadata
  • A local release rehearsal against the deployment concepts

After this module you can

  • Call a loopback fixture service with httpx from a handler, map upstream success, upstream 5xx and timeout to your own statuses, and assert each.
  • Inject an httpx client through a dependency and replace its transport with MockTransport in tests to simulate success, failure and slow responses with no network.
  • Write a release gate script that runs tests, starts the app with the production-style command on loopback, probes health and docs endpoints, and records which deployment concerns are handled by what.

What you'll build

5 guided projects along the way, then a final project.

  • Equipment-loan API: typed routes and schemas

    after module 2
  • Equipment-loan API: validation, errors and services

    after module 4
  • Equipment-loan API: SQLite persistence

    after module 5
  • Equipment-loan API: identity, lifecycle and background work

    after module 7
  • Equipment-loan API: test suite, integration and release gate

    after module 9

Final project

Choose one API: an equipment-loan ledger, a clinic appointment-slot API or a workshop seat-reservation API.

What you submit

Repository with app package, tests, requirements and README; two resources with CRUD, a cross-field rule, a paged list, an atomic operation, restart evidence, contract tests and a release gate script.

How it's reviewed

Rubric: status codes and validation 20%, persistence and atomicity 20%, test quality 25%, security and errors 15%, setup and more, plus an accepted live demonstration.

Where you'll use it

  • Add validation to an API endpoint so bad requests return clear 422 errors.
  • Write pytest tests that override a dependency to test an endpoint without a real upstream.

Roles that use these skills

  • Python backend developer
  • API developer
  • Backend engineer

Earn the certificate by building, not watching

  1. Complete the lessons and pass each module checkpoint.
  2. Build your final project and demonstrate it.
  3. OUTLEARN reviews your project and issues your certificate. It is not issued automatically.

Frequently asked questions

Do I need asyncio knowledge?

No. Asyncio, SQL beyond SELECT/INSERT and prior FastAPI or Pydantic use are not required.

Are real tokens issued?

No. Fake tokens are used; real token issuing is deferred to the earlier course.

Can I join from another framework?

Yes. Experience with Express, Flask or Django plus typed Python is accepted.

Be first in when FastAPI Fundamentals opens

Email us and we will tell you as soon as enrolment opens.

Notify me when it opens
FreeOpens soon
Notify me