Skip to main content

MongoDB with μMongo ODM support for Sanic framework

Project description

MongoDB with μMongo ODM support for Sanic framework


  • Uses motor_asyncio package for async queries to MongoDB
  • Good integrated with uMongo ODM, so that you can use it easily in your projects


This package should be installed using pip:

pip install sanic-mongodb-extension


#!/usr/bin/env python3
from sanic import Sanic, response
from sanic_mongodb_ext import MongoDbExtension
from umongo import Instance, Document, MotorAsyncIOInstance
from umongo.fields import StringField

app = Sanic(__name__)
# Configuration for MongoDB and uMongo
    "MONGODB_DATABASE": "app", # Make ensure that the `app` database is really exists
    "MONGODB_URI": "mongodb://root:root@mongodb:27017",
    # You can also specify custom connection options.
    # For more details check the official docs:
        "minPoolSize": 10,
        "maxPoolSize": 50,
    "LAZY_UMONGO": MotorAsyncIOInstance(),
# uMongo client is available as `app.mongodb` or `app.extensions['mongodb']`.
# The lazy client will be available as `app.lazy_mongodb` only when the database was specified,
# and which is a great choice for the structured projects.

# Describe the model
class Artist(Document):
    name = StringField(required=True, allow_none=False)

# And use it later for APIs
async def handle(request):
    artist = Artist(name="A new rockstar!")
    await artist.commit()
    return response.json(artist.dump())

if __name__ == '__main__':'', port=8000)


The sanic-mongodb-extension is published under BSD license. For more details read LICENSE file.

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 sanic-mongodb-extension, version 0.4.0
Filename, size File type Python version Upload date Hashes
Filename, size sanic_mongodb_extension-0.4.0-py3-none-any.whl (4.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size sanic-mongodb-extension-0.4.0.tar.gz (3.5 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