Skip to main content

Mock data generation for pydantic based models

Project description

PyPI - Python Version

Language grade: Python Total alerts Coverage Maintainability Rating Reliability Rating Quality Gate Status

Discord

Pydantic-Factories

This library offers powerful mock data generation capabilities for pydantic based models and dataclasses. 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

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.6.2.tar.gz (19.0 kB view details)

Uploaded Source

Built Distribution

pydantic_factories-1.6.2-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file pydantic-factories-1.6.2.tar.gz.

File metadata

  • Download URL: pydantic-factories-1.6.2.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.9.13 Linux/5.15.0-1019-azure

File hashes

Hashes for pydantic-factories-1.6.2.tar.gz
Algorithm Hash digest
SHA256 f63f8b94928ca65f71871400e3a46b5fd0f64667cfeb9a7dca0e8706079fde52
MD5 96cbf0eecc3e6c2a0450bccdc88c6408
BLAKE2b-256 b24565b6439912d9920f608f2c3d36e7fa156e51f6db9fb45ccf2f4d5d441e4d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pydantic_factories-1.6.2-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.9.13 Linux/5.15.0-1019-azure

File hashes

Hashes for pydantic_factories-1.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c7d5ef83eadb0f1a02090b2b381599b71d6830296a9d631f31bf95d0cbfc00d7
MD5 3f2066396cfb3191bdb4543c922802a6
BLAKE2b-256 eef95315fe127b087d70810f14cfa86746077004d85be080be98067f256ed8a8

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