MongoDB with μMongo ODM support for Sanic framework
Project description
MongoDB with μMongo ODM support for Sanic framework
Features
Uses motor_asyncio package for async queries to MongoDB
Good integrated with uMongo ODM, so that you can use it easily in your projects
Installation
This package should be installed using pip:
pip install sanic-mongodb-extension
Example
from sanic import Sanic, response
from sanic_mongodb_ext import MongoDbExtension
from umongo import Document, MotorAsyncIOInstance
from umongo.fields import StringField
app = Sanic(__name__)
# Configuration for MongoDB and uMongo
app.config.update({
"MONGODB_DATABASE": "example_database",
"MONGODB_URI": "mongodb://user:password@mongodb:27017",
"LAZY_UMONGO": MotorAsyncIOInstance(),
})
MongoDbExtension(app) # uMongo client is available as `app.mongodb` or `app.extensions['mongodb']`
instance = app.config["LAZY_UMONGO"] # For a structured applications the lazy client very useful
# Describe the model
@instance.register
class Artist(Document):
name = StringField(required=True, allow_none=False)
# And use it later for APIs
@app.route("/")
async def handle(request):
artist = Artist(name="A new rockstar!")
await artist.commit()
return response.json(artist.dump())
License
The sanic-mongodb-extension is published under BSD license. For more details read LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for sanic_mongodb_extension-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1d490def383e7e790d52beac9abc6a235b79728ead21381ab5d74766c6840d1 |
|
MD5 | d0051a30170b79c3e886594a4c7d81bf |
|
BLAKE2b-256 | f99deb6f821127e994b647f35ebcbf1766d33598294f50b97dab3620b0b45155 |