https://github.com/litestar-org/polyfactory
Simple and powerful factories for mock data generation
https://github.com/litestar-org/polyfactory
beanie dataclasses hacktoberfest litestar msgspec odmantic polyfactory pydantic pydantic-factories python starlite typeddict
Last synced: 6 months ago
JSON representation
Simple and powerful factories for mock data generation
- Host: GitHub
- URL: https://github.com/litestar-org/polyfactory
- Owner: litestar-org
- License: mit
- Created: 2021-11-13T16:39:26.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-05-05T10:40:03.000Z (6 months ago)
- Last Synced: 2025-05-05T11:44:46.085Z (6 months ago)
- Topics: beanie, dataclasses, hacktoberfest, litestar, msgspec, odmantic, polyfactory, pydantic, pydantic-factories, python, starlite, typeddict
- Language: Python
- Homepage: https://polyfactory.litestar.dev/
- Size: 9.37 MB
- Stars: 1,195
- Watchers: 10
- Forks: 96
- Open Issues: 44
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.rst
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
- awesome-python-testing - polyfactory - A simple and powerful mock data generation library, based around type hints and supporting dataclasses, typed-dicts, pydantic models, msgspec structs and more. (Object Factories)
README
| Project | | Status |
| --------- | :-- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| CI/CD | | [](https://github.com/litestar-org/polyfactory/actions/workflows/publish.yml) [](https://github.com/litestar-org/polyfactory/actions/workflows/ci.yml) [](https://github.com/litestar-org/polyfactory/actions/workflows/pages/pages-build-deployment) |
| Quality | | [](https://codecov.io/github/litestar-org/polyfactory) |
| Package | | [](https://badge.fury.io/py/polyfactory)    |
| Community | | [](https://reddit.com/r/litestarapi) [](https://discord.gg/X3FJqy8d2j) [](https://matrix.to/#/#litestar:matrix.org) [](https://blog.litestar.dev) [](https://twitter.com/LitestarAPI) [](https://blog.litestar.dev) |
| Meta | | [](https://github.com/litestar-org/polyfactory) [](https://github.com/python/mypy) [](https://spdx.org/licenses/) [](https://github.com/sponsors/litestar-org) [](https://pydantic.dev) [](https://github.com/astral-sh/ruff) [](https://github.com/astral-sh/ruff) [](https://sourcery.ai) [](#contributors-) |
# Polyfactory
Polyfactory is a simple and powerful mock data generation library, based around type
hints and supporting dataclasses, typed-dicts, pydantic models, msgspec structs and more.
Polyfactory part of the Litestar project and as such actively maintained by a community of maintainers and contributors.
## Example
```python
from dataclasses import dataclass
from polyfactory.factories import DataclassFactory
@dataclass
class Person:
name: str
age: float
height: float
weight: float
class PersonFactory(DataclassFactory[Person]):
...
def test_is_person() -> None:
person_instance = PersonFactory.build()
assert isinstance(person_instance, Person)
```
That's it - with almost no work, we are able to create a mock data object fitting the `Person` class model definition.
This is possible because of the typing information available on the dataclass, which are used as a
source of truth for data generation.
The factory parses the information stored in the dataclass and generates a dictionary of kwargs that are passed to
`Person`.
## Documentation
Usage and API reference documentation is available on https://polyfactory.litestar.dev/.
## Installation
```shell
pip install polyfactory
```
## Relation to Pydantic-Factories
Prior to version 2, this library was known as [pydantic-factories](https://pypi.org/project/pydantic-factories/), a name
under which it gained quite a bit of popularity.
A main motivator for the 2.0 release was that we wanted to support more than just Pydantic models, something which also
required a change to its core architecture. As this library would no longer be directly tied to Pydantic, `polyfactory`
was chosen as its new name to reflect its capabilities; It can generate mock data for dataclasses, typed-dicts,
Pydantic, odmantic, and beanie ODM models, as well as custom factories.
## Contributing
This library is a community driven open source project. We welcome and encourage contributions. Please check out the
GitHub issues, read the contribution guide (at the repository's root), and you're always welcome
to [join our discord server](https://discord.gg/F4jPQzHpBU).
## Contributors โจ
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

Na'aman Hirschfeld
๐ง ๐ โ ๏ธ ๐ป ๐

Jacob Coffee
๐ง ๐ โ ๏ธ

Janek Nouvertnรฉ
๐ง ๐ โ ๏ธ ๐ป

Peter Schutt
๐ง โ ๏ธ ๐ป ๐

Marek Czaplicki
๐ป โ ๏ธ

Piotr Przybyลo
๐ป

sygutss
๐ ๐ป

chrisbeardy
๐

guacs
๐ป ๐ ๐ โ ๏ธ ๐ง

Vadim
๐ป

Simske
๐ป

Sondre Lillebรธ Gundersen
๐ป

Mateusz Ciszczoล
๐ป

Pedro Bernardes
๐ป

Martin Roy
๐ป

Matthew Aylward
๐ป

Elton H.Y. Chou
๐ป

Thang
๐ป

Daan
๐ป

Lyz
๐ป

Thorin Schiffer
๐ป

Iipin
๐ป

avihai-yosef
๐ป

anthonyh209
๐ป

Roman Reznikov
๐ป

gigelu
๐ป

Rodrigo Medina
๐ป

Gerrit Egnew
๐ป

danielkatzan
๐

Abdulhaq Emhemmed
๐ป

klimantje
๐ป

Tom Crasset
๐ป

cฤtฤlin
๐ป

Andrew Truong
๐ป ๐

Anthony
๐ป ๐ โ ๏ธ

Jonathan Liuti
๐ป ๐ โ ๏ธ

Julio Olivera
๐ป โ ๏ธ

Benoรฎt Godard
๐ป ๐ โ ๏ธ

Henry Sorsky
๐

Kim Minki
๐

Tim Joseph Dumol
๐

jeffry
๐ป

Sergey Kovalev
๐ป

Isaac Jackson
๐ป

Nikita Semenov
๐ป ๐

Michael Bianco
๐ป ๐
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification.
Contributions of any kind welcome!