pymongo_inmemory
A mongo mocking library with an ephemeral MongoDB running in memory.
What it is and what it does
pymongo_inmemory is a testing library that spins up an ephemeral MongoDB instance in memory, allowing you to test code that uses MongoDB without needing a separate MongoDB server running. It wraps pymongo's MongoClient and automatically handles downloading, extracting, and configuring a MongoDB binary for your OS and Python version. The instance runs only for the duration of your test and leaves no persistent state.
You configure it via setup.cfg or environment variables (setting things like MongoDB version, port, and data folder), then import MongoClient from pymongo_inmemory instead of pymongo. The API is identical to the standard pymongo client, so existing test code requires minimal changes. It caches downloaded MongoDB binaries to avoid repeated downloads, and supports MongoDB versions from 3.0 through 8.0 across Linux, macOS, and Windows.
Use it for:
- Unit testing code that reads/writes to MongoDB without needing a test database server running locally or in CI.
- Integration testing a multi-service application where MongoDB is one component, using an isolated in-memory instance per test.
- Rapid development iteration on MongoDB queries and schema changes without managing a persistent test database.
- CI/CD pipelines where spinning up a full MongoDB container is too heavy or slow; the in-memory instance starts faster.
- Testing edge cases and error conditions by configuring specific MongoDB versions or configurations via environment variables.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides an in-memory MongoDB instance for testing by wrapping pymongo's MongoClient, eliminating the need for a running MongoDB server during development and test runs.
Yes, if you test code that uses MongoDB and want to avoid external service dependencies. The low install friction, permissive license, and straightforward API make it a practical choice for unit and integration testing. The aging maintenance status (last release 519 days ago) is a minor concern but not a blocker—the repository is not archived and recent commits exist. No known security vulnerabilities.
Install
pymongo-inmemory on PyPI
pip
pip install pymongo-inmemoryuv
uv add pymongo-inmemorypoetry
poetry add pymongo-inmemoryInstalling pymongo_inmemory
Before you install
Low friction install with a single runtime dependency (pymongo). Maintenance status is aging—last release was 519 days ago, though the repository remains active with recent commits and no archived status. Supports current Python versions (3.9 through 3.13).
License in practice
MIT license is permissive, allowing use in commercial and private projects with minimal restrictions—only requiring attribution and inclusion of the license text.
Quickstart
pip install pymongo-inmemory
from pymongo_inmemory import MongoClient
with MongoClient() as client:
db = client['testdb']
collection = db['test-collection']
# use collection as normal
Requires Python 3.9 or later. The package downloads and runs a MongoDB binary, so adequate disk space and network access during first run are needed.
Verify before relying
- Whether the package successfully handles all MongoDB versions listed in its URL bank or if some versions have known issues.
- Performance characteristics and memory overhead of the in-memory MongoDB instance for large test datasets.
- Compatibility with all pymongo features or limitations in what MongoClient operations are supported.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (<4.0,>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — pymongo |
| Maintenance | aging — 519 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 117,381/month — #12,165 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pymongo_inmemory-0.5.0-py3-none-any.whl
Keywords: mongodb, testing, pymongo
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pymongoPyMongo is the official MongoDB Python driver,…
permissive · top 1,000 on PyPI
mongomockMongomock provides an in-memory mock of MongoDB…
permissive · top 5,000 on PyPI
Flask-PyMongoFlask-PyMongo integrates MongoDB database…
permissive · top 15,000 on PyPI
pymongoarrowPyMongoArrow converts MongoDB query results…
permissive · top 15,000 on PyPI
pymongocryptPyMongoCrypt provides Python bindings for…
permissive · top 5,000 on PyPI
pymongo-auth-awsEnables PyMongo to authenticate to MongoDB…
permissive · top 5,000 on PyPI
motorMotor provides a non-blocking MongoDB driver…
permissive · top 5,000 on PyPI
pydantic-mongoProvides a Repository pattern for MongoDB with…
permissive · top 15,000 on PyPI
gdbmongoGdbmongo provides GDB pretty printers and…
permissive · top 5,000 on PyPI
pymongoexplainWraps PyMongo's Collection class to explain…
permissive · top 15,000 on PyPI