Skip to main content

Yet another MongoDB ORM for Python. Signals included!

Project description

Yet another MongoDB ORM for Python. Signals included!

(Note: signals can be used independently from miongo models)

Still in development, feedback is highly appreciated.

Usage Examples


pip install miongo


Here’s a simple example of model usage:

#!/usr/bin/env python
import pymongo
from miongo import models

# this is always required
# mingo do not implement mongodb connection, you should do that
models.mongodb_database = pymongo.MongoClient().test_database

class TestModel(models.Model):
    _collection = 'testmodel'

    uid = models.Field()
    name = models.Field()
    enabled = models.Field(default=True)

# creating and saving
model = TestModel()
model.uid = 1 = 'Antony'

# finding in db
model = TestModel()
model.find({'uid': 1})
print model.uid  # 1
print  # Antony
print model.enabled  # True


Signals can be used independently with your models too! Just use signals.SignalEmitterMixin, specify AVAILABLE_SIGNALS and call self.emit_signal(signal_type) to fire a signal when needed.

Here’s an example of implementing before and after save signals:

#!/usr/bin/env python
import pymongo
from miongo import signals, models

models.mongodb_database = pymongo.MongoClient().test_database

# signals.SignalEmitterMixin is important here
# it also can be used with other model classes
class TestModel(models.Model, signals.SignalEmitterMixin):
    _collection = 'testmodel'

    AFTER_SAVE = 1

    name = models.Field()

    def save(self):
        print 'Saving now!'
        super(TestModel, self).save()

# let's define function that will be used by signal
# you may use instance to modify object
def signal_function(signal_type, instance):
    if signal_type == TestModel.BEFORE_SAVE:
        print 'Before save'
    elif signal_type == TestModel.AFTER_SAVE:
        print 'After save'

model = TestModel()

TestModel.connect_to_signal(TestModel.BEFORE_SAVE, signal_function)
TestModel.connect_to_signal(TestModel.AFTER_SAVE, signal_function)

# output is:
# Before save
# Saving now!
# After save

(Note signals can be connected to the instance too)


Author: Anton Kasyanov (

Special thanks to: Ruslan Didyk, Igor Emelyanov

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 miongo, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size miongo-0.1.1.tar.gz (4.9 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