Skip to main content

Pyfake

A flexible, schema-driven fake data generator built on top of Pydantic v2.

Documentation · Github · PyPI

Generate valid 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 valid ❌ Generates strings for emails, URLs or IP addresses that fail validation ✅ Format-aware generators for EmailStr, HttpUrl, DSNs, IP addresses, UUIDs and regex patterns
Support for constraints ❌ Ignores field constraints like min_length, gt, multiple_of ✅ Respects Pydantic constraints: bounds, lengths, multiple_of, max_digits/decimal_places, pattern, and conint/constr-style types
Support for python types ❌ Limited support for complex types like Decimal, UUID, datetime ✅ Supports Decimal, UUID, datetime, timedelta, bytes, enums, literals, nested and self-referencing models, and more
Clear failures ❌ Silently returns invalid data ✅ Raises an error that names the field when a type or constraint can't be satisfied
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
  • Picks a generator for each field (realistic names and addresses are on the roadmap)
  • Validates the result with your model, so every value it returns is valid

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.14

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.14
File Size Uploaded Provenance Actions
pyfake-0.0.14.tar.gz 28.9 kB Without provenance Details for pyfake-0.0.14.tar.gz

Built distribution (wheel)

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

Total release size: 57.2 kB

Release files / pyfake-0.0.14.tar.gz

Download URL pyfake-0.0.14.tar.gz
Size 28.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f76d28e55672014e58af13f53402aed4be5149874e9687b7ff505a77fcfbc6e8
BLAKE2b-256 checksum
How to use checksums
44ed9a1210a56d2c45a51a0d949fef00f49a1c037832a2f4dbdf6b5d24e966b7
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.14-py3-none-any.whl

Download URL pyfake-0.0.14-py3-none-any.whl
Size 28.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b50d94432b1a6ae9602bbb6a80f5fd1bf0baf0a6bfdf5c45dfe5f6a12eef252a
BLAKE2b-256 checksum
How to use checksums
4bc402bf6368717c8c26c7bc3d5f02dc0b481659db4dd90463469d5f553659da
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}

Security for pyfake 0.0.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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