Mixer

7.2.2 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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)

view raw JSON →