Skip to main content

Dataclass Bakery offers you a smart way to create objects based on dataclasses for testing in Python

Project description

Dataclass Bakery offers you a smart way to create objects based on dataclasses for testing in Python. Inspired in model bakery module for Django.

Install

pip install dataclass_bakery

Usage and Info

Basic usage

from dataclasses import dataclass

from dataclass_bakery import baker


@dataclass
class Customer:
    id: int
    name: str
    spent_money: float


baker.make(Customer)
baker.make(Customer, _quantity=3)

"""
Customer(id=25, name='vzWoIfgoZM', spent_money=16.36)

[Customer(id=27, name='OYvyWakmUX', spent_money=84.98), Customer(id=41, name='AiancdsmLg', spent_money=57.57), Customer(id=92, name='feTxLyuSus', spent_money=26.06)]
"""

For more information: https://dataclass-bakery.readthedocs.io/

Types available:

  • int

  • str

  • float

  • bool

  • complex

  • date

  • datetime

  • range

  • list

  • tuple

  • dict

  • set

  • List (from typing import List)

  • Tuple (from typing import Tuple)

  • Dict (from typing import Dict)

  • Union (from typing import Union)

  • Optional (from typing import Optional)

  • Path (from pathlib import Path)

  • Decimal (from decimal import Decimal)

  • UUID (from uuid import UUID)

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

dataclass-bakery-0.0.8.tar.gz (15.4 kB view hashes)

Uploaded Source

Built Distribution

dataclass_bakery-0.0.8-py3-none-any.whl (30.2 kB view hashes)

Uploaded Python 3

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