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
File details
Details for the file pydantic-factories-1.6.1.tar.gz
.
File metadata
- Download URL: pydantic-factories-1.6.1.tar.gz
- Upload date:
- Size: 19.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.15 CPython/3.9.13 Linux/5.15.0-1017-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a753e7ca6d5fa5d9714ae53ae4e3210a7bfd2e80b75f4d2c68ca40c08726856a |
|
MD5 | a7969da3b31a4a4f1a66a1cce2b58052 |
|
BLAKE2b-256 | af4d1ea5aa6fb8840b338ae08ba6c2f740372a87d6b1cf852b75c104e90461de |
File details
Details for the file pydantic_factories-1.6.1-py3-none-any.whl
.
File metadata
- Download URL: pydantic_factories-1.6.1-py3-none-any.whl
- Upload date:
- Size: 24.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.15 CPython/3.9.13 Linux/5.15.0-1017-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8b55806a5f94d2c42ebd34e723831ac359002e5b567c89b16b9d45250f853d8 |
|
MD5 | 435bae002c03aed25cf280c6e2d188ee |
|
BLAKE2b-256 | d9dbf9c0a603da8dd74cb749c0a87e06c3a2f3c7d8072495e3e5fae317c1496e |