• Stars
    star
    1,032
  • Rank 44,644 (Top 0.9 %)
  • Language
    Python
  • License
    MIT License
  • Created about 3 years ago
  • Updated 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