nameko-mongoengine
MongoEngine dependency provider for Nameko microservice framework.
Installation
pip install nameko-mongoengine
Usage
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()
@rpc
def write(self, info):
model = MyModel()
model.info = info
model.save()
return model
@rpc
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()
@rpc
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:
@rpc
def get(self, _id):
db = self.engine.with_alias("your_alias").db
return db.your_collection.find_one({'_id': _id})
Configurations
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
MONGODB_URI:
default: mongodb://localhost:27017/dbname?replicaSet=replset
"<alias>": "<uri>"
Environment Variables
MONGODB_URI='mongodb://localhost:27017/dbname?replicaSet=replset'
# or
# ---- with aliases
MONGODB_URI='{"default": "mongodb://localhost:27017/dbname?replicaSet=replset", "<alias>": "<uri>"}'
Developers
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.
Contributions
Pull requests always welcomed. Thanks!
Metadata
Release files for nameko-mongoengine 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| nameko_mongoengine-0.1.1.tar.gz | 3.9 kB | Details |
Release files / nameko_mongoengine-0.1.1.tar.gz
| Download URL | nameko_mongoengine-0.1.1.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
644be45a056a974648b28008cef51d9d91d6aaaa2356800be5b6ddc9d5e56377
|
|
BLAKE2b-256 checksum How to use checksums |
99667d9e18a59ac2d21bcfa46024ab64ace12974a91ae53e21aff00c887e67fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.6.8
|