- Notifications
You must be signed in to change notification settings - Fork1.1k
PyMongo - the Official MongoDB Python driver
License
mongodb/mongo-python-driver
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
The PyMongo distribution contains tools for interacting with MongoDBdatabase from Python. Thebson
package is an implementation of theBSON format for Python. Thepymongo
package isa native Python driver for MongoDB, offering both synchronous and asynchronous APIs. Thegridfs
package is agridfsimplementation on top ofpymongo
.
PyMongo supports MongoDB 4.0, 4.2, 4.4, 5.0, 6.0, 7.0, and 8.0.
For issues with, questions about, or feedback for PyMongo, please lookinto oursupport channels. Pleasedo not email any of the PyMongo developers directly with issues orquestions - you're more likely to get an answer onStackOverflow(using a "mongodb" tag).
Think you've found a bug? Want to see a new feature in PyMongo? Pleaseopen a case in our issue management tool, JIRA:
- Create an account and login.
- Navigate tothe PYTHONproject.
- ClickCreate Issue - Please provide as much information aspossible 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.
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, withversion (e.g. Django 1.7, mod_wsgi 4.3.0, gevent 1.0.1, Tornado4.0.2, ...)
If you've identified a security vulnerability in a driver or any otherMongoDB project, please report it according to theinstructionshere.
PyMongo can be installed withpip:
python -m pip install pymongo
You can also download the project source and do:
pip install.
Donot install the "bson" package from pypi. PyMongo comes withits own bson package; running "pip install bson" installs a third-partypackage that is incompatible with PyMongo.
PyMongo supports CPython 3.9+ and PyPy3.10+.
Required dependencies:
Support formongodb+srv://
URIs requiresdnspython
Optional dependencies:
GSSAPI authentication requirespykerberos on Unix orWinKerberos on Windows. Thecorrect 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_identity and mayrequirecertifi:
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 requirespymongocrypt andpymongo-auth-aws:
python -m pip install"pymongo[encryption]"
You can install all dependencies automatically with the followingcommand:
python -m pip install"pymongo[gssapi,aws,ocsp,snappy,zstd,encryption]"
Here's a basic example (for more see theexamples section of thedocs):
>>>import pymongo>>> 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')}>>>for itemin db.my_collection.find():...print(item["x"])...10811>>> db.my_collection.create_index("x")'x_1'>>>for itemin db.my_collection.find().sort("x", pymongo.ASCENDING):...print(item["x"])...81011>>> [item["x"]for itemin db.my_collection.find().limit(2).skip(1)][8, 11]
Documentation is available atpymongo.readthedocs.io.
See thecontributing guide for how to build the documentation.
- MongoDB Learn -Pythoncourses.
- Python Articles on DeveloperCenter.
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 thecontributing guide.
About
PyMongo - the Official MongoDB Python driver
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.