This project has been archived by its maintainers, and is no longer receiving any updates.
⚠️
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!
Metadata
Release files for pydantic-factories 1.17.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pydantic_factories-1.17.3.tar.gz | 25.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydantic_factories-1.17.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 57.6 kB
Release files / pydantic_factories-1.17.3.tar.gz
| Download URL | pydantic_factories-1.17.3.tar.gz |
|---|---|
| Size | 25.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
de36e0db7108af5f4328308da9a4049311c4d5e0814553d2f39078b08b05e48d
|
|
BLAKE2b-256 checksum How to use checksums |
31c173e688b29bee1d68604b45e8ce3ee410b4bd09ded23546e18263c1855c74
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.0 CPython/3.11.2 Darwin/22.3.0
|
Release files / pydantic_factories-1.17.3-py3-none-any.whl
| Download URL | pydantic_factories-1.17.3-py3-none-any.whl |
|---|---|
| Size | 31.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5a1522a31d27e1af414719c510a4a934365292f3ea6fdc843ed65d0564242636
|
|
BLAKE2b-256 checksum How to use checksums |
404981bbfccaf7174e7a94be1fa95d9ed46da6663372b2a7cd597c1c6fdfcabe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.0 CPython/3.11.2 Darwin/22.3.0
|
Security for pydantic-factories 1.17.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.