Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Flask-Mixer -- Flask sqlalchemy model object generation

branch: master
Octocat-spinner-32 docs Change license to BSD September 02, 2012
Octocat-spinner-32 flask_mixer Update version June 19, 2013
Octocat-spinner-32 tests Fix nullable FK December 11, 2012
Octocat-spinner-32 .gitignore Add docs September 02, 2012
Octocat-spinner-32 .gitmodules Add flask theme September 02, 2012
Octocat-spinner-32 .travis.yml fix build August 19, 2012
Octocat-spinner-32 Changelog Update version June 19, 2013
Octocat-spinner-32 DESCRIPTION Initial commit August 13, 2012
Octocat-spinner-32 LICENSE fix license September 02, 2012
Octocat-spinner-32 Initial commit August 13, 2012
Octocat-spinner-32 Makefile Fix nullable FK December 11, 2012
Octocat-spinner-32 README.rst Fix warn June 19, 2013
Octocat-spinner-32 deprecated.png fix image size June 20, 2013
Octocat-spinner-32 Fix setup September 03, 2012



This module is depricated. Use instead.

Flask-Mixer is simply application for generate instances of SQLAlchemy models. It's useful for testing. Fast and convenient test-data generation.

Flask-Mixer is in early development.

Build Status


  • python >= 2.6
  • Flask >= 0.8
  • Flask-SQLAlchemy>=0.16


Flask-Mixer should be installed using pip:

pip install Flask-Mixer



from flask import Flask
from flask.ext.mixer import Mixer
from flask.ext.sqlalchemy import SQLAlchemy
from datetime import datetime

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
db = SQLAlchemy()

class User(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True)
    score = db.Column(db.Integer, default=50, nullable=False)
    created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
    username = db.Column(db.String(20), nullable=False)

class Role(db.Model):
    __tablename__ = 'role'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey(, nullable=False)

    user = db.relation(User)

class Profile(db.Model):
    __tablename__ = 'profile'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(20), nullable=False)
    user = db.relationship("User", uselist=False, backref="profile")

mixer = Mixer(app, session_commit=True)

with app.test_request_context():

    # Simple model generation
    user1 = mixer.blend(User)
    assert and user1.username and user1.created_at
    assert user1.score == 50
    assert user.profile.user == user

    # Generate model with some values
    user2 = mixer.blend(User, username='test')
    assert user2.username == 'test'

    # Model would be defined as string
    role1 = mixer.blend('app.models.Role')
    assert role1.user
    assert role1.user_id ==

    # Generate model with reference
    role1 = mixer.blend(Role, user__username='test2')
    assert role2.user.username == 'test2'

    # Set related values from db by random
    profiles = Profile.query.all()
    user = mixer.blend(User, profile=mixer.random)
    assert user.profile in profiles

    # By default, column with defvalue will be to init as them
    # but you can still force set it to random value
    user = mixer.blend(User, score=mixer.random)
    assert user.score != 50

    # Value can be callable
    user = mixer.blend(User, username=lambda:'callable_value')
    assert user.username == 'callable_value'

Bug tracker

If you have any suggestions, bug reports or annoyances please report them to the issue tracker at


Development of flask-mixer happens at github:


  • klen (Kirill Klenov)


Licensed under a BSD license.

Something went wrong with that request. Please try again.