Skip to main content

Pyfake

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

Metadata

Release files for pyfake 0.0.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyfake 0.0.13
File Size Uploaded
pyfake-0.0.13.tar.gz 16.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyfake 0.0.13
File Interpreter ABI Platform
pyfake-0.0.13-py3-none-any.whl Python 3 none any Details

Total release size: 33.8 kB

Release files / pyfake-0.0.13.tar.gz

Download URL pyfake-0.0.13.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5513b7b2e963588f615612b71524fc3dc0cfd9603203abf43cca295cbf10c32f
BLAKE2b-256 checksum
How to use checksums
dd35d03b406036041fea757a120f429d5955e0325299daec474285c072cd489b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / pyfake-0.0.13-py3-none-any.whl

Download URL pyfake-0.0.13-py3-none-any.whl
Size 16.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9c9d046ee1c7fa281fba90cfa0b45e7541053f830ed0c453f92472366df3b88e
BLAKE2b-256 checksum
How to use checksums
819be99ed9c4321f843a44a148407ca2618c915949c0c189ba9b629d8ed32f1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.0.13 This release

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page