Mock data generation for pydantic based models
Project description
Pydantic-Factories
This library offers powerful mock data generation capabilities for pydantic
based models and dataclasses
. 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.10.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42e8342d5b56fa7b38136d9e25f14bedd05b8484f274a86b4532f3174b5dc3fd |
|
MD5 | adeedf170a794a7cd5fb58fc4bc8dabc |
|
BLAKE2b-256 | ebaddd63fe8fe54d8d041397bc10120d16a8dedb9426f3ce6be17a71be867cc6 |
Hashes for pydantic_factories-1.10.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a59c7ed67e8f9b11de8b427b447295dac21cc6fea97fc6db58a5456c2c024446 |
|
MD5 | bf8a78a3156df227d721a7cb0be45e6d |
|
BLAKE2b-256 | e909dff748f23839fe78ed200523be70cb06900c3c15188c9a19ccedea9a2b2e |