Navigation

PyMongo

PyMongo is the recommended way to work with MongoDB from Python.

Banner for the M220P MongoDB University Course

M220P: MongoDB for Python Developers

Learn the essentials of Python application development with MongoDB.

We recommend using pip to install pymongo on all platforms:

$ python -m pip install pymongo

To get a specific version of pymongo:

$ python -m pip install pymongo==3.11

To upgrade using pip:

$ python -m pip install --upgrade pymongo

See Installation for more ways to install.

To connect to a MongoDB Atlas cluster, use the Atlas connection string for your cluster:

import pymongo
client = pymongo.MongoClient(
"mongodb+srv://<username>:<password>@<cluster-url>/test?retryWrites=true&w=majority")
db = client.test
Python DriverMongoDB 4.4MongoDB 4.2MongoDB 4.0MongoDB 3.6MongoDB 3.4MongoDB 3.2MongoDB 3.0MongoDB 2.6
3.11
3.10
3.9
3.8
3.7
3.6
3.5
3.4
3.3
3.2
3.1
3.0
2.9
2.8
2.7

The driver does not support older versions of MongoDB.

Python DriverPython 2.7, PyPyPython 2.6Python 2.5, Jython 2.5Python 2.4
3.11
3.10
3.9
3.8
3.7
3.6
3.5
3.4
3.3
3.2
3.1
3.0
2.9
2.8
2.7
Python DriverPython 3.9Python 3.8Python 3.7Python 3.6Python 3.5Python 3.4Python 3.3PyPy3Python 3.2Python 3.1
3.11
3.10
3.9
3.8
3.7
3.6
3.5
3.4
3.3
3.2
3.1
3.0
2.9
2.8
2.7
Info With Circle IconCreated with Sketch.Note
  • Jython 2.5 is a Python 2.5-compatible alternative interpreter.
  • PyPy is a Python 2.7 and 3.2-compatible alternative interpreter.

For more information on how to read the compatibility tables, see our guide on MongoDB Compatibility Tables.

Give Feedback