Skip to main content

Mock data generation factories

Project description

Polyfactory Logo - Light

Project Status
CI/CD Publish package ci pages-build-deployment
Quality codecov
Package PyPI - Version PyPI - Support Python Versions Pydantic Factories PyPI - Downloads Polyfactory PyPI - Downloads
Community Reddit Discord Matrix Medium Twitter Blog
Meta Litestar Project types - Mypy License - MIT Litestar Sponsors linting - Ruff code style - Ruff Sourcery All 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

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 checkout 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
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

📖

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polyfactory-3.2.0.tar.gz (346.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polyfactory-3.2.0-py3-none-any.whl (62.2 kB view details)

Uploaded Python 3

File details

Details for the file polyfactory-3.2.0.tar.gz.

File metadata

  • Download URL: polyfactory-3.2.0.tar.gz
  • Upload date:
  • Size: 346.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for polyfactory-3.2.0.tar.gz
Algorithm Hash digest
SHA256 879242f55208f023eee1de48522de5cb1f9fd2d09b2314e999a9592829d596d1
MD5 b1e514a1b2149cb5d6556324967ead6f
BLAKE2b-256 9792e90639b1d2abe982749eba7e734571a343ea062f7d486498b1c2b852f019

See more details on using hashes here.

Provenance

The following attestation bundles were made for polyfactory-3.2.0.tar.gz:

Publisher: publish.yml on litestar-org/polyfactory

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file polyfactory-3.2.0-py3-none-any.whl.

File metadata

  • Download URL: polyfactory-3.2.0-py3-none-any.whl
  • Upload date:
  • Size: 62.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for polyfactory-3.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5945799cce4c56cd44ccad96fb0352996914553cc3efaa5a286930599f569571
MD5 bfe2641c01ad7ec68bac2c4f3ae45d69
BLAKE2b-256 d92193363d7b802aa904f8d4169bc33e0e316d06d26ee68d40fe0355057da98c

See more details on using hashes here.

Provenance

The following attestation bundles were made for polyfactory-3.2.0-py3-none-any.whl:

Publisher: publish.yml on litestar-org/polyfactory

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page