This release is a pre-release and may not be stable for production use.
fastapi-pymongo
FastAPI integration for PyMongo:
PyObjectId: Pydantic-nativeObjectId. Validates and serializes to a string, correct OpenAPI/JSON schema.MongoSettings:pydantic-settingsbase class for Mongo URI and database name. Subclass to add app settings.mongo_lifespan/get_client/get_database: client lifecycle wired to FastAPI'slifespan, exposed viaDepends().beanie_lifespan(optional,fastapi-pymongo[beanie]): runs Beanie'sinit_beaniealongside the rest offastapi_pymongo, for an ODM on top.
Install
pip install -e ".[dev]"
Examples
examples/quickstart: minimal CRUD app, raw PyMongo.examples/beanie: same CRUD app on Beanie. Verified against a real MongoDB instance (create/list/get/delete).
Development
pip install -e ".[dev]"
pytest
Documentation
Sphinx docs (furo theme) under docs/source:
pip install -e ".[docs]"
sphinx-build -b html docs/source docs/build
open docs/build/index.html
References
- INTPYTHON-1087: [SPIKE] FastAPI integration library for MongoDB. This repo is the prototype. DoD answers:
- Minimum setup?
AsyncMongoClientvia FastAPIlifespanandDepends(). Seemongo_lifespan/get_client/get_database,examples/quickstart. - Leverage FastAPI/Pydantic?
_idisn't a valid Python field name or a Pydantic/JSON-native type.PyObjectIdfixes serialization and schema.MongoSettingsreuses the same model pattern for config. - Thin wrapper feasible? Yes. Built and tested:
PyObjectId,MongoSettings,mongo_lifespan/get_client/get_database. - Quickstart CRUD prototype? Done.
examples/quickstart. - Packaging? Name
fastapi-pymongo, available on PyPI. - Beanie boundary? No first-party ODM. See
docs/source/reference.rstfor why (MongoDB's PyMODM precedent was paused and archived).beanie_lifespanruns Beanie'sinit_beaniealongside this package for anyone who wants one. Seeexamples/beanie, verified against real MongoDB.PyObjectIddoesn't apply to Beanie models. - Client metadata? Set at client construction via
AsyncMongoClient(uri, driver=DriverInfo(name="fastapi-pymongo", version=...))inmongo_lifespan/beanie_lifespan. Verified against a real server ($currentOp.clientMetadata.driver.name). PyMongo'sclient.append_metadata(...)for an already-open client does not reliably reach the server, filed as PYTHON-6130; don't rely on it. - Cost estimate? Open item.
- Minimum setup?
- INTPYTHON-382: [FastAPI] Update full stack fastapi template to match modern repo. Blocked. The official-template gap this package is an alternative path around.
- INTPYTHON-565: CF: Django MongoDB Backend and Django Ninja support. Backlog. The Django-side precedent for a Pydantic-schema integration.
- PYTHON-3372: Alt to full-stack-fastapi-postgresql. Epic, dev complete.
- PYTHON-5543: pymongo 4.15+fastapi fails to connect to replicaset. Closed.
Metadata
Release files for fastapi-pymongo 0.1.0a0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fastapi_pymongo-0.1.0a0.tar.gz | 12.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastapi_pymongo-0.1.0a0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.5 kB
Release files / fastapi_pymongo-0.1.0a0.tar.gz
| Download URL | fastapi_pymongo-0.1.0a0.tar.gz |
|---|---|
| Size | 12.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f3add5f37cebfbab2181bcc96185e05c6d5ceb9145235a218339538e8f09be9
|
|
BLAKE2b-256 checksum How to use checksums |
e11bfa6d84a5aadcec2899319601d63977b66feeea8022cd5ff46c3cee806a26
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.
Transparency logRelease files / fastapi_pymongo-0.1.0a0-py3-none-any.whl
| Download URL | fastapi_pymongo-0.1.0a0-py3-none-any.whl |
|---|---|
| Size | 12.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3198b7e85b3244c85099df52892b06b5acf0ac87bde194b8eeb2bbb13f5c716c
|
|
BLAKE2b-256 checksum How to use checksums |
2023f0df582bc6c7127cf887c51254a4a3b66dcfefd1348b3e26fb69caa3dab8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.
Transparency log