04.04

Settings and configuration

skillmaxingPython with AISettings and configuration
Visual lesson

Settings and configuration

Included with Pro · 4:22
Lessons · 917 words

A database URL, an OpenAI key, the list of origins allowed to call your API: these are inputs to your program, they arrive from outside as strings, and a wrong one should fail loudly. That is the same problem Pydantic solves for request bodies, and pydantic-settings applies the same tool to the environment. You declare a Settings class, it reads environment variables and a .env file, converts them to typed values, and refuses to start if something required is missing.

The alternative, os.environ["DATABASE_URL"] scattered through modules, fails at whatever moment that line first runs, which in a web service is often the first request after a deploy. A settings class moves that failure to process start, where it belongs.

Pro

Continue reading

Pro unlocks every video lesson, the full notes and runnable code across the Python with AI course, from the language itself to agents, MCP, Langfuse and deployment.

Unlock full access to
Python with AIAI researchComplete system design
30% off with LAUNCH30ends in 7h 40m
Buy now
View all plans ·Already Pro? Sign in
124 online