Skip to main content

Simple MongoDb dependency for nameko (microservices framework). Based on https://github.com/saiqi/nameko-mongodb

Project description

Overview

Build Status

This is DependencyProvider for Nameko microservices framework which enables users to work with MongoDb.

First of all I should say that this package based on https://github.com/saiqi/nameko-mongodb . Thank you @saiqi :)

What has been changed:

  • Automatic uploading to PyPI by Travis-CI (it was a primary purpose for building of my pet projects)
  • Disabled by default results logging
  • Some fixes to make this stuff work with new Nameko

Requirements

  • Python 2.7 / 3.4 / 3.5 / 3.6 / 3.7
  • Nameko 3.11+
  • MongoDb :)

Installation

The same as you guessing: pip install nameko-mongodb

How to use

There are some configuration options to use this package (required are in bold):

  • MONGODB_CONNECTION_URL - connection URL
  • MONGODB_DB_NAME - database name. Default is your service name
  • MONGODB_USER - if you need to be authenticated, provide username
  • MONGODB_PASSWORD
  • MONGODB_AUTHENTICATION_BASE - a source to authenticate. See more information in PyMongo documentation
  • MONGODB_AUTH_MECHANISM - see more information in PyMongo documentation

You can use the connection following way:

from nameko.rpc import rpc
import MongoDatabase from nameko_mongodb


class YourService(object):
    name = 'your_service'

    database = MongoDatabase()

    @rpc
    def find_item(self):
        return self.database.your_collection.find_one()

Also this package can log all executions to logging collection. If you want to use it:

from nameko.rpc import rpc
import MongoDatabase from nameko_mongodb


class YourService(object):
    name = 'your_service'

    database = MongoDatabase(result_backend=True)

    @rpc
    def find_item(self):
        return self.database.your_collection.find_one()

Sometimes there can be useful to get possibility executing callbacks for DependencyProvider methods (i.e. migrating data when dependency initialized etc.). There are some callbacks:

  • on_before_setup: (instance)
  • on_after_setup: (instance)
  • on_before_stop: (instance)
  • on_after_stop: (instance)
  • on_before_worker_setup: (instance, worker_ctx)
  • on_after_worker_setup: (instance, worker_ctx)
  • on_before_worker_result: (instance, worker_ctx, result, exc_info)
  • on_after_worker_result: (instance, worker_ctx, result, exc_info)

How to use callbacks:

from nameko.rpc import rpc
import MongoDatabase from nameko_mongodb


class YourService(object):
    name = 'your_service'

    database = MongoDatabase(
        on_before_setup=lambda x: print("Start setup DP"), 
        on_after_setup=lambda x: print("Stop setup DP"),
    )

    @rpc
    def find_item(self):
        return self.database.your_collection.find_one()

Contribution

I'd be glad to see your pull requests

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-mongodb-1.0.2.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

nameko_mongodb-1.0.2-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file nameko-mongodb-1.0.2.tar.gz.

File metadata

  • Download URL: nameko-mongodb-1.0.2.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for nameko-mongodb-1.0.2.tar.gz
Algorithm Hash digest
SHA256 5f9fdd1a92b33ffc1d7f05b074edb2d2838a81f6afab245ad9843e6f2412b793
MD5 47d37dc7487cbfa6fdeea9bd7b349eb6
BLAKE2b-256 61bdcf08da50c1007797ba57a4f9bcc9e2f66613da017c93346c7af8de41161e

See more details on using hashes here.

File details

Details for the file nameko_mongodb-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: nameko_mongodb-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for nameko_mongodb-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e5f5719892f65f8e09a279b6985d3361e98b8927eaf489953c7a1091a3c284ab
MD5 f918c69fec97035d14159a328cbbe0f9
BLAKE2b-256 5e31b9768506b152e63d6be5d6350b293236b4f400d336408f4a92180c8fce76

See more details on using hashes here.

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