GithubHelp home page GithubHelp logo

sherbang / polyfactory Goto Github PK

View Code? Open in Web Editor NEW

This project forked from litestar-org/polyfactory

0.0 0.0 0.0 915 KB

Simple and powerful factories for mock data generation

Home Page: https://polyfactory.litestar.dev/

License: MIT License

Python 99.85% Makefile 0.15%

polyfactory's Introduction

Polyfactory

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

PyPI - License PyPI - Python Version

Coverage Maintainability Rating Reliability Rating Quality Gate Status Security Rating

Reddit Discord Matrix Medium

This library offers factories for mock data generation using python type hints. It part of the LiteStar-API project and is 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]):
    __model__ = 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 the Person class constructor.

Documentation

A full API reference and usage documentation is available in the dedicated documentation site.

Installation

pip install polyfactory

Relation to Pydantic-Factories

The earlier version of this library was released under the name pydantic-factories. While this library became very popular (above 100K monthly downloads), we decided to rename it because we changed the core architecture - polyfactory is a fitting name because we no longer rely on pydantic, which is now an optional dependency. This library is capable of generating mock data for dataclasses, typed-dicts and any custom factory using type annotations. It also supports using pydantic models - but that is optional.

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.

polyfactory's People

Contributors

anthonyh209 avatar avihai-yosef avatar butch78 avatar daanrademaker avatar danielkatzan avatar dependabot[bot] avatar eltonchou avatar gegnew avatar gigelu avatar goldziher avatar jacobcoffee avatar jtraub avatar lindycoder avatar lyz-code avatar mciszczon avatar nguyent avatar peterschutt avatar phbernardes avatar provinzkraut avatar reznikovroman avatar roeeyn avatar sherbang avatar sondrelg avatar thorin-schiffer 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.