Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

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: about 1 month ago
JSON representation

Simple and powerful factories for mock data generation

Lists

README

        


Litestar - Polyfactory Logo - Light
Litestar - Polyfactory Logo - Dark

| Project | | Status |
| --------- | :-- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| CI/CD | | [![Publish package](https://github.com/litestar-org/polyfactory/actions/workflows/publish.yml/badge.svg)](https://github.com/litestar-org/polyfactory/actions/workflows/publish.yml) [![ci](https://github.com/litestar-org/polyfactory/actions/workflows/ci.yml/badge.svg)](https://github.com/litestar-org/polyfactory/actions/workflows/ci.yml) [![pages-build-deployment](https://github.com/litestar-org/polyfactory/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/litestar-org/polyfactory/actions/workflows/pages/pages-build-deployment) |
| Quality | | [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=litestar-org_polyfactory&metric=coverage)](https://sonarcloud.io/summary/new_code?id=litestar-org_polyfactory) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=litestar-org_polyfactory&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=litestar-org_polyfactory) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=litestar-org_polyfactory&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=litestar-org_polyfactory) [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=litestar-org_polyfactory&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=litestar-org_polyfactory) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=litestar-org_polyfactory&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=litestar-org_polyfactory) |
| Package | | [![PyPI - Version](https://img.shields.io/pypi/v/polyfactory?labelColor=202235&color=edb641&logo=python&logoColor=edb641)](https://badge.fury.io/py/polyfactory) ![PyPI - Support Python Versions](https://img.shields.io/pypi/pyversions/polyfactory?labelColor=202235&color=edb641&logo=python&logoColor=edb641) ![Pydantic Factories PyPI - Downloads](https://img.shields.io/pypi/dm/pydantic-factories?logo=python&label=Pydantic%20Factories%20downloads&labelColor=202235&color=edb641&logoColor=edb641) ![Polyfactory PyPI - Downloads](https://img.shields.io/pypi/dm/polyfactory?logo=python&label=Polyfactory%20downloads&labelColor=202235&color=edb641&logoColor=edb641) |
| Community | | [![Reddit](https://img.shields.io/reddit/subreddit-subscribers/litestarapi?label=r%2FLitestar&logo=reddit&labelColor=202235&color=edb641&logoColor=edb641)](https://reddit.com/r/litestarapi) [![Discord](https://img.shields.io/discord/919193495116337154?labelColor=202235&color=edb641&label=chat%20on%20discord&logo=discord&logoColor=edb641)](https://discord.gg/X3FJqy8d2j) [![Matrix](https://img.shields.io/badge/chat%20on%20Matrix-bridged-202235?labelColor=202235&color=edb641&logo=matrix&logoColor=edb641)](https://matrix.to/#/#litestar:matrix.org) [![Medium](https://img.shields.io/badge/Medium-202235?labelColor=202235&color=edb641&logo=medium&logoColor=edb641)](https://blog.litestar.dev) [![Twitter](https://img.shields.io/twitter/follow/LitestarAPI?labelColor=202235&color=edb641&logo=twitter&logoColor=edb641&style=flat)](https://twitter.com/LitestarAPI) [![Blog](https://img.shields.io/badge/Blog-litestar.dev-202235?logo=blogger&labelColor=202235&color=edb641&logoColor=edb641)](https://blog.litestar.dev) |
| Meta | | [![Litestar Project](https://img.shields.io/badge/Litestar%20Org-%E2%AD%90%20Polyfactory-202235.svg?logo=python&labelColor=202235&color=edb641&logoColor=edb641)](https://github.com/litestar-org/polyfactory) [![types - Mypy](https://img.shields.io/badge/types-Mypy-202235.svg?logo=python&labelColor=202235&color=edb641&logoColor=edb641)](https://github.com/python/mypy) [![License - MIT](https://img.shields.io/badge/license-MIT-202235.svg?logo=python&labelColor=202235&color=edb641&logoColor=edb641)](https://spdx.org/licenses/) [![Litestar Sponsors](https://img.shields.io/badge/Sponsor-%E2%9D%A4-%23edb641.svg?&logo=github&logoColor=edb641&labelColor=202235)](https://github.com/sponsors/litestar-org) [![Sourcery](https://img.shields.io/badge/Pydantic-v2-edb641?labelColor=202235&logoColor=edb641)](https://pydantic.dev) [![linting - Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json&labelColor=202235)](https://github.com/astral-sh/ruff) [![code style - Black](https://img.shields.io/badge/code%20style-black-000000.svg?logo=python&labelColor=202235&logoColor=edb641)](https://github.com/psf/black) [![Sourcery](https://img.shields.io/badge/Sourcery-enabled-edb641?labelColor=202235&logoColor=edb641)](https://sourcery.ai) [![All Contributors](https://img.shields.io/github/all-contributors/litestar-org/polyfactory?labelColor=202235&color=edb641&logoColor=edb641)](#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
Na'aman Hirschfeld

🚧 🚇 ⚠️ 💻 📖
Jacob Coffee
Jacob Coffee

🚧 📖 ⚠️
Janek Nouvertné
Janek Nouvertné

🚧 📖 ⚠️ 💻
Peter Schutt
Peter Schutt

🚧 ⚠️ 💻 📖
Marek Czaplicki
Marek Czaplicki

💻 ⚠️
Piotr Przybyło
Piotr Przybyło

💻
sygutss
sygutss

🐛 💻


chrisbeardy
chrisbeardy

📖
guacs
guacs

💻 🚇 📖 ⚠️ 🚧
Vadim
Vadim

💻
Simske
Simske

💻
Sondre Lillebø Gundersen
Sondre Lillebø Gundersen

💻
Mateusz Ciszczoń
Mateusz Ciszczoń

💻
Pedro Bernardes
Pedro Bernardes

💻


Martin Roy
Martin Roy

💻
Matthew Aylward
Matthew Aylward

💻
Elton H.Y. Chou
Elton H.Y. Chou

💻
Thang
Thang

💻
Daan
Daan

💻
Lyz
Lyz

💻
Thorin Schiffer
Thorin Schiffer

💻


Iipin
Iipin

💻
avihai-yosef
avihai-yosef

💻
anthonyh209
anthonyh209

💻
Roman Reznikov
Roman Reznikov

💻
gigelu
gigelu

💻
Rodrigo Medina
Rodrigo Medina

💻
Gerrit Egnew
Gerrit Egnew

💻


danielkatzan
danielkatzan

📖
Abdulhaq Emhemmed
Abdulhaq Emhemmed

💻
klimantje
klimantje

💻
Tom Crasset
Tom Crasset

💻
cătălin
cătălin

💻
Andrew Truong
Andrew Truong

💻 📖
Anthony
Anthony

💻 📖 ⚠️


Jonathan Liuti
Jonathan Liuti

💻 📖 ⚠️
Julio Olivera
Julio Olivera

💻 ⚠️
Benoît Godard
Benoît Godard

💻 📖 ⚠️
Henry Sorsky
Henry Sorsky

🚇
Kim Minki
Kim Minki

📖
Tim Joseph Dumol
Tim Joseph Dumol

📖
jeffry
jeffry

💻

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