Lightweight runtime type validation for Python. For real.
Low maintenance activity. Last release 8 months ago, commits in 0 of the last 26 weeks. Weaker on commit activity and release cadence.
Consider insteadtype-enforcedPythie’s Index: 8488.8K downloads/moCompare →
pip install frfrfrfr
lightweight runtime validation. actually valid. for real.
what is this
frfr (for real for real) validates your data at runtime against Python types. you pass a type and some data, and it either gives you back a properly typed instance or tells you exactly why your data is cap.
import dataclasses
import frfr
@dataclasses.dataclass
class User:
name: str
age: int
data = {"name": "bestie", "age": 27}
user: User = frfr.validate(User, data) # User instance or ValidationError
that's it. that's the whole api.
install
uv add frfr
# or
pip install frfr
requires python 3.12+ — frfr uses modern typing features (PEP 695 type parameter syntax, type statement) that aren't available in earlier versions.
quickstart
frfr handles the nested, optional, union-y stuff you actually deal with:
import dataclasses
from typing import Literal
import frfr
@dataclasses.dataclass
class Address:
street: str
city: str
country: str = "US"
@dataclasses.dataclass
class Person:
name: str
address: Address | None
role: Literal["admin", "user", "guest"]
tags: list[str]
data = {
"name": "bestie",
"address": {"street": "123 Main St", "city": "Springfield"},
"role": "admin",
"tags": ["verified", "early-adopter"],
}
person: Person = frfr.validate(Person, data)
# Person(name='bestie', address=Address(street='123 Main St', city='Springfield', country='US'), role='admin', tags=['verified', 'early-adopter'])
nested dataclasses, optional fields, union types, literals, defaults — all validated recursively with clear error paths.
why frfr?
it's strict
other validation libs play fast and loose with types. frfr doesn't.
frfr.validate(int, "1") # ValidationError - "1" is a string, not an int
frfr.validate(int, True) # ValidationError - bool is not int, even in python
frfr.validate(int, 1.0) # ValidationError - float is not int, even if it's 1.0
if you want string-to-int coercion, let your json parser handle it. frfr validates types, fr fr.
it coerces when it makes sense
frfr.validate(float, 7) # 7.0 - int to float is lossless
frfr.validate(tuple[str, ...], ["a", "b"]) # ("a", "b") - list to tuple