
Master FastAPI foundations by defining RESTful endpoints, path and query parameters, and pydantic validation. Explore authentication, oauth2 flows, databases, async programming, routers, deployment, and testing.
Explore FastAPI, a blazing fast Python web framework for building APIs, using decorators to create endpoints, validate data, and auto-generate OpenAPI docs with async support.
Install and set up a fast API project with a Python virtual environment, create an app package, install packages, and configure editors like VS Code or PyCharm.
Create a new directory, open it in your editor, and set up a Python virtual environment to install FastAPI, then create main.py for your app.
Define a get route for /shipment in FastAPI that returns shipment data, then start the dev server on localhost:8000 and view the docs at /docs.
Explore python type hinting in fastapi development, distinguishing hints from strict typing, using mypy for static checks, and applying hints to variables, functions, lists, tuples, dicts, and custom classes.
Master path parameters in FastAPI by defining dynamic ids in routes, using type hints to enforce integers or floats, handling validation, and returning structured data.
Understand how route ordering determines which endpoint handles a request with path parameters, testing integer id values, latest shipment routes, and type checking to avoid parsing errors.
Replace hard coded data with a shipments dictionary, fetch the latest or a specific shipment by id, and implement basic error handling for missing ids.
Learn to use query parameters in fast api by appending name=value pairs after a question mark and receiving them as typed route arguments with validation.
Raise an HTTP exception for a non-existent id, switching from the default 200 to 404 not found in FastAPI, with a detail like 'given id does not exist'.
Post a shipment with content and weight, assign an id, and return the id with status placed; enforce a 25 kg limit with a 406 not acceptable error if exceeded.
Combine path and query parameters to build a get shipment endpoint that retrieves a specific shipment field (content, status, weight) by id, returning a field value or a dictionary.
Learn to use the patch method for partial shipment updates, changing only provided fields such as content, weight, or status, while the id remains required and put handles full replacements.
Demonstrates creating a delete endpoint for shipments with the delete method, using a shipment id query parameter, removing the entry via dict pop, and returning a confirmation.
Understand why Pydantic base models improve validation for shipments by defining a shipment schema and using the request body, enabling type validations over query parameters.
Create a Python enum for shipment status with values placed, in transit, out for delivery, and delivered. Use the enum in the API's request body to enforce type safety and validation.
Define separate Pydantic schemas for reading, creating, and updating shipments, using a base schema to avoid repetition. Apply these models to request bodies and responses, enforcing status with an enum.
Explore tips for Pydantic models in FastAPI, including base models, shared fields, and nested schemas. Skip validation with response_model=None, and dump models to dictionaries, excluding none or defaults.
Persist shipment data across sessions by moving from in-memory storage to a JSON file, load shipments on startup, and save updates with a dedicated database module.
Learn why SQL databases suit structured data like shipments, using a SQLite connection to create tables, insert and read via queries, and commit and close the connection.
Learn to read data from a database using a Python cursor, build select queries, and fetch all, fetch many, or fetch one, with where filtering on shipments.
Set the id field as primary key to prevent duplicate shipments, then delete by id with a where clause and commit changes to enforce the unique constraint.
Update shipment data using a sql update statement on the shipment table, setting status to in transit, filtering by shipment id, and committing changes in a sqlite database with Python.
Learn how to safely update database rows using parameterized SQL queries, avoiding string formatting risks, with positional and named placeholders and proper input validation.
Learn to integrate a SQLite database with FastAPI endpoints for shipments, implementing get, create, update, and delete operations, and handle threading considerations for database connections.
Learn to replace raw sql with sql model based database interactions in fast api, defining table classes and injecting sessions into endpoints. Set up a lifespan listener to auto-create tables.
Learn to use SQLModel to model database tables with Python classes, including defining fields, primary keys, enums, and date time objects, and integrating with Pydantic schemas and a database session.
Connect to the database by creating a SQLAlchemy engine with a sqlite URL, enable echo, adjust check_same_thread, and generate the shipment table from the SQL model using metadata.
Use an asynchronous lifespan handler in FastAPI to run startup and shutdown code. Create database tables on startup and manage server lifecycle with a context manager to support API endpoints.
Implement dependency injection in FastAPI to provide a fresh database session per request, using Depends and get_session, interacting with SQLModel through annotated session types.
Annotate values with typing.Annotated to pair a base type with metadata like the unit Celsius. Reuse the annotated type and access metadata via the dunder origin attribute.
use annotated types and depends metadata to inject a session into endpoints. perform create, read, update, and delete on shipments using a sql model and refresh to return ids.
Explore the difference between sql models and api schemas, and how sqlmodel inherits pydantic for validation. Choose to use a single model or separate schemas in fastapi endpoints.
Explore how FastAPI uses asynchronous programming to handle multiple requests while waiting for database responses, then simulate delays with time.sleep to test endpoints.
Convert synchronous functions into asynchronous ones by using the async keyword, work with coroutines and await to run code, and orchestrate coroutine execution with asyncio for endpoints and servers.
Learn to build asynchronous endpoints by marking functions as coroutines, using await and async io run, creating tasks, and coordinating requests with wait for efficient, parallel execution.
Explore using async task groups to create and await multiple coroutines efficiently, with context managed by the with statement and async keyword, handling IO-bound tasks like database queries.
Learn to upgrade from SQLite to PostgreSQL in a FastAPI backend by installing PostgreSQL, creating a database, configuring access, and adding an asynchronous database session for endpoints.
Install and configure PostgreSQL on your system, including the Postgres server and Pgadmin, set a superuser password, and use the default port 5432.
Create a Postgres database with pgAdmin, then read credentials from a .env file into your FastAPI project using pydantic settings to build a Postgres URL for secure connections.
Switch to an asynchronous workflow by using SQLAlchemy's async engine and async session with the Postgres URL from settings, wrapping in a sessionmaker for endpoints.
Learn to structure a fastapi backend by creating an api router, turning endpoints asynchronous, and organizing routes, schemas, and database sessions for scalable backends.
Define a shipment service class to isolate database interactions from endpoint handlers and expose async methods for get, add, update, and delete shipments.
Organize endpoints with an API router by setting a default shipment prefix and tags. Apply global dependencies, router lifespan, and formatting tips for cleaner FastAPI code.
Unlock the Power of APIs with Python and FastAPI!
Ready to transform your Python skills into building blazing-fast, production-ready APIs? This hands-on course is your definitive guide to crafting high-performance APIs using FastAPI and Python.
Go beyond theory and build a complete backend API for a real-world Delivery Management System. You'll master essential backend concepts like the request/response cycle, data modeling, databases, asynchronous programming, and dependency injection – all while leveraging the power of FastAPI's built-in features: asynchronous speed, automatic data validation, OpenAPI support, and exceptional developer productivity.
Python
Even though having a basic understanding of python is required, core language concepts like type hinting, decorator functions, context managers, async programming and others will still be covered.
SQL Database
We will cover databases and SQL from the basics. Especially if you're a beginner, we will first learn the need for structured databases, what SQL is, how to define tables and write SQL queries.
Then we will integrate a SQLite database manually with our FastAPI application and then leverage modern tools like SQLModel to define database table schema and FastAPI's powerful dependency injection to provide database session to API endpoints.
After covering the essentials, we will move onto advanced concepts like asynchronous database (PostgreSQL), manage schema changes with alembic migrations, define one-to-many and many-to-many SQL relationships and link models.
User Authentication
FastAPI has built-in support for OAuth2 Scheme. Implement secure user authentication with OAuth2 Password Flow and handle user signups, email verification of registered users, login, control access to endpoints with JWT, allow password resets and logout users.
Email and SMS Notifications
In our delivery management system, we will send email updates and sms to recipients on shipment updates. Like sending tracking links with email on order placed, shipment status updates, and sending verification codes or OTP as sms to recieve shipments.
API Testing
Learn the basics of the pytest - testing framework. Write and run simple tests, and use fixtures to manage test state. Then, write test for API endpoints with FastAPI's built-in test client.
We will cover required concepts when testing APIs like setting up test databases, overriding dependencies, authentication in test functions and automate testing with schemathesis.
Frontend?
As a bonus, we will also cover frontend web development with React JS. Covering the essentials like components, state management, hooks, context providers and routing. Using modern and meme proof tools like Vite, Axios, React Router, Shadcn UI, and Tanstack React Query.
Docker
Learn the industry standard tool for packaging applications. We will cover the basics of docker and the essential concepts of containerisation. And run our API Server, PostgreSQL database, Redis and Celery background worker seamlessly with Docker Compose.
If you're a Python developer looking to create fast, reliable, and modern web APIs, and if you're eager to understand and build the backend yourself, then this course is your perfect starting point.
Join us in the first lesson and start building today!