
Define declarative Pydantic models with Python type hints to validate, serialize, and deserialize data while generating automatic docs and enabling type-checker integration.
Define a data model by creating a Python class that inherits from the Pydantic base model. Specify name, age, and email using type hints, then instantiate it to trigger validation.
Pydantic coerces data to the type by default, converting strings like 25 to integers, while strict types model config or strict int enforce exact types and raise errors on casting.
Extend your data models with pydantic by constraining age to 18–120, name to 3–50 characters, and validating emails with EmailStr and the email-validator package.
Explore pedantic data types in Python, including date, time, and datetime from the typing module, to validate data in pydantic models.
Define and validate lists in pydantic, from simple string lists to nested 2D grids, and compose ingredients into recipes. Enforce size constraints with field and typing List.
Explore dictionaries and typed key-value structures in pedantic, annotate with dict vs typing dict, validate multi-level data, and implement nested models like product catalogs and order books.
Explore sets and tuples in python with pedantic typing, learning duplicate removal, type enforcement, and how fixed or variable length tuples model 3d coordinates and lists.
Explore union types in Pydantic, allowing a field to accept multiple models like car, motorcycle, or truck, and learn how validation depends on the union order and shared base models.
Explore how to declare optional and nullable fields in pydantic using the optional type, set defaults including optional any, and use runtime default factories in newer versions.
Learn how UUIDs provide globally unique identifiers using Python's uuid module and implement default factories to auto generate IDs for models, enabling seamless user creation.
Explore immutability in Python by enforcing model and attribute level constraints with Pydantic, ensuring data integrity and predictable state in concurrent applications through frozen models and frozen fields.
Explore how pedantic data handles implicit type conversions and extra attributes, and how to switch between ignore, forbid, and allow for model instantiation, including strict mode.
Learn how Python enums define a fixed set of values and how to enforce them in Pydantic models to improve validation, readability, and data integrity.
Compare enums and typing literals to constrain attribute values in Pydantic models, showing literals offer similar validation with significantly better performance on modern Python versions.
Define custom validators to encode complex rules—such as age being at least 18 and even—using field validator decorators and class methods that run after instantiation.
Explore model level validation in pydantic by using before validators to enforce cross-field rules like start date before end date, and after validators as an alternative.
Explore how Pydantic error objects convey validation details by inspecting value errors, validation errors, and their class hierarchy, and learn to access messages, types, input values, and json representations.
Learn how to serialize Pydantic models to dicts and json strings, using model_dump and model_dump_json, and understand the differences between dictionaries and json for web data exchange.
See how to tailor pydantic serialization by using exclude and include to select fields. Use logical knobs like exclude unset and exclude defaults to control which attributes are serialized.
Build and inspect json schemas from Pydantic models to document, code generate, and create user interfaces, using the model json schema method and the json schema standard.
Convert serialized json data into model instances with the model validate json method, turning it into Python objects. Handle validation errors to distinguish valid users from invalid ones.
Cover building and deploying a fast API web app from scratch using pydantic models for polls and voters, with input validation, vote by label, results tracking, and Vercel serverless deployment.
Create a Python virtual environment to isolate dependencies, ensure consistency across development and deployment, and control package versions. Activate the environment to run projects without affecting the global Python installation.
Activate your virtual environment and install FastAPI and uvicorn to build fast Python APIs with pydantic integration. Stick to the same versions to avoid surprises.
Learn to structure a Python application with a main entry point, dotenv env vars, and packages for pydantic models, API routes, services, and config, using dunder init for clean imports.
Implement a minimal FastAPI API that returns 'Hello there', run with uvicorn, expose a /test endpoint, and leverage type hints and pedantic models to auto-generate Swagger docs.
Define a pedantic pydantic poll model with id, options, and created_at fields, using UUID and UTC datetime default factories, with options as strings initially and later as choice instances.
Define a post route /polls/create to return a new poll instance using the poll pydantic model with options, while auto-generating id and createdat.
Update the poll model to include a 5–50 character title and an expiry date, and require a poll object in the create poll request body, showcasing Pydantic and FastAPI integration.
Define a new Pydantic choice model with id, description, and label, enforcing uuid default, description 1–100 characters, and label 1–5, to support polls and automatic label generation.
Learn to split a data model into write and read models with choice create and choice read, enabling minimal user input while the backend generates id, label, and persistence-ready data.
Learn to split the poll model into a write poll create model and read poll model, with title, options as strings, optional expires, and id and created_at in read only.
Implement a pydantic field level validator in the poll create data model to enforce the options list length between 2 and 5 and raise a value error.
Learn to implement a create poll instance method in pydantic that converts option strings into choice instances with incrementing labels, validates future expiration dates, and returns a new poll instance.
Wire up the create poll method to the polls create endpoint so a post request yields a new poll with a generated uuid and confirmation.
refactor validation errors into http exceptions with FastAPI to return json responses and status codes. enforce poll rules, 2–5 choices and future expiration, with 400 messages and 200 success.
Explore Redis as an in-memory key-value store for database, cache, and message broker. Learn open-source roots, data structures such as strings and streams, and a cloud-hosted durable Redis instance.
Set up free GitHub and Vercel accounts, create a Vercel kv database named polling app, and obtain the api token and rest url to access Redis instance at no cost.
Explore connecting to Redisai instance using the app stash sdk, then create simple save and get endpoints to store and retrieve data by id, with plans to refactor.
Move secrets from code to environment variables using a dot env file and python-dotenv. Load them with load_dotenv and access via os.getenv to configure Redis URL and token across environments.
Create utils.py in the services package and implement save_poll to persist a poll's json to redis under poll:<poll_id>, preparing for http endpoint integration.
Persist newly created polls to Redis by invoking utils.save_all with the new poll instance in the POST /polls/create endpoint.
Retrieve polls from Redis, deserialize to a poll object, validate against the poll data model, and expose a get polls by poll id route that returns the poll or 404.
reorganize fastapi app by moving poll routes from main.py into a dedicated api router module, integrate with the app using include_router under the polls prefix, enabling modularity and future expansion.
Rename the app to polls API and update the metadata with a descriptive title, description, and version 0.1. Define open API tags for polls and plan future tags.
Learn how faster iteration with a visual http client like Postman streamlines API testing for polls, using create and get by id, with automated tests and global variables.
Validate voting data with pydantic models, separating read and write structures for votes and voters, enabling vote by id or label using poll id, choice id, and voter email.
Define a votes router with post routes for vote by id and vote by label, reading poll id from path, using pydantic models, and integrate under /votes for swagger visibility.
Define a utility that converts a poll label into its corresponding choice uuid by fetching the poll and matching the label to a choice id.
Return full vote instances on the voting routes, including poll id, choice id, and voter. Prepare to persist these votes to Redis.
Define save vote and get vote utilities using Redis hash sets, saving with hset and retrieving with hget, storing under votes:pollId with fields voter_email and vote_json.
Integrate the save vote utility with the voting routes to persist each successful vote to Redis by calling utils.save_vote with the poll ID and vote object.
Prevent duplicate votes by checking whether a voter's email already voted in the poll before saving the vote. Validate with a get vote utility and plan a dependency-injected refactor.
enforce pre-voting validations by checking poll expiry before recording a vote; implement an is_active method on the poll model using expires_at, and raise an exception if the poll has expired.
Implement robust validations in the poll voting routes by checking poll existence and validating the selected choice against poll options, with error handling for not found and bad requests.
Refactor the get choice id by label to use a poll object and a shared utility, avoiding unnecessary database calls and streamlining router logic with utils.
Create a common validations dependency to centralize poll and vote checks for both vote by id and vote by label routes, and inject it with fastapi.
Implement a get polls endpoint that returns all polls from Redis by fetching keys with the poll prefix, deserializing to the poll model, and returning the list.
Batch Redis calls with mget to fetch all poll jsons in one request, reduce RTT, and deserialize with a list comprehension using poll.model_validate_json.
Enable server-side filtering on the get polls endpoint for active, expired, or all statuses; use a three-value enum defaulting to active as an optional query parameter and return a count.
Track poll results by incrementing vote counts in Redis with hash increment by poll ID and choice ID, while saving votes updates the full vote JSON and enables fast tallying.
Implement a get vote count utility and a poll results endpoint to retrieve and display vote tallies for a given poll id, returning a dictionary of choice ids and counts.
Define two Pydantic data models for human readable poll results: a Result with description and vote count, and a PollResults with title, votes, and a list of Result objects.
Create a get all results helper that outputs a poll’s title, total votes, and per-choice descriptions with vote counts, sorted descending for readability and API integration.
Implement a delete poll utility to remove all Redis keys for a poll ID, including polls, votes, and vote counts, via a new delete route under the danger tag.
Discover how to build a custom validation exception handler in FastAPI to reshape Pydantic errors into concise JSON responses and integrate it with your app.
Follow a six-step deployment checklist to push a FastAPI app to the web, including freezing requirements, configuring vercel.json, and creating git repos before a free Vercel deployment.
Freeze dependencies with pip freeze and create a precise requirements.txt for consistent deployments. Configure Vercel with json file containing builds and routes to run main.py as a serverless Python function.
Explore how to define a .gitignore to exclude environment variables, virtual environments, macOS system files, and Python bytecode, then initialize a local git repo and stage code for version control.
Create a private remote GitHub repository and push your existing local project from the command line, ensuring gitignore, main.py, and requirements.txt go to the remote before Vercel deployment.
Deploy the app to Vercel, configure environment variables from the dot env using load_dot_env, import the git repository, and verify the swagger docs at the polls API URL.
Explore Python data types, from integers and floats to booleans, strings, tuples, lists, sets, dictionaries, and the none type, and learn how type() reveals an object's kind.
Learn how variables bind values to names as pointers in memory, with descriptive identifiers, snake_case, and Python's case sensitivity, while avoiding reserved keywords like else.
Explore basic and augmented arithmetic operators in Python, including +, -, *, /, +=, and **, plus modulo for even/odd checks and the rule of operator precedence.
Explore integers and floats in Python, learn how int and float conversions work, and examine floating point precision and binary representation with examples like 0.1 versus 0.2.
Master booleans in Python by using true and false, apply operators like ==, !=, >, <, >=, <=, and combine with and, or, not to express truthiness and complex conditions.
Learn strings as ordered sequences of characters; use single or double quotes, and apply escaping and alternating quotes to include quotes. Master concatenation, repetition, and multi-line strings.
Explore how methods attach to objects, differ from functions, and use string methods like upper, lower, is alpha, starts with, ends with, and the format method for substitution.
Explore Python lists, their zero-based indexing, and how to access items with indices and slices. Learn negative indexing, slice upper bounds, and common index errors.
Compare strings and lists as sequences of characters and objects, practice accessing items by index and slice, and discuss order and immutability for both data types as explained.
Explore built-in list functions such as max, len, and sort, and learn how to use append, pop, remove, and join methods with separators to convert lists into strings.
Explore tuples, an immutable, ordered Python container similar to lists that uses optional parentheses, supports index-based access, and pairs related values like SAT scores or coordinates.
Learn Python sets as unordered containers of unique values, created with braces; add and discard elements, perform union, intersection, and difference, remove duplicates by converting a list to a set.
Explore dictionaries in Python, a key-value data structure built with curly braces. Access with square brackets or get, handle missing keys, and add or remove entries via assignment and pop.
Explore how dictionaries map immutable keys to diverse values such as integers, lists, or nested dictionaries, and learn key methods like keys, values, and items, plus their unordered nature.
Explore membership operators in Python, using in and not in to test dictionary keys and items in lists, tuples, and sets, and note that Python uses in instead of contains.
Learn to control program flow with if, else, and elif by evaluating boolean conditions, using comparison operators, and managing blocks and indentation to determine pass or fail outcomes.
Explore Python's truthiness in if conditions by examining which objects evaluate to true or false, including numbers, None, empties, and non-empty collections.
Learn how for loops in Python iterate over iterables to execute a block of code for each item, print greetings, and understand iteration variables in lists and strings.
Learn the range in Python as an immutable sequence of integers with start, stop, and step. Use it in for loops; stop is exclusive, and range(n) defaults to start=0 and step=1.
Explore while loops in Python, learn how they run until a condition is met, and see how a doubling cost and shrinking balance determine how many rounds you can play.
Learn how break exits a loop and how continue skips iterations in Python for and while loops, illustrated by greeting examples and one-line equivalents.
Zip multiple Python iterables to create paired tuples from names and scores, see how to unpack these tuples for per-person output, and extend with attendance data.
Master list comprehensions in Python to build and filter lists with concise, one-line syntax. Filter by odd numbers or scores above 90, and extract student names from dictionaries.
Learn to define reusable Python functions to compute averages and apply them to lists, then enrich student records with average and past keys via a loop.
Learn the difference between positional and keyword arguments in Python by using a reverse name function, mixing argument types, and avoiding a syntax error with keyword before positional.
Explore lambda functions in Python, defining anonymous one-line functions for concise use with map and similar patterns, useful for single-place computations and later pandas methods.
Explore how Python modules and the standard library organize code with variables, functions, and classes. Learn import patterns, from-import, aliasing, and using statistics.mean to compute averages.
Welcome to the best resource online for learning modern Pydantic, a data validation library that has taken the python community by storm.
Pydantic is was first released in 2018 and has since become one of the most popular python libraries. It is nowadays downloaded more than 130 million times a month, and is used by some of the largest organizations out there, from the tech giants like Google, Amazon, Apple, Meta, and Netflix, to large conglomerates in various other industries, such as Starbucks, JPMorgan Chase. Oh, and yes, even NASA.
There's a good reason for this. Pydantic is a powerful library that elegantly solves a very common problem in software development: data validation.
Pydantic's speed, simple declarative syntax, and extensibility make it an indispensable utility in modern python development.
And in this course, you will learn everything you need to know to get started with Pydantic, from the very basics of defining data models, to more advanced topics such as fields with factory defaults, creating custom model-validators, data serialization, and much more.
The first part of the course will be purely about pydantic, where we explore it in isolation. You will learn:
how to define data models with pydantic
how to compose more complex models from simpler ones via inheritance
the foundations of type hinting in python, including enumerations, literals, and other advanced types-
how to use pydantic's powerful validation system
how to serialize and deserialize data
how to extract models to schemas
how to validate data against pydantic models
Then in the second part of the course we will turn our attention to the Capstone Project, where we will use pydantic to develop and deploy a python web API that allows users to create and vote on polls. This app will use Redis as our durable key-value data store, and will be deployed to production as a serverless function.
The Capstone will be developed step by step, in a series of about 30 skill challenges, where you will be asked to incrementally implement small features. This will give you the opportunity to practice what you've learned in the first part of the course, and to:
get a practical feel for how Pydantic is used in real-world applications
learn about modern API development with python
understand what Redis is and how it can be used as a durable data store
learn about virtual environments and dependency management in python
practice using git and github
learn the basics of serverless computing by deploying the API as a serverless function
The course will use the latest version of Pydantic, which leverages the power of Rust to achieve blazing fast performance.
Also, if you're new to python or haven't used the used the language in a while, there's a full-featured python crash course included as an extra appendix which will get you up to speed in no time.
I'm very excited to share this with you, and I look forward to seeing you in the course!