A fake data generator that is pydantic compatible.
Project description
A flexible, schema-driven fake data generator built on top of Pydantic v2.
Documentation · Github · PyPI
Generate realistic fake data for your Pydantic models with ease. Perfect for testing, prototyping, and anywhere you need valid mock data.
⚡ Quick Example
from typing import Annotated, List, Set, Literal
from pydantic import BaseModel, Field
from pyfake import fake
from rich import print
class Playlist(BaseModel):
track_ids: List[int]
genre: Literal["rock", "pop", "jazz"]
tags: Annotated[List[str], Field(min_length=2, max_length=5)]
unique_ratings: Set[int]
result = fake(Playlist, as_dict=True)
print(result)
# {
# "track_ids": [28, 25, 95, 40],
# "genre": "pop",
# "tags": ["CJKHILHXTN", "qkhhjDJYiV"],
# "unique_ratings": {17, 49}
# }
✨ Why Pyfake?
| Problem | Most fake data generators | Pyfake |
|---|---|---|
| Random but not structured | ❌ Generates random data without understanding the schema | ✅ Reads your Pydantic models to produce structured, schema-aware data |
| Structured but not realistic | ❌ Generates data that fits the schema but isn't realistic (e.g. random strings for names) | ✅ Uses intelligent generators to produce realistic fake data (e.g. names, addresses) |
| Hard to extend | ❌ Difficult to add custom generators or handle complex types | ✅ Easily extensible with a flexible generator registry and schema resolution system |
| Support for constraints | ❌ Ignores field constraints like min_length, gt, multiple_of |
✅ Respects all Pydantic field constraints when generating data |
| Support for python primitive types | ❌ Limited support for complex types like Decimal, UUID, datetime |
✅ Full support for Python primitives, including Decimal, UUID, datetime, and more |
| Reproducibility | ❌ No built-in way to generate the same fake data across runs | ✅ Supports seeding for reproducible fake data generation |
🧠 How It Works
Pyfake reads your Pydantic schema and:
- Inspects field types and constraints
- Applies intelligent generators
- Produces validated fake data
Installation
Using uv (Recommended)
uv add pyfake
Using pip
python -m venv .venv
source .venv/bin/activate
pip install pyfake
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyfake-0.0.9.tar.gz.
File metadata
- Download URL: pyfake-0.0.9.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36f5ec8b336c7d4e7844a51ba9e97d3b97907c205c3b77cf2089f07f8b7596b2
|
|
| MD5 |
c850cda1cae9a83ffda7a31efb7fc49d
|
|
| BLAKE2b-256 |
9437d07e29641a4865628fae9e2e151c8354d56870c920bb5c096593a9824c2b
|
File details
Details for the file pyfake-0.0.9-py3-none-any.whl.
File metadata
- Download URL: pyfake-0.0.9-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34c8a6aa5edc89252824987085066a7fac11876358626a9f91588e551e91de45
|
|
| MD5 |
e372eb4d83804f0860fd0b0e29e2b13c
|
|
| BLAKE2b-256 |
4d17a0f7fe6f44d660bf1c0a40d622801e472cd0e69c6320b7c29c80b65155ae
|