Skip to main content

Async-enabled fork of model-bakery: smart object creation facility for Django, with baker.amake/aprepare.

Project description

Model Bakery: Smart fixtures for better tests

Build Coverage Latest PyPI version Documentation Status

Model Bakery offers you a smart way to create fixtures for testing in Django. With a simple and powerful API, you can create many objects with a single line of code.

About this fork

model-bakery-async is a fork of model-bakery that adds async-native fixture creation — baker.amake() / baker.aprepare() and their Baker counterparts — for use from async def tests on Django's async ORM.

It packages the work from upstream PR #599, which the upstream maintainers declined to merge citing the maintenance burden of a parallel async implementation (the code quality was not in question). We maintain it here so projects that need async fixtures can depend on a published package.

It is a drop-in replacement: the distribution is model-bakery-async but it imports as model_bakery, and all sync APIs from upstream are preserved. Because it shares the model_bakery import namespace, install either this package or upstream model-bakery — not both.

Installation

pip install model-bakery-async

Then import it exactly like upstream model-bakery:

from model_bakery import baker

Supported Versions

Model Bakery follows the Python and Django release and support cycles. We drop support for Python and Django versions when they reach end-of-life.

Basic usage

# models.py
from django.db import models

class Customer(models.Model):
    name = models.CharField(max_length=30)
    email = models.EmailField()
    age = models.IntegerField()
    is_jards_macale_fan = models.BooleanField()
    bio = models.TextField()
    birthday = models.DateField()
    last_shopping = models.DateTimeField()

# test_models.py
from django.test import TestCase
from model_bakery import baker

class TestCustomerModel(TestCase):
    def setUp(self):
        self.customer = baker.make('shop.Customer')
        print(self.customer.__dict__)

"""
{'_state': <django.db.models.base.ModelState object at 0x1129a3240>,
 'age': 3841,
 'bio': 'vUFzMUMyKzlnTyiCxfgODIhrnkjzgQwHtzIbtnVDKflqevczfnaOACkDNqvCHwvtWdLwoiKrCqfppAlogSLECtMmfleeveyqefkGyTGnpbkVQTtviQVDESpXascHAluGHYEotSypSiHvHzFteKIcUebrzUVigiOacfnGdvijEPrZdSCIIBjuXZMaWLrMXyrsUCdKPLRBRYklRdtZhgtxuASXdhNGhDsrnPHrYRClhrSJSVFojMkUHBvSZhoXoCrTfHsAjenCEHvcLeCecsXwXgWJcnJPSFdOmOpiHRnhSgRF',
 'birthday': datetime.date(2019, 12, 3),
 'email': 'rpNATNsxoj@example.com',
 'is_jards_macale_fan': True,
 'id': 1,
 'last_shopping': datetime.datetime(2019, 12, 3, 21, 42, 34, 77019),
 'name': 'qiayYnESvqcYLLBzxpFOcGBIfnQEPx'}
"""

Documentation

For more detailed information, check out the full documentation.

Contributing

As an open-source project, Model Bakery welcomes contributions of many forms:

  • Code patches
  • Documentation improvements
  • Bug reports

Take a look at our contribution guidelines for instructions on how to set up your local environment.

Maintainers

Creator

Sponsors

Sponsors

License

Model Bakery is licensed under Apache License 2.0. See the LICENSE file for more information.

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

model_bakery_async-1.23.6.tar.gz (31.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

model_bakery_async-1.23.6-py3-none-any.whl (33.4 kB view details)

Uploaded Python 3

File details

Details for the file model_bakery_async-1.23.6.tar.gz.

File metadata

  • Download URL: model_bakery_async-1.23.6.tar.gz
  • Upload date:
  • Size: 31.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for model_bakery_async-1.23.6.tar.gz
Algorithm Hash digest
SHA256 cdd36f93fce1be0682ec49cef2b3fa7f2d79fbaa129817a1463dbfccd8533f85
MD5 187fc0850fb81bdee20aa7c0e784d8db
BLAKE2b-256 08772cdb5efe773a5f1d3fd80fcf7eee7d3e3c8ee3ec1909420d6f6dc2d047fc

See more details on using hashes here.

File details

Details for the file model_bakery_async-1.23.6-py3-none-any.whl.

File metadata

  • Download URL: model_bakery_async-1.23.6-py3-none-any.whl
  • Upload date:
  • Size: 33.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for model_bakery_async-1.23.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e6bcc4410648c55eb0d16c12e3ed9794345010bb2d892a34eebb1b002a8594a6
MD5 380996d8f97e34515bb44806dd0446c0
BLAKE2b-256 2b36171f1ecd24bca93691d892f8af6ec99a90509365214c81a19cc1a22dfdea

See more details on using hashes here.

Supported by

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