skillfed

pydantic-factories

Mock data generation for pydantic based models and python dataclasses

pydantic-factories v1.17.3 166.6K downloads/30d#10,485 on PyPI16
Permissive license MIT Abandoned released

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-factories

uv

uv add pydantic-factories

poetry

poetry add pydantic-factories

Installing 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

Environment :: Web EnvironmentFramework :: PytestIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software DevelopmentTopic :: Software Development :: LibrariesTopic :: Software Development :: TestingTopic :: Software Development :: Testing :: UnitTopic :: UtilitiesTyping :: Typed

Tags

pydantic mock data generationfactory for pydantic modelstest data fixtures pydanticdataclass mock factorygenerate fake pydantic instancestesting data builderspydantic model mocking
test-fixturesabandoned-project

More Software Development packages