Navigation

PyMongo

Introduction

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

Take the free online course taught by MongoDB

../../_images/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

Note

MongoDB 4.2 Feature Availability

The following compatibility table specifies the recommended version(s) of the MongoDB Python driver for use with a specific version of MongoDB.

The first column lists the driver version(s).

Python Driver MongoDB 4.2 MongoDB 4.0 MongoDB 3.6 MongoDB 3.4 MongoDB 3.2 MongoDB 3.0 MongoDB 2.6
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

The following compatibility table specifies the recommended version(s) of the MongoDB Python driver for use with a specific version of Python.

The first column lists the driver version(s).

Python 2 Compatibility

Python Driver Python 2.4 Python 2.5, Jython 2.5 Python 2.6 Python 2.7, PyPy
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 Driver Python 3.1 Python 3.2 PyPy3 Python 3.3 Python 3.4 Python 3.5 Python 3.6 Python 3.7
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