π£οΈ Week 03 Lecture
Data Validation with Pydantic Models

Last Updated: 02 February 2025, 13:45.
Welcome to Week 03 of DS205!
As you may recall, we will continue to work on our API development skills this week. This particular session will focus on Data Validation with Pydantic Models in FastAPI sprinkled with a bit of practical testing skills.
π Session Details
- Date: Monday, 03 February 2025
- Time: 10:00 am - 12:00 pm
- Location: KSW.1.01
π£οΈ Lecture Content
Instead of slides, this will be a full π¨π»βπ» live demo lecture. You will find the material for study later on our dedicated GitHub Repository: lse-ds205/ascor-api.
I will create a dedicated branch for todayβs lecture, and then I will make git
commits as we go along, so you can follow the changes in real-time and study from the code later.
1. Recap: API Development Journey
- Brief review of π£οΈ Week 02 concepts
- Common challenges encountered in the formative exercise so far
- The importance of testing in API development
2. Testing FastAPI Code: A Practical Guide
- Writing testable Python functions
- Separating business logic from API routes (using Notebooks vs unit tests)
- Unit testing basics for API functions
- Test-driven development approach
3. Data Validation with Pydantic
- Introduction to Pydantic Models
- Type hints and data validation
- Creating custom data models
- Handling nested data structures
- Validation Features
- Required vs optional fields
- Field constraints and validators
- Custom validation logic
4. Interactive API Documentation
- Understanding FastAPIβs
/docs
(now I know how to get it to work on Nuvolos ;))- OpenAPI (Swagger) documentation
- Testing endpoints through the UI
- Reading error messages
π Next Steps
- Review the practical examples from todayβs lecture
- Continue working on the π W02-W03 Formative Exercise
- Attend this weekβs lab session for hands-on support with your API development
π₯ Session Recording
The lecture recording will be available on Moodle after the session, typically by Monday afternoon.