Pyfake
A Flexible and Extensible fake data generator based on Pydantic models.
Docs: pyfake.readthedocs.io/en/latest • Source: github.com/Mukhopadhyay/pyfake
✨ Why Pyfake?
Most fake data generators are either:
❌ Random but not structured
❌ Structured but not realistic
❌ Hard to extend
Pyfake fixes that.
It leverages Pydantic models as the single source of truth to generate:
- Validated data
- Schema-aware fake data
- Easily extensible generators
- Strong typing + IDE autocomplete
Quick Example
from pyfake import Pyfake
from pydantic import BaseModel, Field
from typing import Annotated, Union
class SubModel(BaseModel):
sub_integer: int
sub_string: str
class Model(BaseModel):
integer_field: Annotated[int | None, Field(ge=0, le=100)]
string_field: Annotated[str, Field(min_length=5, max_length=10, pattern=r"^[a-zA-Z]+$")]
multi_type_field: Union[Annotated[int, Field(ge=0, le=100)], Annotated[str, Field(min_length=3, max_length=15)]]
sub_model: SubModel
users = Pyfake.from_schema(User, num=5)
print(users)
python example.py
{
'integer_field': None,
'string_field': 'kEwkDX',
'multi_type_field': 'rTCtez',
'sub_model': {
'sub_integer': 34,
'sub_string': 'WuUoAyokHe'
}
}
{
'integer_field': None,
'string_field': 'kEwkDX',
'multi_type_field': 'rTCtez',
'sub_model': {
'sub_integer': 34,
'sub_string': 'WuUoAyokHe'
}
}
Installation
uv add pyfake
python -m venv .venv
source .venv/bin/activate
pip install pyfake
From source
pyfake can be downloaded directly from github as well
How It Works
Pyfake reads your Pydantic schema and:
- Inspects field types and constraints
- Applies intelligent generators
- Produces validated fake data
flowchart LR
A[Pydantic Model] --> B[Schema Parser]
B --> C[Generator Engine]
C --> D[Validated Fake Data]
