Motor client provider for applauncher
pip install motor_bundle
Then add to your main.py
import motor_bundle
bundle_list = [
motor_bundle.MotorBundle(),
]
Currently just the connection uri, for example
motor:
uri: 'mongodb://localhost/default'
Just inject and use it as a regular motor client. Check example.py
for more details
from applauncher import Kernel, event, ServiceContainer
from motor_bundle import MotorBundle
import asyncio
class ExampleBundle:
def __init__(self):
self.event_listeners = [
(event.KernelReadyEvent, self.run),
]
async def do_insert(self, db):
document = {'key': 'value'}
result = await db.test_collection.insert_one(document)
print('result %s' % repr(result.inserted_id))
def run(self, event):
"""Injecting the client"""
motor = ServiceContainer.motor.client()
db = motor.get_default_database()
loop = asyncio.get_event_loop()
loop.run_until_complete(self.do_insert(db))
with Kernel(bundles=[MotorBundle(), ExampleBundle()], environment="DEV") as kernel:
kernel.wait()
More information in the motor documentation