Skip to main content

Mock data generation for pydantic based models and python dataclasses

Project description

Starlite Logo - Light Starlite Logo - Dark

PyPI - License PyPI - Python Version

Coverage Maintainability Rating Reliability Rating Quality Gate Status

Discord Matrix Reddit

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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantic_factories-1.17.2.tar.gz (26.1 kB view details)

Uploaded Source

Built Distribution

pydantic_factories-1.17.2-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_factories-1.17.2.tar.gz.

File metadata

  • Download URL: pydantic_factories-1.17.2.tar.gz
  • Upload date:
  • Size: 26.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.1 Linux/5.15.0-1031-azure

File hashes

Hashes for pydantic_factories-1.17.2.tar.gz
Algorithm Hash digest
SHA256 a1ea1d3a595235a65f954d6e182ec4bfe94645f2c4d986fd43ae19a62ffb90b0
MD5 c0c79fdf16ab444bc56b58daff9c185d
BLAKE2b-256 60979f1ae52b1eabb1e2e72fbc69ed48c7380a373b5ea8b7f02a20d932b84d97

See more details on using hashes here.

File details

Details for the file pydantic_factories-1.17.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_factories-1.17.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e1378700a9e963b368b602e46e8ccc3331027f10233e617eb47b3a3dd052ee25
MD5 fce38ef863c20681ad46ccd4fa17e4fc
BLAKE2b-256 c5450e76b74a13783032e77066f1f6b7f692020f8d44cc5399518ba3881bda32

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page