Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

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 5 hours ago
JSON representation

Simple and powerful factories for mock data generation

Awesome Lists containing this project

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 - Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/format.json&labelColor=202235)](https://github.com/astral-sh/ruff) [![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

๐Ÿ’ป


Sergey Kovalev
Sergey Kovalev

๐Ÿ’ป
Isaac Jackson
Isaac Jackson

๐Ÿ’ป
Nikita Semenov
Nikita Semenov

๐Ÿ’ป ๐Ÿ“–

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