Mock data generation factories
Project description
Polyfactory
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for polyfactory-2.0.0a1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19312b27d78e63a4b16bfc39eecfa0e11783acfe106d3772c93738fcc1331002 |
|
MD5 | cae659e7d0f9f07437e902f8567e2a67 |
|
BLAKE2b-256 | b3e96967356c190ca77007ae053dc607c071e659fc68cf2647efb3d301778863 |