|
| 1 | +.. _python-async-driver: |
| 2 | + |
| 3 | +==================== |
| 4 | +Motor (Async Driver) |
| 5 | +==================== |
| 6 | + |
| 7 | +.. facet:: |
| 8 | + :name: genre |
| 9 | + :values: reference |
| 10 | + |
| 11 | +.. facet:: |
| 12 | + :name: programming_language |
| 13 | + :values: python |
| 14 | + |
| 15 | +.. meta:: |
| 16 | + :keywords: Python async, Stable API, local connection, atlas, code example |
| 17 | + :description: Explore Motor, the async Python driver for MongoDB, with installation guides, connection examples, and compatibility details. |
| 18 | + |
| 19 | +.. contents:: On this page |
| 20 | + :local: |
| 21 | + :backlinks: none |
| 22 | + :depth: 1 |
| 23 | + :class: twocols |
| 24 | + |
| 25 | +.. banner:: |
| 26 | + :variant: warning |
| 27 | + |
| 28 | + As of May 14, 2025, Motor is deprecated in favor of the GA release of the PyMongo Async |
| 29 | + API in the PyMongo library. We will not add new features to Motor, and we will |
| 30 | + provide only bug fixes until it reaches end of life on May 14, 2026. After that, we will |
| 31 | + fix only critical bugs until final support ends on May 14, 2027. We |
| 32 | + strongly recommend migrating to the PyMongo Async API while Motor is still supported. |
| 33 | + |
| 34 | + For more information about migrating, see the `Migrate to PyMongo Async <https://www.mongodb.com/docs/languages/python/pymongo-driver/current/reference/migration/>`__ |
| 35 | + guide in the PyMongo documentation. |
| 36 | + |
| 37 | + |
| 38 | +Introduction |
| 39 | +------------ |
| 40 | + |
| 41 | +Welcome to the documentation site for Motor, the official MongoDB |
| 42 | +driver for asynchronous Python applications. Download it using |
| 43 | +`pip <https://pypi.python.org/pypi/pip>`__ |
| 44 | +or set up a runnable project by following our tutorials. |
| 45 | + |
| 46 | +.. tip:: |
| 47 | + |
| 48 | + If you do not need to access MongoDB in a non-blocking manner or from |
| 49 | + co-routines, we recommend that you use the `PyMongo |
| 50 | + <https://www.mongodb.com/docs/languages/python/pymongo-driver/current/>`__ |
| 51 | + driver instead. |
| 52 | + |
| 53 | +- `Tutorial on using Motor with Tornado <http://motor.readthedocs.org/en/stable/tutorial-tornado.html>`__ |
| 54 | + |
| 55 | +- `Tutorial on using Motor with asyncio <https://motor.readthedocs.io/en/stable/tutorial-asyncio.html>`__ |
| 56 | + |
| 57 | +- `Motor Documentation <http://motor.readthedocs.org/>`__ |
| 58 | + |
| 59 | +- `Changelog <http://motor.readthedocs.org/en/stable/changelog.html>`__ |
| 60 | + |
| 61 | +- `Source Code <https://github.com/mongodb/motor/>`__ |
| 62 | + |
| 63 | +Follow the links below to read blog posts that describe specific use cases |
| 64 | +for the Motor driver: |
| 65 | + |
| 66 | +- `Porting From PyMongo To Motor <http://emptysqua.re/blog/porting-from-pymongo-to-motor/>`__ |
| 67 | + |
| 68 | +- `Refactoring Tornado Coroutines <http://emptysqua.re/blog/refactoring-tornado-coroutines/>`__ |
| 69 | + |
| 70 | +- `All Motor articles on A. Jesse Jiryu Davis's blog <http://emptysqua.re/blog/category/motor/>`__ |
| 71 | + |
| 72 | +Installation |
| 73 | +------------ |
| 74 | + |
| 75 | +You must install the Motor driver module to make it available to your Python |
| 76 | +application. We recommend using `pip <http://pypi.python.org/pypi/pip>`__ |
| 77 | +to install Motor. |
| 78 | + |
| 79 | +The following command demonstrates how you can install the latest version of |
| 80 | +the module using the command line: |
| 81 | + |
| 82 | +.. code-block:: sh |
| 83 | + |
| 84 | + $ python -m pip install motor |
| 85 | + |
| 86 | +For more information on requirements and other methods of installation, |
| 87 | +see the `Motor Installation <https://motor.readthedocs.io/en/stable/installation.html>`__ |
| 88 | +documentation. |
| 89 | + |
| 90 | +.. _connect-atlas-motor-driver: |
| 91 | + |
| 92 | +Connect to MongoDB Atlas |
| 93 | +------------------------ |
| 94 | + |
| 95 | +You can use the following connection snippet to test your connection to |
| 96 | +your MongoDB deployment on Atlas using the ``asyncio`` asynchronous framework: |
| 97 | + |
| 98 | +.. literalinclude:: /includes/connection-snippets/scram/py-motor-connection.py |
| 99 | + :language: python |
| 100 | + |
| 101 | +This connection snippet uses the {+stable-api+} feature, which you can |
| 102 | +enable when using the Motor driver v2.5 and later to connect to MongoDB Server |
| 103 | +v5.0 and later. When you use this feature, you can update your driver or server without |
| 104 | +worrying about backward compatibility issues with any commands covered by the |
| 105 | +{+stable-api+}. |
| 106 | + |
| 107 | +To learn more about the {+stable-api+} feature, see |
| 108 | +:manual:`{+stable-api+} </reference/stable-api/>` in the Server manual. |
| 109 | + |
| 110 | +.. include:: /includes/stable-api-notice.rst |
| 111 | + |
| 112 | +.. _connect-atlas-no-stable-api-motor-driver: |
| 113 | + |
| 114 | +Connect to MongoDB Atlas Without the Stable API |
| 115 | +----------------------------------------------- |
| 116 | + |
| 117 | +If you are using a version of MongoDB or the driver that doesn't support the |
| 118 | +{+stable-api+} feature, you can use the following code snippet to test your connection |
| 119 | +to your MongoDB deployment on Atlas: |
| 120 | + |
| 121 | +.. literalinclude:: /includes/connection-snippets/scram/py-motor-connection-no-stableapi.py |
| 122 | + :language: python |
| 123 | + |
| 124 | +If you are using the ``tornado`` asynchronous library, you can use the |
| 125 | +following code to connect to your MongoDB deployment: |
| 126 | + |
| 127 | +.. literalinclude:: /includes/connection-snippets/scram/py-motor-connection-tornado.py |
| 128 | + :language: python |
| 129 | + |
| 130 | +Connect to a MongoDB Server on Your Local Machine |
| 131 | +------------------------------------------------- |
| 132 | + |
| 133 | +.. include:: /includes/localhost-connection.rst |
| 134 | + |
| 135 | +To test whether you can connect to your server, replace the connection |
| 136 | +string in the :ref:`Connect to MongoDB Atlas <connect-atlas-motor-driver>` code |
| 137 | +example and run it. |
| 138 | + |
| 139 | +Compatibility |
| 140 | +------------- |
| 141 | + |
| 142 | +MongoDB Compatibility |
| 143 | +~~~~~~~~~~~~~~~~~~~~~ |
| 144 | + |
| 145 | +The following compatibility table specifies the recommended version or versions |
| 146 | +of the Motor (Python async) driver for use with a specific version of MongoDB. |
| 147 | + |
| 148 | +The first column lists the driver version. |
| 149 | + |
| 150 | +.. sharedinclude:: dbx/lifecycle-schedule-callout.rst |
| 151 | + |
| 152 | +.. include:: /includes/mongodb-compatibility-table-motor.rst |
| 153 | + |
| 154 | +.. include:: /includes/older-server-versions-unsupported.rst |
| 155 | + |
| 156 | +Language Compatibility |
| 157 | +~~~~~~~~~~~~~~~~~~~~~~ |
| 158 | + |
| 159 | +The following compatibility table specifies the recommended version(s) of the |
| 160 | +Motor (Python async) driver for use with a specific version of Python. |
| 161 | + |
| 162 | +The first column lists the driver version(s). |
| 163 | + |
| 164 | +.. include:: /includes/language-compatibility-table-motor.rst |
| 165 | + |
| 166 | +.. include:: /includes/about-driver-compatibility.rst |
| 167 | + |
| 168 | +.. include:: /includes/help-links-motor.rst |
0 commit comments