--- id: polyfactory version: "3.3.0" license: MIT license_treatment: permissive maintenance: active --- # polyfactory — Mock data generation factories License: permissive · Maintenance: active · Downloads: 11.3M/mo ## 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 above — verify before relying. Polyfactory generates mock data objects from type hints, supporting dataclasses, Pydantic models, typed-dicts, msgspec structs, and other typed structures for testing and development. 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 pip install polyfactory uv add polyfactory poetry add polyfactory ## Installing polyfactory 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_current - Install friction: low - Maintenance: active - Downloads: 11.3M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags mock data generation, test fixture factory, dataclass mock builder, pydantic model factory, type-hint based test data, fake data from types, testing data generator, testing, fixtures, mock-data [View on SkillFed](https://skillfed.io/packages/polyfactory) · [View on PyPI](https://pypi.org/project/polyfactory/)