Replace your YAML configs with Pydantic
YAML sucks. Just look up “The yaml document from hell” if you don’t believe me.
But you’ll find it all over the place: Google App Engine, Kubernetes, GitHub Actions…
So I was like - screw that - and I wrote a script that allows me to express these configs as Python code using Pydantic and then convert it to YAML.
This method of writing config allows you to bake validation directly into your application. And it’s hella cool.
Check out the video on YouTube
Topics
Advantages of Pydantic Configuration:
Type safety and validation ensuring correct data types and value ranges.
Dynamically generating configuration files from database values.
Creation of domain models that enhance development with features like autocomplete and type hinting in IDEs.
Practical Examples:
Logging Configuration:
Creating a logging configuration using Pydantic.
Validation of logging configuration.
Generating and using YAML configuration from Python code.
Google Cloud Platform (GCP) App Engine:
Expressing App Engine configuration with Pydantic.
Validation of configuration for resources like CPU and memory.
Generating YAML file from Python configuration and deploying it.
Kubernetes Configuration:
Modeling Kubernetes configurations with Pydantic.
Generating and validating Kubernetes YAML configuration from Python code.
CI/CD with GitHub Actions:
Converting CI/CD pipeline configurations to Pydantic.
Handling YAML keys that are not Python variable-friendly (e.g., dashes in keys).
Using aliases to map YAML keys to Python-friendly names.
Validating CI/CD configurations with Pydantic.
Namaste,
Alex
If you accept a poorly executed shot attempt or a half ass lat workout as good enough, then your more likely to accept half ass versions of other more important things from yourself.
Arnold Schwarzenegger