• Stars
    star
    1,032
  • Rank 44,644 (Top 0.9 %)
  • Language
    Python
  • License
    MIT License
  • Created about 3 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple and powerful factories for mock data generation

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 - Black 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]):
    __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 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

๐Ÿ’ป

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

More Repositories

1

litestar

Production-ready, Light, Flexible and Extensible ASGI API framework | Effortlessly Build Performant APIs
Python
5,383
star
2

litestar-fullstack

Litestar Fullstack Reference Application with React, Vite, SQLAlchemy, Docker, Task Queues, and more!
Python
308
star
3

advanced-alchemy

A carefully crafted, thoroughly tested, optimized companion library for SQLAlchemy
Python
222
star
4

litestar-pg-redis-docker

Example Litestar project using Postgresql, Redis and Docker
Python
147
star
5

awesome-litestar

A curated list of resources related to Litestar.
Makefile
67
star
6

api-performance-tests

Benchmarking Litestar vs other ASGI API framework
Python
35
star
7

fast-query-parsers

Ultra-fast query string and url-encoded form-data parsers
Rust
30
star
8

pytest-databases

Reusable database fixtures for any and all databases.
Python
18
star
9

litestar-hello-world-stale

The minimum Litestar application
Python
17
star
10

litestar-vite

Vite Plugin for Litestar
Python
16
star
11

pydantic-factories

Simple and powerful mock data generation using pydantic or dataclasses
Python
13
star
12

starlite-jwt

JWT Auth toolkit for Starlite
Python
12
star
13

pydantic-openapi-schema

Generate OpenAPI 3.x.x using Pydantic
Python
11
star
14

type-lens

Runtime type introspection utilities
Python
11
star
15

litestar-hello-world

A minimal implementation of a Litestar application
Makefile
11
star
16

dtos

Domain modelling at the edge.
Python
10
star
17

project-template

Template repository for packages belonging to the Litestar Organization
Python
9
star
18

starlite-multipart

Toolkit for working with multipart/formdata
Python
8
star
19

vite-plugin

Litestar Adapter for Vite
TypeScript
8
star
20

litestar-asyncpg

Database connection management plugin for Litestar and asyncpg
Python
7
star
21

starlite-sessions

Simple sessions authentication for Starlite
Python
6
star
22

starlite-oidc

OpenID Connect (OIDC) authentication toolkit for Starlite
Python
5
star
23

litestar-oracledb

An Oracle Database plugin for Litestar
Python
5
star
24

starlite-cli

CLI for Starlite
Python
3
star
25

litestar-fullstack-inertia

A fully-functional reference application using Litestar, Inertia JS, and Advanced Alchemy
Python
3
star
26

litestar-piccolo

Litestar plugin for the Piccolo ORM
Python
3
star
27

litestar-oidc

WIP - OIDC Implementation for Litestar applications
Python
2
star
28

litestar.dev

Source code for litestar.dev
HTML
2
star
29

starlite-websockets-hello-world

MInimal example of websockets with Starlite
Python
1
star
30

branding

Branding for the @litestar-org organization and project
CSS
1
star