Git Product home page Git Product logo

polyfactory's Introduction

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

Project Status
CI/CD Publish package ci pages-build-deployment
Quality Coverage Quality Gate Status Maintainability Rating Reliability Rating Security Rating
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 Sourcery 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 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
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

💻

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

polyfactory's People

Contributors

goldziher avatar allcontributors[bot] avatar guacs avatar jacobcoffee avatar provinzkraut avatar adhtruong avatar dependabot[bot] avatar jtraub avatar gsakkis avatar sondrelg avatar mciszczon avatar daanrademaker avatar phbernardes avatar mdczaplicki avatar lindycoder avatar butch78 avatar peterschutt avatar wangxin688 avatar sam-or avatar lyz-code avatar thorin-schiffer avatar nguyent avatar sobolevn avatar wer153 avatar vegemash avatar eltonchou avatar reznikovroman avatar reskov avatar simske avatar timdumol avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.