Sphere
Log in Join
☆ 7

Dataclass or Pydantic model for application config?

Config comes from environment variables and a YAML file. I want validation for ports and URLs. Pydantic feels heavy for ten fields but dataclasses have no validation. What do you use?

⚑ Report

3 replies

☆ 0
Z Zoe ·2026-10-01#1

For anything from outside the process, Pydantic pays for itself. A bad port fails at startup instead of at 3am.

⚑ Report
☆ 0
A Amir ·2026-10-01#2

My concern is import time and the extra dependency in a small Lambda.

⚑ Report
☆ 0
D Dmitri ·2026-10-01#3

Measure it. In most services the import cost is a few tens of milliseconds. If that really matters, parse with a dataclass and validate the handful of fields you care about by hand.

⚑ Report
Log in to reply.