Guide Home Part 1 - FastAPI Foundations Part 2 - Building Applications Part 3 - Pages and HTML Part 4 - Security and Deployment Part 5 - Going Further Capstone Build Plan Markdown Source All Guides

Modern Python Web Applications for ASP.NET Core Developers

A FastAPI-centered path through APIs, server-rendered pages, data, security, deployment, background work, and testing.

Who This Is For

You know .NET and ASP.NET Core. You know the Python language well enough to read and write Python, but you want a guided path through the web ecosystem: project layout, routing, dependency injection, validation, persistence, authentication, authorization, security, deployment, background work, HTTP clients, and testing.

Framework Choice

This guide uses FastAPI as the main framework because it maps naturally to ASP.NET Core APIs:

The guide also introduces Jinja2 templates with FastAPI/Starlette for server-rendered pages. When a concept is better served by Django's integrated ecosystem, the chapter calls that out. Django is Python's closest analogue to a large batteries-included framework with built-in admin, forms, ORM, authentication, sessions, CSRF protection, and security defaults. Flask appears only as context because it is useful historically and for small apps, but it is not the recommended default for this learning path.

Core Stack

Use this stack for the capstone unless a chapter explicitly explores an alternative:

ConcernPython choiceASP.NET Core mental model
Web frameworkFastAPIMinimal APIs plus MVC/Web API concepts
ASGI serverUvicorn or GranianKestrel hosting process
Validation and DTOsPydantic v2Model binding, validation attributes, API contracts
Database ORMSQLAlchemy 2.xEF Core, but more explicit
MigrationsAlembicEF Core migrations
TemplatesJinja2 via StarletteRazor views/pages conceptually, not syntactically
Password hashingpwdlib or passlib with Argon2/bcryptASP.NET Identity password hashing
JWTPyJWT or python-joseBearer token authentication
Settingspydantic-settingsIConfiguration plus options binding
Testspytest, HTTPX, pytest-asyncioxUnit plus WebApplicationFactory
HTTP clientHTTPXIHttpClientFactory plus HttpClient
Background jobsARQ, Celery, Dramatiq, or APSchedulerhosted services, queues, workers
Observabilitystructlog/logging, OpenTelemetry, Sentrylogging providers, tracing, health checks

Capstone: RecipeVault

The running project is RecipeVault, a recipe management app that grows from a tiny JSON API into a secure, database-backed, tested, deployable web application.

By the end, RecipeVault has:

Chapter 1

Getting Started with Modern Python Web Apps

ASP.NET Core gives you a project template, Program.cs, a dependency injection container, configuration providers, middleware, and Kestrel. In Python, you assemble...

Open chapter
Chapter 2

Understanding the Python Web Stack

ASP.NET Core applications run through Kestrel and an HTTP middleware pipeline. Python has two major web server interfaces:

Open chapter
Chapter 3

Your First Application

Start with a vertical slice: route, model, service, test. Do not start with a grand architecture.

Open chapter
Chapter 4

Middleware and the ASGI Pipeline

ASP.NET Core middleware wraps the request delegate. ASGI middleware does the same conceptual job: inspect or modify requests and responses around downstream handling.

Open chapter
Chapter 5

JSON APIs with FastAPI

FastAPI's core strength is JSON APIs with typed contracts. This is the closest match to ASP.NET Core minimal APIs and Web API controllers.

Open chapter
Chapter 6

Routing

ASP.NET Core endpoint routing maps URLs and HTTP verbs to handlers. FastAPI routes are path operation decorators.

Open chapter
Chapter 7

Request Binding and Validation

ASP.NET Core binds route values, query strings, headers, forms, and bodies. FastAPI does the same using function parameters, Annotated, and Pydantic models.

Open chapter
Chapter 8

Dependency Injection and Dependencies

ASP.NET Core has a full DI container with singleton, scoped, and transient lifetimes. FastAPI has dependency functions. They are less formal, but request-scoped...

Open chapter
Chapter 9

Registering Services and Application Composition

ASP.NET Core centralizes registration in Program.cs and extension methods. Python usually uses explicit module-level composition.

Open chapter
Chapter 10

Configuration and Settings

ASP.NET Core has layered configuration providers and options binding. Python commonly uses environment variables with a typed settings class.

Open chapter
Chapter 11

Documenting APIs with OpenAPI

FastAPI generates OpenAPI from routes, type hints, Pydantic models, status codes, tags, summaries, descriptions, and security dependencies.

Open chapter
Chapter 12

Saving Data with SQLAlchemy and Alembic

EF Core is integrated into the .NET ecosystem. SQLAlchemy is powerful, mature, and more explicit. Alembic handles migrations.

Open chapter
Chapter 13

Creating a Website with Templates

ASP.NET Core offers Razor Pages and MVC views. FastAPI does not include a page framework, but Starlette supports Jinja2 templates.

Open chapter
Chapter 14

Mapping URLs to Pages

Razor Pages map page files to routes. FastAPI maps functions to URLs. To keep page routes maintainable, group them by feature.

Open chapter
Chapter 15

Generating Responses with Handlers

ASP.NET Core handlers return IResult, IActionResult, model objects, redirects, files, or pages. FastAPI handlers can return Python data, response objects...

Open chapter
Chapter 16

Binding and Validating Forms

HTML forms are not JSON. FastAPI can bind form fields, but it is more manual than Pydantic JSON bodies.

Open chapter
Chapter 17

Rendering HTML with Jinja2

Razor views and Jinja2 templates solve the same broad problem: mix static markup with server-provided data.

Open chapter
Chapter 18

Building Forms and Reusable UI Helpers

ASP.NET Core Tag Helpers reduce repetitive form markup. In Python/Jinja2, use macros, partial templates, or a form library.

Open chapter
Chapter 19

Creating a Website with Controller-Style Routers

MVC controllers group related actions. In FastAPI, APIRouter modules fill that role.

Open chapter
Chapter 20

Creating HTTP APIs with Router Modules

ASP.NET Core Web API controllers often use attributes, filters, route prefixes, and action results. FastAPI router modules give the same larger-scale organization.

Open chapter
Chapter 21

Filters, Dependencies, and Cross-Cutting Concerns

ASP.NET Core has filters for MVC and Razor Pages. FastAPI does not have the same filter taxonomy. The closest tools are:

Open chapter
Chapter 22

Creating Custom Request Components

ASP.NET Core lets you build custom middleware, filters, model binders, and result types. FastAPI and Starlette let you build custom dependencies, middleware, routes...

Open chapter
Chapter 23

Authentication

ASP.NET Core Identity is a complete membership system. FastAPI does not ship an equivalent. You choose:

Open chapter
Chapter 24

Authorization

Authentication answers "who are you?" Authorization answers "what may you do?"

Open chapter
Chapter 25

API Authentication and Bearer Tokens

ASP.NET Core APIs commonly use JWT bearer authentication. FastAPI supports OAuth2 and bearer token dependencies, but you must decide token issuing, validation, and...

Open chapter
Chapter 26

Logging and Troubleshooting

ASP.NET Core has structured logging abstractions. Python has standard logging, plus libraries such as structlog and loguru. For production services, prefer standard...

Open chapter
Chapter 27

Publishing and Deployment

ASP.NET Core deployments publish build output. Python deployments usually install your package and run an ASGI server.

Open chapter
Chapter 28

HTTPS, TLS, and Proxy-Aware Apps

ASP.NET Core often handles forwarded headers and HTTPS redirection. Python apps are commonly behind a reverse proxy, load balancer, or platform edge.

Open chapter
Chapter 29

Security Best Practices

Security in Python web apps is a combination of framework features, dependencies, deployment, and habits.

Open chapter
Chapter 30

Application Startup, Lifespan, and Hosting

ASP.NET Core has host startup, dependency registration, and app lifetime events. FastAPI uses lifespan events for startup and shutdown.

Open chapter
Chapter 31

Advanced Configuration

Once RecipeVault grows, split configuration by concern.

Open chapter
Chapter 32

Custom Web Components and Framework Extensions

ASP.NET Core developers often build custom model binders, tag helpers, middleware, and filters. Python gives you several smaller extension points.

Open chapter
Chapter 33

Calling Remote APIs

ASP.NET Core uses HttpClientFactory to manage clients and avoid socket exhaustion. Python commonly uses HTTPX.

Open chapter
Chapter 34

Background Tasks and Services

ASP.NET Core has hosted services and background services. FastAPI has in-process background tasks, but they are only suitable for small, non-critical follow-up work.

Open chapter
Chapter 35

Unit Testing

ASP.NET Core developers often use xUnit, Moq, and FluentAssertions. Python's standard path is pytest.

Open chapter
Chapter 36

Testing Web Applications

FastAPI testing uses a test client for HTTP-level tests and dependency overrides for test seams.

Open chapter
Chapter 37

Capstone Build Plan

Build RecipeVault in slices. Each slice should have code, tests, and a visible result.

Open chapter