pydantic-factories
Mock data generation for pydantic based models and python dataclasses
What it is and what it does
Pydantic-factories is a mock data generator that inspects pydantic model definitions, dataclasses, and TypedDicts to automatically create realistic test instances. It uses type hints and field constraints as a blueprint, delegating to faker for realistic string and date generation. You define a factory class pointing to your model, call `.build()`, and receive a fully populated instance ready for testing—no manual field assignment needed.
The library integrates faker and pydantic to handle both built-in Python types and pydantic-specific types, respecting field constraints. It's designed for unit testing and test-driven development workflows where you need representative mock objects quickly. The project is no longer maintained; the authors have moved development to polyfactory.
Use it for:
- Generate realistic test fixtures for pydantic models in unit tests without manually populating every field.
- Create mock data for dataclass-based APIs during development and testing phases.
- Populate TypedDict instances with valid random data for integration test scenarios.
- Quickly prototype test suites for pydantic-based applications during TDD workflows.
- Generate bulk test data for validation and constraint-testing of model fields.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Generates mock data objects that conform to pydantic models, dataclasses, and TypedDicts by parsing type annotations and field constraints.
No. The project is archived and abandoned as of April 2023, with maintainers explicitly directing users to migrate to polyfactory. While the code may still work with current pydantic versions, there will be no fixes for compatibility issues with future releases. Start with polyfactory instead unless you are maintaining legacy code already using this package.
Install
pydantic-factories on PyPI
pip
pip install pydantic-factoriesuv
uv add pydantic-factoriespoetry
poetry add pydantic-factoriesInstalling pydantic-factories
Before you install
Low friction install with three straightforward runtime dependencies. However, the repository is archived and the project is abandoned; the maintainers have explicitly migrated to polyfactory as the successor. No updates since April 2023.
License in practice
MIT license permits commercial and private use with minimal restrictions, making it safe to adopt from a licensing standpoint.
Quickstart
pip install pydantic-factories
from pydantic import BaseModel
from pydantic_factories import ModelFactory
class Person(BaseModel):
name: str
age: int
class PersonFactory(ModelFactory):
__model__ = Person
result = PersonFactory.build()
Verify before relying
- Whether existing code using pydantic-factories will continue to work with future pydantic versions without maintenance.
- Compatibility with pydantic v2 and later versions, given the project's abandoned status.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.8,<4.0) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — faker, pydantic, typing-extensions |
| Maintenance | abandoned — 1,229 days since the last release |
| Last repo commit | (repository archived) |
| First released | |
| Downloads | 166,645/month — #10,485 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pydantic_factories-1.17.3-py3-none-any.whl
Keywords: dataclasses, factory, faker, mock, pydantic, pytest, starlite, tdd, testing
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
polyfactoryPolyfactory generates mock data objects from…
permissive · top 5,000 on PyPI
pydantic-collectionsProvides a `BaseCollectionModel` class that…
permissive · top 15,000 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
mimesisMimesis generates realistic fake data across 47…
permissive · top 5,000 on PyPI
dydanticDynamically generates Pydantic models from JSON…
permissive · top 5,000 on PyPI
pydantic-to-typescript2Converts Pydantic models to TypeScript…
permissive · top 15,000 on PyPI
pydantic-to-typescriptConverts pydantic model definitions into…
permissive · top 5,000 on PyPI
graphene-pydanticConverts Pydantic models into GraphQL object…
permissive · top 15,000 on PyPI
datamodel-code-generatorGenerates Python data models (Pydantic,…
permissive · top 5,000 on PyPI
pydantic_yamlPydantic-YAML adds YAML serialization and…
permissive · top 5,000 on PyPI