HeadlinesBriefing favicon HeadlinesBriefing.com

baredtype: Python Validation Without Custom Classes

DEV Community •
×

Python developers often rely on flexible dict and list structures for data flow. The baredtype library bridges this native approach with formal validation, enforcing strict rules without forcing data into custom classes. It leverages modern Python features like TypedDict and Annotated to describe structures precisely while maintaining JSON compatibility.

Unlike other validation libraries, baredtype doesn't require wrapping data in new objects. You validate standard Python dictionaries using the library's `validate` function, then serialize and deserialize them with standard `json` methods. This approach respects existing code patterns and handles None values and optional keys naturally through Python idioms.

The library maps Python types to external standards like JSON Schema and OpenAPI, handling complex type combinations through oneOf and allOf quantifiers. It supports both static type checking with tools like Mypy and property-based testing with Hypothesis for generating edge cases. Runtime validation remains essential for untrusted external data, providing a final check against your specifications.