|
| 1 | +# AGENTS.md - PyMongo (mongo-python-driver) |
| 2 | + |
| 3 | +## Overview |
| 4 | +Official Python driver for MongoDB. |
| 5 | + |
| 6 | +## Tech Stack |
| 7 | +- **Build/env:** `hatch` — use `hatch run test:test` and `hatch run test:test-async`, not `pytest` directly |
| 8 | +- **Task runner:** `just` (Justfile at repo root) |
| 9 | +- **Linter/formatter:** `ruff` via pre-commit |
| 10 | +- **Type checker:** `mypy` (strict) |
| 11 | +- **Docs:** Sphinx / reStructuredText; use Sphinx docstring format for all docstrings |
| 12 | + |
| 13 | +> **Never** run `pip install bson`. PyMongo ships its own `bson`; the PyPI `bson` package silently breaks things. |
| 14 | +
|
| 15 | +## Project Structure |
| 16 | +- `pymongo/synchronous/` — sync driver (MongoClient, Collection, Database, etc.) generated from `pymongo/asynchronous/` using unasync |
| 17 | +- `pymongo/asynchronous/` — async API, mirrors `pymongo/synchronous/` |
| 18 | +- `bson/` — BSON implementation |
| 19 | +- `gridfs/` — GridFS API |
| 20 | +- `test/` — sync test suite |
| 21 | +- `test/asynchronous/` — async test suite, mirrors `test/` |
| 22 | +- `test/unified_format/` — cross-driver spec tests (Unified Test Format) |
| 23 | +- `tools/convert_test_to_async.py` — generates async test stubs from sync tests |
| 24 | + |
| 25 | +## Commands |
| 26 | +```bash |
| 27 | +just install # set up venv + pre-commit hook |
| 28 | +just typing-mypy # type check |
| 29 | +just run lint-manual # ruff linter |
| 30 | + |
| 31 | +hatch run test:test # run sync tests |
| 32 | +hatch run test:test-async # run async tests |
| 33 | + |
| 34 | +MONGODB_VERSION=8.0 just run-server # start a local MongoDB server |
| 35 | +``` |
| 36 | + |
| 37 | +## Testing |
| 38 | +Tests require a live MongoDB server (`just run-server` above). |
| 39 | + |
| 40 | +Never modify pymongo/synchronous code first; update the async counterpart and run our `tools/synchro.py` script: |
| 41 | +1. Make changes in `pymongo/asynchronous` or top-level `pymongo/` files and `test/`. |
| 42 | +2. Run `tools/convert_test_to_async.py` on the sync test file to generate a starting-point async version. |
| 43 | +3. Manually complete the async version in `test/asynchronous/`. |
| 44 | + |
| 45 | +Do not edit files in `pymongo/synchronous/` or mirrored files in `test/` directly — they are auto-generated by `tools/synchro.py` from `pymongo/asynchronous/` and `test/asynchronous/`. Only edit them if the change includes a `_IS_SYNC` statement. |
| 46 | + |
| 47 | +Async functions must not call blocking I/O. |
| 48 | + |
| 49 | +New features need integration tests. Bug fixes need regression tests. |
| 50 | + |
| 51 | +## Commit and PR Conventions |
| 52 | +- Prefix commits and PR titles with the JIRA ticket: `PYTHON-1234 Fix retryable write on mongos` |
| 53 | +- Backport PRs: append the target branch in brackets — `PYTHON-1234 [v4.9] Fix retryable write` |
| 54 | +- Merge via **Squash and Merge** only |
| 55 | + |
| 56 | +See .github/copilot-instructions.md for more details. |
0 commit comments