Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

Your models, fake data

Project description

# Mockingbird

**Your models, mock data**

[![Build Status](](

Mockingbird creates mock data for your models. It keeps your front-end
devs happy, they can work with the output and not need to talk to a database.

It is **not** related to [](

If you are setting up your application like this, it can be a very powerful
tool to keep your front end dev marking-it-up™ and stylin-it-up™


class SqlContactRepository(object):
def get_contact(self):
this method is not done yet, but it would be really great
for the my front end developers start working and not wait on me.
I will use the MockContactRepository for the time being
while I work here. Maybe I will fetch Django Models or some other
custom work... Who knows! While I figure it out though no need
to make my front end wait!

class MockContactRepository(object)
def get_contact(self):
return mockingbird.Contact()

class ContactService(object):
def __init__(self, dao):
self.dao = dao

def get_contact(self):
return self.dao.get_contact()

class MyController(MyControllerBase):
def some_action(self):
service = ContactService(MockContacts)
contacts = service.get_contact()

I would even go one step further and not even define the service in the
controller, but define all of the services for your app in say...


Then you can control all of your service dependencies from one location!
With the flip of some text all of your services could deliver
mock data or real data and your front end devs never need know the difference!

**Mockingbird! Your models, mock data Shaaaaaaaaaaa!**

## Setup

First make some models. I'm just going to use plain-ol-python-objects.
You should be able to use any kind of model you like, Django, SQLAlchemy, etc
though those are untested.

Mockingbird uses ```setattr(your_model, "attribute_name", value)```. So anything
that supports that should work.

class Contact(object):
def __init__(self): = None
self.label = None
self.meta = None

class ContactMeta(object):
def __init__(self): = None = None
self.dob = None,
self.age = 0
self.is_married = False

class AddressBook(object):
def __init__(self):
self.contacts = []

Now that we have some models, lets tell Mockingbird about them:


from mockingbird import Mockingbird

mockingbird = Mockingbird()
mockingbird.spec(Contact, {"name": MockRealName(),
"label": MockString(min=4, max=10),
"meta": MockObject(ContactMeta)})

mockingbird.spec(ContactMeta, {"phone": MockPhone(),
"email": MockEmail(),
"dob": MockDate(),
"age": MockInt(min=22, max=44)
"is_married": MockBoolean()})

mockingbird.spec(AddressBook, {"contacts": MockList(Contact, min=10, max=20)})


As you can see, we let Mockingbird know the class we would like to register
and the attributes we would like it to set. In the dictionary that is passed
the keys represent the attributes and the values represent the kind of mock data
we would like to have applied.

Now to get one of our models filled up with mock data:


contact = mockingbird.Contact()
book = mockingbird.AddressBook()


Ta da! model objects filled to the brim with fake data. Let your front end devs
go nuts while you work on the server logic.

Currently Mockingbird supports the following Mock Data Generators:

- MockBoolean
- MockChoice
- MockDate
- MockEmail
- MockInt
- MockList
- MockObject
- MockPhoneNumber
- MockRealName
- MockText

If you would like to see how their used, go ahead and look at tests/
for now until I can write up the docs on their options. Or browse through ```mockingbird.generators.*```

Here are some additional generators I am thinking about adding:

- MockAddress
- MockCity
- MockHash
- MockPrice
- MockState
- MockUsername
- MockZip

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for mockingbird, version 0.1.4
Filename, size File type Python version Upload date Hashes
Filename, size mockingbird-0.1.4.tar.gz (13.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page