Mock data generation for pydantic based models and python dataclasses
Project description
Pydantic-Factories
This library offers powerful mock data generation capabilities for pydantic
based models, dataclasses
and TypeDict
s. It can also be used with other libraries that use pydantic as a foundation.
Check out the documentation 📚.
Installation
pip install pydantic-factories
Example
from datetime import date, datetime
from typing import List, Union
from pydantic import BaseModel, UUID4
from pydantic_factories import ModelFactory
class Person(BaseModel):
id: UUID4
name: str
hobbies: List[str]
age: Union[float, int]
birthday: Union[datetime, date]
class PersonFactory(ModelFactory):
__model__ = Person
result = PersonFactory.build()
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 pydantic model and model-fields, which are used as a source of truth for data generation.
The factory parses the information stored in the pydantic model and generates a dictionary of kwargs that are passed to
the Person
class' init method.
Features
- ✅ supports both built-in and pydantic types
- ✅ supports pydantic field constraints
- ✅ supports complex field types
- ✅ supports custom model fields
- ✅ supports dataclasses
Why This Library?
- 💯 powerful
- 💯 extensible
- 💯 simple
- 💯 rigorously tested
Contributing
This library is open to contributions - in fact we welcome it. Please see the contribution guide!
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 pydantic_factories-1.17.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85848136cd768894dc5b6e3ffaf49753c7627c545ef05ff096ff616071cd59ff |
|
MD5 | 2434d907a05599238cc76e80f58c99e9 |
|
BLAKE2b-256 | d5b7d894c8ce5501d0381f71237df543abb2a2421d97fa836fb11bcad07768fd |
Hashes for pydantic_factories-1.17.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05c0b143540f54d9dd9d0d500b7b146ff29e0c1cd4bb5f2ed99c60842ff1d5e6 |
|
MD5 | 06445947fd65c06231a53f985b9bef90 |
|
BLAKE2b-256 | b4138ceec8cf0e44e3d00c5dad6d0ecbf51f1f2ce31e5197b75a7f4d82c90d78 |