pymongo 4.13.0


pip install pymongo

  Latest version

Released: May 14, 2025


Meta
Author: The MongoDB Python Team
Requires Python: >=3.9

Classifiers

Development Status
  • 5 - Production/Stable

Intended Audience
  • Developers

License
  • OSI Approved :: Apache Software License

Operating System
  • MacOS :: MacOS X
  • Microsoft :: Windows
  • POSIX

Programming Language
  • Python :: 3
  • Python :: 3 :: Only
  • Python :: 3.9
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: Implementation :: CPython
  • Python :: Implementation :: PyPy

Topic
  • Database

Typing
  • Typed

PyMongo

PyPI Version Python Versions Monthly Downloads API Documentation Status

About

The PyMongo distribution contains tools for interacting with MongoDB database from Python. The bson package is an implementation of the BSON format for Python. The pymongo package is a native Python driver for MongoDB, offering both synchronous and asynchronous APIs. The gridfs package is a gridfs implementation on top of pymongo.

PyMongo supports MongoDB 4.0, 4.2, 4.4, 5.0, 6.0, 7.0, and 8.0.

Support / Feedback

For issues with, questions about, or feedback for PyMongo, please look into our support channels. Please do not email any of the PyMongo developers directly with issues or questions - you're more likely to get an answer on StackOverflow (using a "mongodb" tag).

Bugs / Feature Requests

Think you've found a bug? Want to see a new feature in PyMongo? Please open a case in our issue management tool, JIRA:

Bug reports in JIRA for all driver projects (i.e. PYTHON, CSHARP, JAVA) and the Core Server (i.e. SERVER) project are public.

How To Ask For Help

Please include all of the following information when opening an issue:

  • Detailed steps to reproduce the problem, including full traceback, if possible.

  • The exact python version used, with patch level:

python -c "import sys; print(sys.version)"
  • The exact version of PyMongo used, with patch level:
python -c "import pymongo; print(pymongo.version); print(pymongo.has_c())"
  • The operating system and version (e.g. Windows 7, OSX 10.8, ...)

  • Web framework or asynchronous network library used, if any, with version (e.g. Django 1.7, mod_wsgi 4.3.0, gevent 1.0.1, Tornado 4.0.2, ...)

Security Vulnerabilities

If you've identified a security vulnerability in a driver or any other MongoDB project, please report it according to the instructions here.

Installation

PyMongo can be installed with pip:

python -m pip install pymongo

You can also download the project source and do:

pip install .

Do not install the "bson" package from pypi. PyMongo comes with its own bson package; running "pip install bson" installs a third-party package that is incompatible with PyMongo.

Dependencies

PyMongo supports CPython 3.9+ and PyPy3.10+.

Required dependencies:

Support for mongodb+srv:// URIs requires dnspython

Optional dependencies:

GSSAPI authentication requires pykerberos on Unix or WinKerberos on Windows. The correct dependency can be installed automatically along with PyMongo:

python -m pip install "pymongo[gssapi]"

MONGODB-AWS authentication requires pymongo-auth-aws:

python -m pip install "pymongo[aws]"

OCSP (Online Certificate Status Protocol) requires PyOpenSSL, requests, service_identity and may require certifi:

python -m pip install "pymongo[ocsp]"

Wire protocol compression with snappy requires python-snappy:

python -m pip install "pymongo[snappy]"

Wire protocol compression with zstandard requires zstandard:

python -m pip install "pymongo[zstd]"

Client-Side Field Level Encryption requires pymongocrypt and pymongo-auth-aws:

python -m pip install "pymongo[encryption]"

You can install all dependencies automatically with the following command:

python -m pip install "pymongo[gssapi,aws,ocsp,snappy,zstd,encryption]"

Examples

Here's a basic example (for more see the examples section of the docs):

>>> import pymongo
>>> client = pymongo.MongoClient("localhost", 27017)
>>> db = client.test
>>> db.name
'test'
>>> db.my_collection
Collection(Database(MongoClient('localhost', 27017), 'test'), 'my_collection')
>>> db.my_collection.insert_one({"x": 10}).inserted_id
ObjectId('4aba15ebe23f6b53b0000000')
>>> db.my_collection.insert_one({"x": 8}).inserted_id
ObjectId('4aba160ee23f6b543e000000')
>>> db.my_collection.insert_one({"x": 11}).inserted_id
ObjectId('4aba160ee23f6b543e000002')
>>> db.my_collection.find_one()
{'x': 10, '_id': ObjectId('4aba15ebe23f6b53b0000000')}
>>> for item in db.my_collection.find():
...     print(item["x"])
...
10
8
11
>>> db.my_collection.create_index("x")
'x_1'
>>> for item in db.my_collection.find().sort("x", pymongo.ASCENDING):
...     print(item["x"])
...
8
10
11
>>> [item["x"] for item in db.my_collection.find().limit(2).skip(1)]
[8, 11]

Documentation

Documentation is available at pymongo.readthedocs.io.

See the contributing guide for how to build the documentation.

Learning Resources

Testing

The easiest way to run the tests is to run the following from the repository root.

pip install -e ".[test]"
pytest

For more advanced testing scenarios, see the contributing guide.

4.13.0 May 14, 2025
4.13.0.dev0 May 14, 2025
4.12.1 Apr 29, 2025
4.12.0 Apr 08, 2025
4.11.3 Mar 18, 2025
4.11.2 Mar 03, 2025
4.11.1 Feb 10, 2025
4.11 Jan 28, 2025
4.10.1 Oct 01, 2024
4.10.0 Oct 01, 2024
4.9.2 Oct 02, 2024
4.9.1 Sep 18, 2024
4.9 Sep 18, 2024
4.8.0 Jun 26, 2024
4.8.0b0 Jun 25, 2024
4.7.3 Jun 04, 2024
4.7.2 May 07, 2024
4.7.1 Apr 30, 2024
4.7.0 Apr 24, 2024
4.6.3 Mar 28, 2024
4.6.2 Feb 21, 2024
4.6.1 Nov 29, 2023
4.6.0 Nov 01, 2023
4.5.0 Aug 22, 2023
4.4.1 Jul 13, 2023
4.4.0 Jun 21, 2023
4.4.0b0 Jan 25, 2023
4.3.3 Nov 17, 2022
4.3.2 Oct 18, 2022
4.2.0 Jul 20, 2022
4.1.1 Apr 13, 2022
4.1.0 Apr 04, 2022
4.0.2 Mar 03, 2022
4.0.1 Dec 07, 2021
4.0 Nov 29, 2021
3.13.0 Nov 01, 2022
3.12.3 Dec 07, 2021
3.12.2 Nov 29, 2021
3.12.1 Oct 19, 2021
3.12.0 Jul 13, 2021
3.11.4 May 04, 2021
3.11.3 Feb 03, 2021
3.11.2 Dec 02, 2020
3.11.1 Nov 17, 2020
3.11.0 Jul 30, 2020
3.10.1 Jan 08, 2020
3.10.0 Dec 10, 2019
3.9.0 Aug 14, 2019
3.8.0 Apr 22, 2019
3.7.2 Oct 10, 2018
3.7.1 Jul 16, 2018
3.7.0 Jun 26, 2018
3.6.1 Mar 01, 2018
3.6.0 Dec 05, 2017
3.5.1 Aug 23, 2017
3.5.0 Aug 08, 2017
3.4.0 Nov 29, 2016
3.3.1 Oct 27, 2016
3.3.0 Jul 12, 2016
3.2.2 Mar 15, 2016
3.2.1 Feb 02, 2016
3.2 Dec 08, 2015
3.1.1 Nov 18, 2015
3.1 Nov 02, 2015
3.0.3 Jul 01, 2015
3.0.2 May 12, 2015
3.0.1 Apr 21, 2015
3.0 Apr 07, 2015
2.9.5 Jun 30, 2017
2.9.4 Sep 30, 2016
2.9.3 Mar 15, 2016
2.9.2 Feb 01, 2016
2.9.1 Nov 17, 2015
2.9 Sep 30, 2015
2.8.1 May 11, 2015
2.8 Jan 28, 2015
2.7.2 Jul 29, 2014
2.7.1 May 23, 2014
2.7 Apr 03, 2014
2.6.3 Oct 11, 2013
2.6.2 Sep 06, 2013
2.6.1 Sep 04, 2013
2.6 Aug 19, 2013
2.5.2 Jun 01, 2013
2.5.1 May 13, 2013
2.5 Mar 22, 2013
2.4.2 Jan 24, 2013
2.4.1 Dec 06, 2012
2.4 Nov 27, 2012
2.3 Aug 29, 2012
2.2.1 Jul 06, 2012
2.2 Apr 30, 2012
2.1.1 Jan 05, 2012
2.1 Dec 07, 2011
2.0.1 Aug 16, 2011
2.0 Aug 06, 2011
1.11 May 06, 2011
1.10.1 Apr 07, 2011
1.10 Mar 30, 2011
1.9 Sep 28, 2010
1.8.1 Aug 13, 2010
1.8 Aug 05, 2010
1.7 Jun 17, 2010
1.6 Apr 14, 2010
1.5.2 Mar 31, 2010
1.5.1 Mar 17, 2010
1.5 Mar 10, 2010
1.4 Jan 27, 2010
1.3 Dec 16, 2009
1.2.1 Dec 10, 2009
1.2 Dec 09, 2009
1.1.2 Nov 23, 2009
1.1.1 Nov 14, 2009
1.1 Oct 21, 2009
1.0 Sep 30, 2009
0.16 Sep 16, 2009
0.15.2 Sep 09, 2009
0.15.1 Sep 03, 2009
0.15 Aug 26, 2009
0.14.2 Aug 24, 2009
0.14.1 Aug 21, 2009
0.14 Aug 19, 2009
0.13 Jul 29, 2009
0.12 Jul 08, 2009
0.11.3 Jun 18, 2009
0.11.2 Jun 08, 2009
0.11.1 Jun 04, 2009
0.11 Jun 03, 2009
0.10.3 May 27, 2009
0.10.2 May 22, 2009
0.10.1 May 18, 2009
0.10 May 14, 2009
0.9.7 May 13, 2009
0.9.6 May 08, 2009
0.9.5 Apr 15, 2009
0.9.4 Apr 15, 2009
0.9.3 Apr 03, 2009
0.9.2 Mar 26, 2009
0.9.1 Mar 18, 2009
0.9 Mar 17, 2009
0.8.1 Feb 27, 2009
0.8 Feb 20, 2009
0.7.2 Feb 20, 2009
0.7.1 Feb 20, 2009
0.7 Feb 17, 2009
0.6 Feb 11, 2009
0.5.3rc0 Feb 09, 2009
0.5.2rc0 Feb 06, 2009
0.5.1rc0 Feb 06, 2009
0.5rc0 Feb 05, 2009
0.4rc0 Feb 05, 2009
0.3.1rc0 Feb 03, 2009
0.3rc0 Jan 30, 2009
0.2rc0 Jan 27, 2009
0.1.2rc0 Jan 23, 2009
0.1.1rc0 Jan 23, 2009
0.1rc0 Jan 22, 2009
0.0rc0 Jan 22, 2009

Wheel compatibility matrix

Platform CPython 3.9 CPython 3.10 CPython 3.11 CPython 3.12 CPython 3.13 CPython (additional flags: t) 3.13
macosx_10_13_x86_64
macosx_10_9_x86_64
macosx_11_0_arm64
manylinux1_i686
manylinux1_x86_64
manylinux2014_aarch64
manylinux2014_i686
manylinux2014_ppc64le
manylinux2014_s390x
manylinux2014_x86_64
manylinux_2_17_aarch64
manylinux_2_17_i686
manylinux_2_17_ppc64le
manylinux_2_17_s390x
manylinux_2_17_x86_64
manylinux_2_5_i686
manylinux_2_5_x86_64
win32
win_amd64

Files in release

pymongo-4.13.0-cp310-cp310-macosx_10_9_x86_64.whl (783.7KiB)
pymongo-4.13.0-cp310-cp310-macosx_11_0_arm64.whl (784.0KiB)
pymongo-4.13.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1MiB)
pymongo-4.13.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.2MiB)
pymongo-4.13.0-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.1MiB)
pymongo-4.13.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1MiB)
pymongo-4.13.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.1MiB)
pymongo-4.13.0-cp310-cp310-win32.whl (770.1KiB)
pymongo-4.13.0-cp310-cp310-win_amd64.whl (779.2KiB)
pymongo-4.13.0-cp311-cp311-macosx_10_9_x86_64.whl (836.8KiB)
pymongo-4.13.0-cp311-cp311-macosx_11_0_arm64.whl (837.1KiB)
pymongo-4.13.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.4MiB)
pymongo-4.13.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.4MiB)
pymongo-4.13.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.4MiB)
pymongo-4.13.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4MiB)
pymongo-4.13.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.3MiB)
pymongo-4.13.0-cp311-cp311-win32.whl (814.6KiB)
pymongo-4.13.0-cp311-cp311-win_amd64.whl (828.2KiB)
pymongo-4.13.0-cp312-cp312-macosx_10_13_x86_64.whl (890.4KiB)
pymongo-4.13.0-cp312-cp312-macosx_11_0_arm64.whl (890.1KiB)
pymongo-4.13.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6MiB)
pymongo-4.13.0-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7MiB)
pymongo-4.13.0-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.6MiB)
pymongo-4.13.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6MiB)
pymongo-4.13.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.6MiB)
pymongo-4.13.0-cp312-cp312-win32.whl (859.9KiB)
pymongo-4.13.0-cp312-cp312-win_amd64.whl (877.7KiB)
pymongo-4.13.0-cp313-cp313-macosx_10_13_x86_64.whl (943.4KiB)
pymongo-4.13.0-cp313-cp313-macosx_11_0_arm64.whl (943.1KiB)
pymongo-4.13.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.9MiB)
pymongo-4.13.0-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.9MiB)
pymongo-4.13.0-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.9MiB)
pymongo-4.13.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9MiB)
pymongo-4.13.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (1.8MiB)
pymongo-4.13.0-cp313-cp313-win32.whl (905.1KiB)
pymongo-4.13.0-cp313-cp313-win_amd64.whl (927.1KiB)
pymongo-4.13.0-cp313-cp313t-macosx_10_13_x86_64.whl (998.5KiB)
pymongo-4.13.0-cp313-cp313t-macosx_11_0_arm64.whl (998.5KiB)
pymongo-4.13.0-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.2MiB)
pymongo-4.13.0-cp313-cp313t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.3MiB)
pymongo-4.13.0-cp313-cp313t-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.2MiB)
pymongo-4.13.0-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2MiB)
pymongo-4.13.0-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.1MiB)
pymongo-4.13.0-cp313-cp313t-win32.whl (952.8KiB)
pymongo-4.13.0-cp313-cp313t-win_amd64.whl (980.7KiB)
pymongo-4.13.0-cp39-cp39-macosx_10_9_x86_64.whl (730.6KiB)
pymongo-4.13.0-cp39-cp39-macosx_11_0_arm64.whl (730.9KiB)
pymongo-4.13.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (914.2KiB)
pymongo-4.13.0-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (931.1KiB)
pymongo-4.13.0-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl (923.0KiB)
pymongo-4.13.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (916.0KiB)
pymongo-4.13.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (905.9KiB)
pymongo-4.13.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl (889.6KiB)
pymongo-4.13.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl (915.3KiB)
pymongo-4.13.0-cp39-cp39-win32.whl (725.5KiB)
pymongo-4.13.0-cp39-cp39-win_amd64.whl (730.2KiB)
pymongo-4.13.0.tar.gz (2.1MiB)
Extras:
Dependencies:
dnspython (<3.0.0,>=1.16.0)