Skip to main content

Mock data generation for pydantic based models

Project description

PyPI - Python Version Coverage Maintainability Rating Reliability Rating Quality Gate Status

Pydantic Factories

This library offers mock data generation for pydantic based models. This means any user defined models as well as third party libraries that use pydantic as a foundation, e.g. SQLModel, FastAPI, Beanie, Ormar and others.

Features

  • ✅ supports both built-in and pydantic types
  • ✅ supports pydantic field constraints
  • ✅ supports complex field typings
  • ✅ supports custom model fields

Why This Library?

  • 💯 powerful mock data generation
  • 💯 simple to use and extend
  • 💯 rigorously tested

Installation

pip install pydantic-factories

OR

poetry add --dev pydantic-factories

Usage

from datetime import date, datetime
from typing import List, Union

from pydantic import BaseModel, UUID4

from pydantic_factories.factory import ModelFactory


class Person(BaseModel):
    id: UUID4
    name: str
    hobbies: List[str]
    age: Union[float, int]
    birthday: Union[datetime, date]


class PersonFactoryWithDefaults(ModelFactory):
    __model__ = Person


result = PersonFactoryWithDefaults.build()

That's it - the factory will create a data object that fits the defined model and pass it to the pydantic model as kwargs. It will then pass through the pydantic validation and parsing mechanism, and create a model instance.

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-0.3.1b0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

pydantic_factories-0.3.1b0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file pydantic-factories-0.3.1b0.tar.gz.

File metadata

  • Download URL: pydantic-factories-0.3.1b0.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.9.8 Linux/5.11.0-1021-azure

File hashes

Hashes for pydantic-factories-0.3.1b0.tar.gz
Algorithm Hash digest
SHA256 ab95f879b9cd21c2e97d455257dacf0e86c2fc4dc2a7fdc786aac96df4c21def
MD5 f61a70e4cf0ce603df94ced1671e33db
BLAKE2b-256 a75754a6badab89c4cbcc650d12e1582c9c3ca16eff185244cb8515b3203e9e2

See more details on using hashes here.

File details

Details for the file pydantic_factories-0.3.1b0-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_factories-0.3.1b0-py3-none-any.whl
Algorithm Hash digest
SHA256 b3b238db2a8c588ca0ab6e87affea65f4d9bb6a1084038c5d96e50fe2aa8e887
MD5 372e206b689f752a9dc021540905b0ab
BLAKE2b-256 bb84d8fd0d80d53cb63209338e01af432427028630150aac53bce77d9c2ca373

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