Mock data generation for pydantic based models
Project description
Pydantic Factories
This library offers mock data generation for pydantic based models. This means any user defined models as well as third party libraries that use pydantic as a foundation, e.g. SQLModel, FastAPI, Beanie, Ormar and others.
Features
- ✅ supports both built-in and pydantic types
- ✅ supports pydantic field constraints
- ✅ supports complex field typings
- ✅ supports custom model fields
Why This Library?
- 💯 powerful mock data generation
- 💯 simple to use and extend
- 💯 rigorously tested
Installation
pip install pydantic-factories
OR
poetry add --dev pydantic-factories
Usage
from datetime import date, datetime
from typing import List, Union
from pydantic import BaseModel, UUID4
from pydantic_factories.factory import ModelFactory
class Person(BaseModel):
id: UUID4
name: str
hobbies: List[str]
age: Union[float, int]
birthday: Union[datetime, date]
class PersonFactoryWithDefaults(ModelFactory):
__model__ = Person
result = PersonFactoryWithDefaults.build()
That's it - the factory will create a data object that fits the defined model and pass it to the pydantic model as kwargs. It will then pass through the pydantic validation and parsing mechanism, and create a model instance.
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-0.3.2b0.tar.gz
.
File metadata
- Download URL: pydantic-factories-0.3.2b0.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.9.8 Linux/5.11.0-1021-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06ff0b6163b1049d2ff90659f77b344aa19ed4cce72d2ed7bdb74e567510d8d9 |
|
MD5 | 6a00ca61729697cad84cc503ec6df24e |
|
BLAKE2b-256 | 377ec9b9a5e464eac825154db19b6c5a1ba7cc5d739bc521be24050458b46474 |
File details
Details for the file pydantic_factories-0.3.2b0-py3-none-any.whl
.
File metadata
- Download URL: pydantic_factories-0.3.2b0-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.9.8 Linux/5.11.0-1021-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8aaedbd25b967d51434d1ea1be0bd54d4b32e8f4fa7f79dab41004e8209e0f48 |
|
MD5 | e2c40acd6c461a541edb7817e01c0df6 |
|
BLAKE2b-256 | a80ed551a11f8cef4cbc24fe7c93e8daea1e33302831394d7b7e96f816760cf5 |