Motor - the async Python driver for MongoDB and Tornado or asyncio

Overview

Motor

https://raw.github.com/mongodb/motor/master/doc/_static/motor.png

Info: Motor is a full-featured, non-blocking MongoDB driver for Python Tornado and asyncio applications.
Documentation: Available at motor.readthedocs.io
Author: A. Jesse Jiryu Davis

About

Motor presents a coroutine-based API for non-blocking access to MongoDB. The source is on GitHub and the docs are on ReadTheDocs.

"We use Motor in high throughput environments, processing tens of thousands of requests per second. It allows us to take full advantage of modern hardware, ensuring we utilise the entire capacity of our purchased CPUs. This helps us be more efficient with computing power, compute spend and minimises the environmental impact of our infrastructure as a result."

David Mytton, Server Density

"We develop easy-to-use sensors and sensor systems with open source software to ensure every innovator, from school child to laboratory researcher, has the same opportunity to create. We integrate Motor into our software to guarantee massively scalable sensor systems for everyone."

Ryan Smith, inXus Interactive

Support / Feedback

For issues with, questions about, or feedback for PyMongo, please look into our support channels. Please do not email any of the Motor developers directly with issues or questions - you're more likely to get an answer on the MongoDB Community Forums.

Bugs / Feature Requests

Think you've found a bug? Want to see a new feature in Motor? Please open a case in our issue management tool, JIRA:

Bug reports in JIRA for all driver projects (i.e. MOTOR, CSHARP, JAVA) and the Core Server (i.e. SERVER) project are public.

How To Ask For Help

Please include all of the following information when opening an issue:

  • Detailed steps to reproduce the problem, including full traceback, if possible.

  • The exact python version used, with patch level:

    $ python -c "import sys; print(sys.version)"
    
  • The exact version of Motor used, with patch level:

    $ python -c "import motor; print(motor.version)"
    
  • The exact version of PyMongo used, with patch level:

    $ python -c "import pymongo; print(pymongo.version); print(pymongo.has_c())"
    
  • The exact Tornado version, if you are using Tornado:

    $ python -c "import tornado; print(tornado.version)"
    
  • The operating system and version (e.g. RedHat Enterprise Linux 6.4, OSX 10.9.5, ...)

Security Vulnerabilities

If you've identified a security vulnerability in a driver or any other MongoDB project, please report it according to the instructions here.

Installation

Motor can be installed with pip:

$ pip install motor

Dependencies

Motor works in all the environments officially supported by Tornado or by asyncio. It requires:

  • Unix (including macOS) or Windows.
  • PyMongo >=3.11,<4
  • Python 3.5+

See requirements for details about compatibility.

Examples

See the examples on ReadTheDocs.

Documentation

Motor's documentation is on ReadTheDocs.

Build the documentation with Python 3.5. Install sphinx, Tornado, and aiohttp, and do cd doc; make html.

Testing

Run python setup.py test. Tests are located in the test/ directory.

Comments
  • MOTOR-40 Example using aiohttp.

    MOTOR-40 Example using aiohttp.

    @asvetlov, thanks to you and @jettify, Motor 0.5 with asyncio is close to release. Could you review this example application that I plan to include in the tutorial?

    The docs are rendered here:

    http://emptysqua.re/aiotthp-example-docs/tutorial-asyncio.html#a-web-application-with-aiohttp

    Review on Reviewable

    opened by ajdavis 11
  • MOTOR-979 Use asyncio.get_event_loop so that DeprecationWarnings are correctly issued

    MOTOR-979 Use asyncio.get_event_loop so that DeprecationWarnings are correctly issued

    …issued

    It looks like a workaround I wrote in Tornado was incorrectly incorporated into AsyncioMotorClient here https://github.com/mongodb/motor/pull/155/files#r851429040

    if a user has opted into DeprecationWarnings as errors asyncio.get_event_loop_policy().get_event_loop() incorrectly suppresses the deprecation warning:

    Python 3.10.4 (main, Apr  8 2022, 17:35:13) [GCC 9.4.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import motor.motor_asyncio
    >>> client = motor.motor_asyncio.AsyncIOMotorClient()
    >>> client.test.pages.drop()  # this should raise a DeprecationWarning because it was called without a running loop
    <Future pending cb=[_chain_future.<locals>._call_check_cancel() at /usr/lib/python3.10/asyncio/futures.py:384]>
    >>> 
    
    opened by graingert 8
  • MotorCursor().to_list applies outgoing_son_manipulators as expected

    MotorCursor().to_list applies outgoing_son_manipulators as expected

    • added MotorDatabase()._fix_outgoing calling the delegate's method since we call add_son_manipulator on the delegate as well.
    • applying _fix_outgoing when to_list retrieves data from Cursor's deque
    • tests for to_list and control find_one, next_object (these two were unaffected by this bug)
    opened by eguven 7
  • MOTOR-884 Mirror all PyMongo extras

    MOTOR-884 Mirror all PyMongo extras

    Motor is a wrapper around Pymongo, extras available during pip install Pymongo should be available with Motor as well. I recently faced an issue regarding this and have raised it on Jira.

    opened by tusharsnn 5
  • Add 'mongo_client' argument to AgnosticClient

    Add 'mongo_client' argument to AgnosticClient

    This change adds a new mongo_client argument when creating a new MotorClient or AsyncIOMotorClient instance, setting the delegate object to a pre-existing MongoClient instead of creating a new instance.

    Background

    I help maintain a project that uses Motor and has a very large number of tests, the majority of which involve MongoDB accesses. These tests use Tornado's AsyncTestCase and create new MotorClient instances in their setUp methods. As the tests run, they become progressively slower and, especially on weaker computers, eventually hang. Attaching a debugger to the hung Python process shows that there are a large number of active threads, the number roughly corresponding to the number of MotorClient instances that were created, thus far. These threads appear to be running the PyMongo _process_periodic_tasks code run through the periodic executor.

    To avoid the hanging issue and improve overall test performance, we would like to be able to re-use the same MotorClient instance in all tests that need database access but, since MotorClient needs an IO loop and Tornado's AsyncTestCase creates a new IO loop for each test, that does not appear possible. A decent alternative is to re-use a single MongoClient instance for all tests and pass that MongoClient when creating a new MotorClient in the setUp method.

    opened by tjensen 5
  • Add optional dependencies, forwarding them to pymongo

    Add optional dependencies, forwarding them to pymongo

    pymongo supports three optional dependencies, it would be nice to support them as well here, so that we can depend directly on motor[srv] instead of having to list both motor and pymongo[srv]

    opened by arthurdarcet 4
  • MOTOR-1014 Add __aenter__ and __aexit__ for AgnosticBaseCursor so that cursor can be instantiated using the context manager

    MOTOR-1014 Add __aenter__ and __aexit__ for AgnosticBaseCursor so that cursor can be instantiated using the context manager

    When I use the following code:

    async with self.coll.find() as cursor:
        async for record in cursor:
            yield record
    

    It's going to throw an AttributeError So I added the asynchronous context manager method so that I did not have to close the cursor when I was done with it

    opened by coderk17 3
Releases(3.1.1)
  • 3.1.1(Oct 25, 2022)

  • 3.1.0(Sep 13, 2022)

  • 3.0.0(Apr 28, 2022)

  • 2.5.1(Aug 19, 2021)

  • 2.4.0(Apr 8, 2021)

    Motor 2.4 adds support for client-side field-level encryption and Python 3.9.

    For more info see the changelog: https://motor.readthedocs.io/en/2.4.0/changelog.html

    Source code(tar.gz)
    Source code(zip)
  • 2.3.0(Sep 24, 2020)

  • 2.2.0(Aug 14, 2020)

    Motor 2.2 adds support for MongoDB 4.4 features. It depends on PyMongo 3.11 or later. Motor continues to support MongoDB 3.0 and later. Motor 2.2 also drops support for Python 2.7 and Python 3.4.

    For more info see the changelog: https://motor.readthedocs.io/en/2.2.0/changelog.html

    Source code(tar.gz)
    Source code(zip)
  • 2.1.0(Dec 12, 2019)

    Motor 2.1 adds support for MongoDB 4.2 features. It depends on PyMongo 3.10 or later. Motor continues to support MongoDB 3.0 and later. Motor 2.1 also adds support for Python 3.8.

    Motor now offers experimental support for Windows when it is using the asyncio event loop. This means it supports Windows exclusively with Python 3, either integrating with asyncio directly or with Tornado 5 or later: starting in version 5, Tornado uses the asyncio event loop on Python 3 by default.

    For more info see the changelog: https://motor.readthedocs.io/en/2.1.0/changelog.html

    Source code(tar.gz)
    Source code(zip)
Owner
mongodb
mongodb
MongoX is an async python ODM for MongoDB which is built on top Motor and Pydantic.

MongoX MongoX is an async python ODM (Object Document Mapper) for MongoDB which is built on top Motor and Pydantic. The main features include: Fully t

Amin Alaee 112 Dec 4, 2022
PyMongo - the Python driver for MongoDB

PyMongo Info: See the mongo site for more information. See GitHub for the latest source. Documentation: Available at pymongo.readthedocs.io Author: Mi

mongodb 3.7k Jan 8, 2023
MongoDB data stream pipeline tools by YouGov (adopted from MongoDB)

mongo-connector The mongo-connector project originated as a MongoDB mongo-labs project and is now community-maintained under the custody of YouGov, Pl

YouGov 1.9k Jan 4, 2023
An asyncio compatible Redis driver, written purely in Python. This is really just a pet-project for me.

asyncredis An asyncio compatible Redis driver. Just a pet-project. Information asyncredis is, like I've said above, just a pet-project for me. I reall

Vish M 1 Dec 25, 2021
asyncio compatible driver for elasticsearch

asyncio client library for elasticsearch aioes is a asyncio compatible library for working with Elasticsearch The project is abandoned aioes is not su

null 97 Sep 5, 2022
Async ODM (Object Document Mapper) for MongoDB based on python type hints

ODMantic Documentation: https://art049.github.io/odmantic/ Asynchronous ODM(Object Document Mapper) for MongoDB based on standard python type hints. I

Arthur Pastel 732 Dec 31, 2022
sync/async MongoDB ODM, yes.

μMongo: sync/async ODM μMongo is a Python MongoDB ODM. It inception comes from two needs: the lack of async ODM and the difficulty to do document (un)

Scille 428 Dec 29, 2022
python-beryl, a Python driver for BerylDB.

python-beryl, a Python driver for BerylDB.

BerylDB 3 Nov 24, 2021
ClickHouse Python Driver with native interface support

ClickHouse Python Driver ClickHouse Python Driver with native (TCP) interface support. Asynchronous wrapper is available here: https://github.com/myma

Marilyn System 957 Dec 30, 2022
DataStax Python Driver for Apache Cassandra

DataStax Driver for Apache Cassandra A modern, feature-rich and highly-tunable Python client library for Apache Cassandra (2.1+) and DataStax Enterpri

DataStax 1.3k Dec 25, 2022
Neo4j Bolt driver for Python

Neo4j Bolt Driver for Python This repository contains the official Neo4j driver for Python. Each driver release (from 4.0 upwards) is built specifical

Neo4j 762 Dec 30, 2022
Pure-python PostgreSQL driver

pg-purepy pg-purepy is a pure-Python PostgreSQL wrapper based on the anyio library. A lot of this library was inspired by the pg8000 library. Credits

Lura Skye 11 May 23, 2022
A Python Object-Document-Mapper for working with MongoDB

MongoEngine Info: MongoEngine is an ORM-like layer on top of PyMongo. Repository: https://github.com/MongoEngine/mongoengine Author: Harry Marr (http:

MongoEngine 3.9k Jan 8, 2023
Monty, Mongo tinified. MongoDB implemented in Python !

Monty, Mongo tinified. MongoDB implemented in Python ! Inspired by TinyDB and it's extension TinyMongo. MontyDB is: A tiny version of MongoDB, against

David Lai 522 Jan 1, 2023
A simple password manager I typed with python using MongoDB .

Python with MongoDB A simple python code example using MongoDB. How do i run this code • First of all you need to have a python on your computer. If y

null 31 Dec 6, 2022
Implementing basic MongoDB CRUD (Create, Read, Update, Delete) queries, using Python.

MongoDB with Python Implementing basic MongoDB CRUD (Create, Read, Update, Delete) queries, using Python. We can connect to a MongoDB database hosted

MousamSingh 4 Dec 1, 2021
A CRUD and REST api with mongodb atlas.

Movies_api A CRUD and REST api with mongodb atlas. Setup First import all the python dependencies in your virtual environment or globally by the follo

Pratyush Kongalla 0 Nov 9, 2022
A Pythonic, object-oriented interface for working with MongoDB.

PyMODM MongoDB has paused the development of PyMODM. If there are any users who want to take over and maintain this project, or if you just have quest

mongodb 345 Dec 25, 2022
Micro ODM for MongoDB

Beanie - is an asynchronous ODM for MongoDB, based on Motor and Pydantic. It uses an abstraction over Pydantic models and Motor collections to work wi

Roman 993 Jan 3, 2023