Docs Menu

Compatibility

The following compatibility table specifies the recommended version or versions of PyMongo for use with a specific version of MongoDB.

The first column lists the driver version.

Important

MongoDB ensures compatibility between the MongoDB Server and the drivers for three years after the server version's end of life (EOL) date. To learn more about the MongoDB release and EOL dates, see MongoDB Software Lifecycle Schedules.

Icon
Explanation

All features are supported.

The Driver version will work with the MongoDB version, but not all new MongoDB features are supported.

No mark

The Driver version is not tested with the MongoDB version.

PyMongo Version
MongoDB 8.0
MongoDB 7.0
MongoDB 6.0
MongoDB 5.0
MongoDB 4.4
MongoDB 4.2
MongoDB 4.0
MongoDB 3.6

4.11

4.9 to 4.10

4.4 to 4.8

4.2 to 4.3

3.12 to 4.1

3.11

3.9 to 3.10

3.7 to 3.8

PyMongo supports both CPython and PyPy.

When a version of Python is marked end-of-life (EOL), the next minor release of PyMongo drops support for that version. The driver offers the following ongoing support for EOL Python versions:

  • CPython: The last minor PyMongo version compatible with the EOL CPython version receives critical bug fixes for one year.

  • PyPy: PyMongo doesn't support PyPy versions past their EOL date.

The following compatibility table specifies the recommended version of PyMongo for use with a specific version of Python. The first column lists the driver version.

PyMongo Version
CPython 3.13
CPython 3.12
CPython 3.11
CPython 3.10 [1]
CPython 3.9
CPython 3.8
CPython 3.7
CPython 3.6
CPython 3.5
CPython 3.4
PyPy3

4.11

4.9 to 4.10

4.8

4.5 to 4.7

4.3 to 4.4

4.2

4.1 [2]

4.0

3.13

3.12

3.11

3.10

3.7 to 3.9

[1] Versions of Python 3.10 and later are not compatible with TLS/SSL for versions of MongoDB 4.0 and earlier. For more information, see the TLS section of the Troubleshooting guide.
[2] Pymongo 4.1 requires Python 3.6.2 or later.

For more information about how to read the compatibility tables, see MongoDB Compatibility Tables.

PyMongo versions 3.7 through 3.12 are compatible with Python 2.7 and PyPy, a Python 2.7-compatible alternative interpreter. However, in some cases, PyMongo applications behave differently when running in a Python 2 environment.

The following sections describe the differences in behavior between Python 2 and Python 3 when using PyMongo.

In all versions of Python, PyMongo encodes instances of the bytes class as binary data with subtype 0, the default subtype for binary data. In Python 3, PyMongo decodes these values to instances of the bytes class. In Python 2, the driver decodes them to instances of the Binary class with subtype 0. For code examples that show the differences, see the Extended JSON page.

The driver behaves the same way when decoding JSON binary values with subtype 0. In Python 3, it decodes these values to instances of the bytes class. In Python 2, the driver decodes them to instances of the Binary class with subtype 0. For code examples that show the differences, see the Extended JSON page.

If you pickled an ObjectId in Python 2 and want to unpickle it in Python 3, you must pass encoding='latin-1' as an argument to the pickle.loads() method.

The following example shows how to use Python 3 to unpickle an ObjectId that was pickled in Python 2:

import pickle
pickle.loads(b'<ObjectId byte stream>', encoding='latin-1')

If a Python 3 application uses a compatible serialization protocol to pickle an ObjectId, you can use Python 2 to unpickle it. To specify a compatible protocol in Python 3, pass a value of 0, 1, or 2 for the protocol parameter of the pickle.dumps() method.

The following example pickles an ObjectId in Python 3, then prints the ObjectId and resulting bytes instance:

import pickle
from bson.objectid import ObjectId
oid = ObjectId()
oid_bytes = pickle.dumps(oid, protocol=2)
print("ObjectId: {}".format(oid))
print("ObjectId bytes: {}".format(oid_bytes))
ObjectId: 67af9b1fae9260c0e97eb9eb
ObjectId bytes: b'\x80\x02cbson.objectid\nObjectId\nq\x00...

The following example unpickles the ObjectId from the previous example, and then prints the bytes and ObjectId instances:

import pickle
from bson.objectid import ObjectId
oid_bytes = b'\x80\x02cbson.objectid\nObjectId\nq\x00...'
oid = pickle.loads(oid_bytes)
print("ObjectId bytes: {}".format(oid_bytes))
print("ObjectId: {}".format(oid))
ObjectId bytes: b'\x80\x02cbson.objectid\nObjectId\nq\x00)...
ObjectId: 67af9b1fae9260c0e97eb9eb