Skip to content

gcotecarrier/pydantic-kata

Repository files navigation

Kata Pydantic

This repository is meant as an interactive way to discover the Pydantic library.

This kata is not meant as a puzzle or a test, but instead as a guided tour through useful Pydantic and Python features.

Pre-requisites to running the kata

Structure of this kata

This kata is separated into multiple parts that increasingly dive into deeper Pydantic concepts.

The earlier parts are standard Pydantic features expected to be used in day-to-day work while the later ones are advanced features for more specific use cases.

To introduce these different concepts, the kata has a suite of mostly red tests that you're supposed to toggle to green. Most of the tests come with a docstring explaining how it can be turned green with some potential gotchas / alternate implementations.

It's recommended to go through the different test files one test case at a time since they will contain helpful comments and display Pydantic features you might not see otherwise.

Rules

There are exactly two rules in this kata:

  1. You cannot change the test code
  2. You must use Pydantic features to make the tests go green

Running the kata

Make targets for all parts are provided :

Target Description
make part_zero Part Zero is an overview of interesting out-of-the-box Pydantic benefits
make part_one Part One is an introduction to enriching your Pydantic models with annotations and field properties
make part_two Part Two is about running Pydantic validation on non-dictionary data and handling different naming conventions
make part_three Part Three is an introduction to using Pydantic settings for your program configurations
make part_four Part Four is a deeper dive into enriching your Pydantic models with more advanced features. Because Part Four builds up Part One, the Makefile will run the tests for both to ensure no regression happened
make part_five Part Five is an example of how you might abstract away the complexity of external models to simplify your internal business rules
make all_parts Run all five parts sequentially

Are you stuck?

If you're stuck and unsure how to proceed further, there's a sample_solutions.zip file at the root of the project that you could peek into.

Of course, looking up all the solutions beforehand defeats the purpose of a learning exercise, so it's recommended to use this sparingly.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published