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.14.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fe375055e9774e9be2466a83417b1fb20056f473d337b551a3c2003cb1576f7 |
|
MD5 | 601e6b112340904feef89c5d0abe3afa |
|
BLAKE2b-256 | d6f035672a06f17fab81231cfbb58ca98c6f6878688fe3629e3d741068ea3acf |
Hashes for pydantic_factories-1.14.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca6a054128c8688f0dd27248e35e8665b294a7e589c48f0f0ccf8891266bf322 |
|
MD5 | 369c724b36e310d66e407070200361eb |
|
BLAKE2b-256 | 417e34ee043dfbfb23bf17fd33d85beb57c484531922c79466b59f8ec161f0dc |