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 5 hours 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 (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-25T14:15:21.000Z (4 months ago)
- Last Synced: 2024-10-30T08:17:03.615Z (4 months ago)
- Topics: beanie, dataclasses, hacktoberfest, litestar, msgspec, odmantic, polyfactory, pydantic, pydantic-factories, python, starlite, typeddict
- Language: Python
- Homepage: https://polyfactory.litestar.dev/
- Size: 7.26 MB
- Stars: 1,041
- Watchers: 14
- Forks: 81
- Open Issues: 34
-
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 | | [![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 dataclassfrom polyfactory.factories import DataclassFactory
@dataclass
class Person:
name: str
age: float
height: float
weight: floatclass 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
๐ป ๐
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification.
Contributions of any kind welcome!