Mixer is a Python library designed as a fixtures replacement, simplifying the creation of test data. It supports various ORMs like Django ORM, SQLAlchemy ORM, MongoEngine ODM, and plain Python objects. The current version is 7.2.2. It has a moderate release cadence, with updates and bug fixes released periodically.
pip install mixerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the `Mixer` for plain Python objects and use `mixer.blend` to create single instances, and `mixer.cycle` to create multiple unique instances, with or without overriding specific fields.
Migrate your imports to use backend-specific instances (e.g., `from mixer.backend.django import mixer`) or explicitly instantiate `Mixer` for plain objects (`from mixer.mix import Mixer; mixer_instance = Mixer()`).
Always import the correct mixer backend for your ORM: `from mixer.backend.django import mixer` for Django, `from mixer.backend.sqlalchemy import mixer` for SQLAlchemy, etc.
Instead of `mixer.blend(User, email=lorem.email())`, use `mixer.blend(User, email=lorem.email)`. If you need to pass arguments to the faker, use a lambda: `email=lambda: lorem.email(domain='example.com')`.
For non-nullable foreign keys, either ensure the related model can be created by Mixer successfully, or explicitly pass an existing instance of the related object: `mixer.blend(MyModel, foreign_key_field=existing_related_instance)`.