Skip to main content

MongoDB support for Muffin framework.

Project description

Muffin-Mongo – MongoDB support for Muffin framework.

Tests Status PYPI Version Python Versions


  • python >= 3.7


The plugin supports only asyncio evenloop (not trio)


Muffin-Mongo should be installed using pip:

pip install muffin-mongo


Setup the plugin and connect it into your app:

from muffin import Application
from muffin_mongo import Plugin as Mongo

# Create Muffin Application
app = Application('example')

# Initialize the plugin
# As alternative: db = DB(app, **options)
mongo = Mongo(db_url='mongodb://localhost:27017', database='db_name')

That’s it now you are able to use the plugin inside your views:

@app.route('/items', methods=['GET'])
async def get_items(request):
    """Return a JSON with items from the database."""
    documents = await mongo.items.find().sort('key').to_list(100)
    return [dict(dd.items(), _id=str(dd['_id'])) for dd in documents]

@app.route('/items', methods=['POST'])
async def insert_item(request):
    """Store items from JSON into database. Return ids."""
    data = await  # parse formdata/json from the request
    res = await mongo.items.insert_many(data)
    return [str(key) for key in res.inserted_ids]

Configuration options

Name Default value Desctiption
db_url "mongodb://localhost:27017" A mongo connection URL
database None A database name (optional)

You are able to provide the options when you are initiliazing the plugin:

mongo.setup(app, db_url='mongodb://localhost:27017')

Or setup it from Muffin.Application configuration using the MONGO_ prefix:

MONGO_DB_URL = 'mongodb://localhost:27017'

Muffin.Application configuration options are case insensitive

Bug tracker

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


Development of Muffin-Mongo happens at:


  • klen (Kirill Klenov)


Licensed under a MIT license.

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 muffin-mongo, version 0.4.0
Filename, size File type Python version Upload date Hashes
Filename, size muffin_mongo-0.4.0-py3-none-any.whl (4.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size muffin-mongo-0.4.0.tar.gz (4.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page