πŸ—£οΈ Week 03 Lecture

Data Validation with Pydantic Models

Author
Published

02 February 2025

Image created with the AI embedded in MS Designer using the prompt 'abstract green and blue icon depicting the advanced stages of data wrangling, API design, and scalable pipelines for sustainability-focused data engineering.'

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

  1. Review the practical examples from today’s lecture
  2. Continue working on the πŸ“ W02-W03 Formative Exercise
  3. 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.