Package: pymongo
Info:Seethe mongo sitefor more information. SeeGitHubfor the latest source.Documentation:Available atpymongo.readthedocs.ioAuthor:The MongoDB Python TeamAboutThe PyMongo distribution contains tools for interacting with MongoDB
database from Python.  Thebsonpackage is an implementation of
theBSON formatfor Python. Thepymongopackage is a native Python driver for MongoDB. Thegridfspackage
is agridfsimplementation on top ofpymongo.PyMongo supports MongoDB 3.6, 4.0, 4.2, 4.4, 5.0, 6.0, and 7.0.Support / FeedbackFor issues with, questions about, or feedback for PyMongo, please look into
oursupport channels. Please
do not email any of the PyMongo developers directly with issues or
questions - you’re more likely to get an answer onStackOverflow(using a “mongodb” tag).Bugs / Feature RequestsThink you’ve found a bug? Want to see a new feature in PyMongo? Please open a
case in our issue management tool, JIRA:Create an account and login.Navigate tothe PYTHON project.ClickCreate Issue- Please provide as much information as possible about the issue type and how to reproduce it.Bug reports in JIRA for all driver projects (i.e. PYTHON, CSHARP, JAVA) and the
Core Server (i.e. SERVER) project arepublic.How To Ask For HelpPlease 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 VulnerabilitiesIf you’ve identified a security vulnerability in a driver or any other
MongoDB project, please report it according to theinstructions here.InstallationPyMongo can be installed withpip:$ python -m pip install pymongoOreasy_installfromsetuptools:$ python -m easy_install pymongoYou can also download the project source and do:$ pip install .Donotinstall the “bson” package from pypi. PyMongo comes with its own
bson package; doing “easy_install bson” installs a third-party package that
is incompatible with PyMongo.DependenciesPyMongo supports CPython 3.7+ and PyPy3.7+.Required dependencies:Support for mongodb+srv:// URIs requiresdnspythonOptional dependencies:GSSAPI authentication requirespykerberoson Unix orWinKerberoson Windows. The correct
dependency can be installed automatically along with PyMongo:$ python -m pip install "pymongo[gssapi]"MONGODB-AWS authentication requirespymongo-auth-aws:$ python -m pip install "pymongo[aws]"OCSP (Online Certificate Status Protocol) requiresPyOpenSSL,requests,service_identityand may
requirecertifi:$ python -m pip install "pymongo[ocsp]"Wire protocol compression with snappy requirespython-snappy:$ python -m pip install "pymongo[snappy]"Wire protocol compression with zstandard requireszstandard:$ python -m pip install "pymongo[zstd]"Client-Side Field Level Encryption requirespymongocryptandpymongo-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]"Additional dependencies are:(to generate documentation or run tests)toxExamplesHere’s a basic example (for more see theexamplessection of the docs):>>>importpymongo>>>client=pymongo.MongoClient("localhost",27017)>>>db=client.test>>>db.name'test'>>>db.my_collectionCollection(Database(MongoClient('localhost', 27017), 'test'), 'my_collection')>>>db.my_collection.insert_one({"x":10}).inserted_idObjectId('4aba15ebe23f6b53b0000000')>>>db.my_collection.insert_one({"x":8}).inserted_idObjectId('4aba160ee23f6b543e000000')>>>db.my_collection.insert_one({"x":11}).inserted_idObjectId('4aba160ee23f6b543e000002')>>>db.my_collection.find_one(){'x': 10, '_id': ObjectId('4aba15ebe23f6b53b0000000')}>>>foritemindb.my_collection.find():...print(item["x"])...10
8
11>>>db.my_collection.create_index("x")'x_1'>>>foritemindb.my_collection.find().sort("x",pymongo.ASCENDING):...print(item["x"])...8
10
11>>>[item["x"]foritemindb.my_collection.find().limit(2).skip(1)][8, 11]DocumentationDocumentation is available atpymongo.readthedocs.io.Documentation can be generated by runningtox -m doc. Generated documentation can be found in thedoc/build/html/directory.Learning ResourcesMongoDB Learn -Python courses.Python Articles on Developer Center.TestingThe easiest way to run the tests is to runtox -m testin
the root of the distribution.To verify that PyMongo works with Gevent’s monkey-patching:$ python green_framework_test.py geventOr with Eventlet’s:$ python green_framework_test.py eventlet