Navigation

PyMongo

Introduction

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

Take the free online course taught by MongoDB

/figures/M220P_hero.jpg

M220P: MongoDB for Python Developers

Learn the essentials of Python application development with MongoDB.

Installation

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.5.1

To upgrade using pip:

$ python -m pip install --upgrade pymongo

See Installation for more ways to install.

Connect to MongoDB Atlas

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

Compatibility

MongoDB Compatibility

Python DriverMongoDB 4.2MongoDB 4.0MongoDB 3.6MongoDB 3.4MongoDB 3.2MongoDB 3.0MongoDB 2.6
3.11 (beta)
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.

Language Compatibility

Python 2 Compatibility

Python DriverPython 2.4Python 2.5, Jython 2.5Python 2.6Python 2.7, PyPy
3.11 (beta)
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 3 Compatibility

Python DriverPython 3.1Python 3.2PyPy3Python 3.3Python 3.4Python 3.5Python 3.6Python 3.7
3.11 (beta)
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

note

  • Jython 2.5 is a Python 2.5-compatible alternative interpreter.
  • PyPy is a Python 2.7 and 3.2-compatible alternative interpreter.

How to get help