PyMongo connects Python programs to MongoDB with sync and async APIs, BSON support, and an optional GridFS package. Install with pip; do not install the separate pypi bson package.
Overview
PyMongo is MongoDB’s recommended Python distribution for working with MongoDB. It includes pymongo as the native driver with synchronous and asynchronous APIs, bson for BSON encoding, and gridfs for GridFS storage on top of pymongo. Documentation and API references are hosted on mongodb.com and readthedocs.
Guides cover installation, connections, databases and collections, CRUD, aggregation, specialized data formats, indexes, database commands, MongoDB Search, MongoDB Vector Search, logging, monitoring, and authentication mechanisms. Django MongoDB Backend is noted as generally available for connecting Django applications to MongoDB.
Optional dependencies extend authentication, compression, OCSP, client-side field level encryption, and mongodb+srv URI handling. CPython 3.11 and newer is supported. PyMongo ships its own bson module; installing the unrelated bson package from PyPI is incompatible.
Issues and questions are handled through MongoDB’s public support channels rather than direct email to maintainers. Semantic versioning applies to releases.
Key features
- Synchronous and asynchronous APIs
- BSON package included
- GridFS implementation
- CRUD and aggregation
- Optional wire protocol compression
- Client-side field level encryption support
- MongoDB Search and vector search
- mongodb+srv URI support with dnspython
Use cases
- Python apps using MongoDB
- Async network frameworks with PyMongo
- Storing large files via GridFS
- Django apps via MongoDB backend
- Encrypted or compressed MongoDB connections