Mock data generation for pydantic based models and python dataclasses
Archived. The repository is read-only: no more fixes or releases will come.
Consider insteadpolyfactoryPythie’s Index: 7413.1M downloads/moCompare →
pip install pydantic-factories
⚠️
The next version of this library is released as polyfactory. Users are encouraged to migrate to it.
⚠️
Pydantic-Factories
This library offers powerful mock data generation capabilities for pydantic
based models, dataclasses and TypeDicts. 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 class model definition.