Registry / testing / mixer
library7.2.2pypypiunverified

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 mixer
INSTALL
IMPORT
SIG · MIXER
M
mixer
testingpythonv7.2.2
Install
2.7s avg
Import
Disk
35MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v7.2.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.940 runs
installs and imports cleanly · install 0.0s · import 0.000s · 37.2MB
glibc
py 3.103.940 runs
installs and imports cleanly · install 2.7s · import 0.000s · 38MB
35MB installed
● package 35MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Mixer
from mixer import Mixer
from mixer import Mixer

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.

from mixer.mix import Mixer class User: def __init__(self, name: str, email: str, age: int): self.name = name self.email = email self.age = age def __repr__(self): return f"User(name='{self.name}', email='{self.email}', age={self.age})" mixer = Mixer() # Initialize a mixer instance for plain Python objects # Create a single user with random data user_instance = mixer.blend(User) print(f"Random User: {user_instance}") # Create a user with specific fields specific_user = mixer.blend(User, name='Alice', age=30) print(f"Specific User: {specific_user}") # Create multiple unique users users_list = mixer.cycle(3, User) print("\nMultiple Users:") for user in users_list: print(user)
Debug
Known issues
breakingThe `mixer.main.mixer` module and `mixer.mix.Mixer` (as a top-level callable) were removed or significantly changed. Direct imports like `from mixer.main import mixer` will fail.
fix
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()`).
affects: 7.0.0 and later
gotchaUsing the wrong `mixer` instance for your ORM backend (e.g., using `mixer.mix.Mixer` instance for a Django model) will not correctly integrate with the ORM's save methods or relationships, potentially leading to validation errors or incorrect data.
fix
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.
affects: All versions
gotchaWhen providing callables (like `mixer.fakers` functions) to `mixer.blend` or `mixer.cycle`, pass the callable itself, not the result of calling it. Mixer will invoke the callable for each new object.
fix
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')`.
affects: All versions
gotchaMixer attempts to create related objects for foreign keys automatically. If a related object is not explicitly provided, and the foreign key is non-nullable, this can lead to `IntegrityError` if the automatically created related object is invalid or fails to save.
fix
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)`.
affects: All versions
Upgrade
Version history
7.2.2latest on PyPI · released Mar 23, 2022
Audit
Dependencies
DjangooptionalRequired for Django ORM integration
SQLAlchemyoptionalRequired for SQLAlchemy ORM integration
MongoEngineoptionalRequired for MongoEngine ODM integration
Agent activity
19 hits · last 30 days
node
16
Amazon
1
Resources
mixer — pip install mixer · libregistry