polyfactory
Mock data generation factories
Decision gist · record as of 2026-08-14
Yes. Polyfactory is actively maintained, has no known vulnerabilities, low install friction, and solves a real testing problem—eliminating manual fixture boilerplate. It's well-suited for any project using typed Python models that needs realistic mock data for tests.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Low friction install with only two runtime dependencies (faker and typing-extensions).
- Actively maintained as part of the Litestar project with recent activity and no known vulnerabilities.
License · maintenance · safety
MIT (permissive) — MIT license is permissive; you can use, modify, and distribute this package freely in both open-source and commercial projects with minimal restrictions.
last release 2026-02-22 (173 days) · last repo commit 2026-08-04 · 1,501 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 11,299,823 downloads/mo, #1,401 on PyPI
Alternatives
Verify before relying
pip install polyfactory
from dataclasses import dataclass
from polyfactory.factories import DataclassFactory
@dataclass
class Person:
name: str
age: float
class PersonFactory(DataclassFactory[Person]):
pass
person = PersonFactory.build()- Whether the library supports generating data for custom classes beyond the documented types (dataclasses, Pydantic, typed-dicts, msgspec, attrs, SQLAlchemy).
- Performance characteristics when generating large volumes of mock objects or deeply nested structures.
What it is and what it does
Polyfactory is a mock data generation library that reads type hints from your data models and automatically generates realistic test objects without manual configuration. It works with dataclasses, Pydantic models, typed-dicts, msgspec structs, and other typed structures, making it straightforward to create test fixtures that match your schema.
You define a factory class that inherits from the appropriate factory type for your model, and then call `.build()` to generate a populated instance. The library uses faker under the hood to produce realistic values (names, addresses, dates, etc.) that respect the types declared in your model. This eliminates boilerplate fixture code and keeps your test data generation in sync with your schema as it evolves.
Use it for
- Generate realistic test data for unit tests without writing fixture factories by hand for each model.
- Create mock Pydantic or dataclass instances for integration tests with pre-populated fields matching your schema.
- Populate test databases with diverse, type-correct sample data for testing queries and business logic.
- Build mock API responses during development when the real service is unavailable or not yet implemented.
- Generate synthetic data for performance testing or load testing with properly typed, realistic values.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
Polyfactory is actively maintained, has no known vulnerabilities, low install friction, and solves a real testing problem—eliminating manual fixture boilerplate. It's well-suited for any project using typed Python models that needs realistic mock data for tests.
Install
polyfactory on PyPI
Before you install
Low friction install with only two runtime dependencies (faker and typing-extensions). Actively maintained as part of the Litestar project with recent activity and no known vulnerabilities.
License in practice
MIT license is permissive; you can use, modify, and distribute this package freely in both open-source and commercial projects with minimal restrictions.
Quickstart
pip install polyfactory
from dataclasses import dataclass
from polyfactory.factories import DataclassFactory
@dataclass
class Person:
name: str
age: float
class PersonFactory(DataclassFactory[Person]):
pass
person = PersonFactory.build()
Verify before relying
- Whether the library supports generating data for custom classes beyond the documented types (dataclasses, Pydantic, typed-dicts, msgspec, attrs, SQLAlchemy).
- Performance characteristics when generating large volumes of mock objects or deeply nested structures.
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release <4.0,>=3.9 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 2 packagesfakertyping-extensions |
| Maintenance | Actively maintained 173 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 11,299,823 / month, #1,401 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentFramework :: PytestIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9Topic :: Software DevelopmentTopic :: Software Development :: LibrariesTopic :: Software Development :: TestingTopic :: Software Development :: Testing :: UnitTopic :: UtilitiesTyping :: Typed |
Evidence: polyfactory-3.3.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “mock data generation”
- polyfactoryPolyfactory generates mock data objects from type hints, supporting…
- pydantic-factoriesGenerates mock data objects that conform to pydantic models,…
- mimesisMimesis generates realistic fake data across 47 locales—names,…
Give your agent the search over MCP, or paste the wish link into any chat.
More Software Development packages
Provides backported and experimental type hints for Python 3.9+, allowing use of newer typing features on older Python versions and enabling early experimentation with type system PEPs before they enter the standard library.
NumPy provides an N-dimensional array object and a comprehensive suite of mathematical, linear algebra, Fourier transform, and random number functions for scientific computing in Python.
FastAPI is a Python web framework for building REST APIs using type hints, with automatic request validation, serialization, and interactive API documentation.
Provides a way to document function parameters, class attributes, return types, and variables inline using Python's `Annotated` type hint syntax instead of traditional docstrings.
Typer builds command-line applications from Python functions using type hints, automatically generating help text, argument parsing, and shell completion.
Install it if you are building CLIs in Python.
Distlib provides low-level packaging utilities for building, distributing, and managing Python software—including metadata handling, version specifiers, wheel support, script installation, and dependency resolution.
See also pydantic-factories · datamodel-code-generator · django-clone · coqpit · dataclass-factory · dataclasses-jsonschema · dydantic · jsonschema-pydantic · desert · wagtail-factories