polyfactory

2.18.1last stable release 2 months ago
Complexity Score
Medium
Open Issues
N/A
Dependent Projects
23
Weekly Downloadsglobal
971,807

License

  • MIT
    • Yesattribution
    • Permissivelinking
    • Permissivedistribution
    • Permissivemodification
    • Nopatent grant
    • Yesprivate use
    • Permissivesublicensing
    • Notrademark grant

Downloads

Readme

Project Status CI/CD Quality Package Community Meta

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

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

pip install polyfactory

Relation to Pydantic-Factories

Prior to version 2, this library was known as 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.

Contributors โœจ

Thanks goes to these wonderful people (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
๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!

Dependencies

CVE IssuesActive
0
Scorecards Score
No Data
Test Coverage
No Data
Follows Semver
No
Github Stars
1,059
Dependenciestotal
16
DependenciesOutdated
1
DependenciesDeprecated
0
Threat Modelling
No Data
Repo Audits
No Data

Learn how to distribute polyfactory in your own private PyPI registry

pip install polyfactory
Processing...
Done

39 Releases

PyPI on Cloudsmith

Getting started with PyPI on Cloudsmith is fast and easy.