Skip to main content

Mongoengine dependency provider for Nameko microservice framework

Project description


Build Status Apache 2.0 licensed

MongoEngine dependency provider for Nameko microservice framework.


pip install nameko-mongoengine


The basic usage of the dependency provider is shown:

from mongoengine import Document, fields
from nameko_mongoengine import MongoEngine
from nameko.rpc import rpc

class MyModel(Document):
        My document model
    info = fields.StringField(required=True)

class MockService:
    name = "mock_service"
    engine = MongoEngine()

    def write(self, info):
        model = MyModel() = info
        return model

    def read(self, _id):
        return MyModel.objects.get(id=_id)

The dependency engine exposes standard pymongo interface to database connections. The default connection can be accessed by the db property:

class MockService:
    name = "mock_service"
    engine = MongoEngine()

    def get(self, _id):
        return self.engine.db.your_collection.find_one({'_id': _id})

Other database connections defined by MongoEngine aliases can be accessed by:

def get(self, _id):
    db = self.engine.with_alias("your_alias").db
    return db.your_collection.find_one({'_id': _id})


The dependency configurations can be set in nameko config.yaml file, or by environment variables.

Config File

MONGODB_URI: mongodb://localhost:27017/dbname?replicaSet=replset

# or
# ---- with aliases
  default: mongodb://localhost:27017/dbname?replicaSet=replset
  "<alias>": "<uri>"

Environment Variables


# or
# ---- with aliases
MONGODB_URI='{"default": "mongodb://localhost:27017/dbname?replicaSet=replset", "<alias>": "<uri>"}'


To perform development tasks and run tests run:

$ pip install -e .[dev]			# to install all dependencies
$ docker run -d --restart=always --name some-rabbit -p 5672:5672 -p 15672:15672 rabbitmq:3-management   # Run rabbitmq-management server
$ docker run --rm -d -p 27017:27017 mongo			# Run mongodb server on docker
$ pytest --cov=nameko_mongoengine tests/			# to get coverage report
$ pylint nameko_mongoengine			# to check code quality with PyLint

Optionally you can use make.


Pull requests always welcomed. Thanks!

Project details

Download files

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

Source Distribution

nameko_mongoengine-0.1.1.tar.gz (3.9 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page