Mock data generation for pydantic based models and python dataclasses
Project Links
Meta
Author: Na'aman Hirschfeld
Maintainer: Na'aman Hirschfeld
Requires Python: >=3.8,<4.0
Classifiers
Environment
- Web Environment
Framework
- Pytest
Intended Audience
- Developers
License
- OSI Approved :: MIT License
Natural Language
- English
Operating System
- OS Independent
Programming Language
- Python
- Python :: 3
- Python :: 3.8
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.10
- Python :: 3.11
- Python :: 3.8
- Python :: 3.9
Topic
- Software Development
- Software Development :: Libraries
- Software Development :: Testing
- Software Development :: Testing :: Unit
- Utilities
Typing
- Typed
⚠️
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 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
- ✅ supports TypedDicts
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!
1.17.3
Apr 03, 2023
1.17.2
Feb 09, 2023
1.17.1
Jan 15, 2023
1.17.0
Dec 04, 2022
1.16.0
Nov 24, 2022
1.15.0
Nov 07, 2022
1.14.0
Nov 04, 2022
1.13.0
Oct 26, 2022
1.12.0
Oct 17, 2022
1.11.1
Oct 16, 2022
1.11.0
Oct 16, 2022
1.10.0
Oct 13, 2022
1.9.0
Oct 09, 2022
1.8.2
Oct 08, 2022
1.8.1
Oct 07, 2022
1.8.0
Oct 07, 2022
1.7.1
Oct 01, 2022
1.7.0
Sep 28, 2022
1.6.2
Sep 15, 2022
1.6.1
Aug 30, 2022
1.6.0
Aug 27, 2022
1.5.4
Aug 12, 2022
1.5.2
Aug 11, 2022
1.5.1
Aug 10, 2022
1.5.0
Aug 09, 2022
1.4.1
Jul 25, 2022
1.4.0
Jul 18, 2022
1.3.0
May 27, 2022
1.2.9
May 20, 2022
1.2.8
May 03, 2022
1.2.7
Mar 29, 2022
1.2.6
Mar 04, 2022
1.2.5
Feb 18, 2022
1.2.4
Feb 11, 2022
1.2.3
Jan 21, 2022
1.2.2
Jan 21, 2022
1.2.1
Jan 16, 2022
1.2.0
Jan 09, 2022
1.1.0
Jan 07, 2022
1.0.0
Jan 01, 2022
0.8.0
Dec 31, 2021
0.7.0
Dec 28, 2021
0.6.3
Dec 16, 2021
0.6.2
Dec 16, 2021
0.6.1
Dec 15, 2021
0.6.0
Dec 14, 2021
0.5.0
Nov 29, 2021
0.4.6
Nov 29, 2021
0.4.5
Nov 29, 2021
0.4.4
Nov 29, 2021
0.4.3
Nov 29, 2021
0.4.2
Nov 28, 2021
0.4.1
Nov 27, 2021
0.4.0
Nov 25, 2021
0.3.5b0
Nov 24, 2021
0.3.4b0
Nov 24, 2021
0.3.3b0
Nov 23, 2021
0.3.2b0
Nov 23, 2021
0.3.1b0
Nov 22, 2021
0.3.0b0
Nov 21, 2021
0.2.0a0
Nov 18, 2021
0.1.0a0
Nov 17, 2021