mongomock
Fake pymongo stub for testing simple MongoDB-dependent code
Decision gist · record as of 2026-08-14
Yes. Mongomock is production-stable, widely used, has no known vulnerabilities, and solves a real testing problem with low install friction. The aging maintenance status is a minor concern but the repository remains active and the ISC license is permissive. Install it if you test pymongo-dependent code.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Low install friction: pure Python wheel with only three runtime dependencies (packaging, pytz, sentinels).
- Last release was 636 days ago; repository is active and not archived, though maintenance status is aging.
License · maintenance · safety
permissive license (permissive) — ISC License (permissive): you may use, modify, and distribute mongomock freely in commercial and private projects with minimal restrictions—only requiring preservation of copyright and license notices.
last release 2024-11-16 (636 days) · last repo commit 2025-06-30 · 1,003 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 7,923,784 downloads/mo, #1,680 on PyPI
Alternatives
Verify before relying
import mongomock
client = mongomock.MongoClient()
db = client.test_db
collection = db.test_collection
collection.insert_one({'name': 'test', 'value': 1})
result = collection.find_one({'name': 'test'})
print(result)- Completeness of MongoDB API coverage relative to pymongo v4—the description notes TDD-driven feature addition but does not enumerate which operations are supported.
- Whether the package works with pymongo v5 or later versions beyond v4.
- Monthly download volume and ranking position reflect current popularity but may not indicate active maintenance frequency.
What it is and what it does
Mongomock is a testing library that replaces pymongo's MongoClient with an in-memory mock, allowing you to test MongoDB-dependent code without setting up or managing a real MongoDB instance. It implements enough of the MongoDB API to behave like a real collection for typical query and update operations, making tests faster and more portable across CI environments and local machines.
The library is designed for functional testing rather than as a perfect replica of MongoDB. When a feature is not yet implemented, it raises NotImplementedError rather than silently behaving differently from production pymongo, ensuring your tests fail where production code would fail. It supports both direct instantiation (creating a mock client in your test) and decorator-based patching (intercepting pymongo.MongoClient calls in code under test).
Use it for
- Unit test code that queries and updates MongoDB collections without spinning up a test database.
- Run test suites in CI/CD pipelines where MongoDB infrastructure is unavailable or undesirable.
- Validate application logic against MongoDB operations in isolation, comparing expected vs. actual collection state.
- Migrate code from pymongo v3 to v4 by running tests against both versions to catch API incompatibilities early.
- Mock MongoDB interactions in decorator-patched functions that create their own pymongo connections.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
Mongomock is production-stable, widely used, has no known vulnerabilities, and solves a real testing problem with low install friction. The aging maintenance status is a minor concern but the repository remains active and the ISC license is permissive. Install it if you test pymongo-dependent code.
Install
mongomock on PyPI
Before you install
Low install friction: pure Python wheel with only three runtime dependencies (packaging, pytz, sentinels). Last release was 636 days ago; repository is active and not archived, though maintenance status is aging.
License in practice
ISC License (permissive): you may use, modify, and distribute mongomock freely in commercial and private projects with minimal restrictions—only requiring preservation of copyright and license notices.
Quickstart
import mongomock
client = mongomock.MongoClient()
db = client.test_db
collection = db.test_collection
collection.insert_one({'name': 'test', 'value': 1})
result = collection.find_one({'name': 'test'})
print(result)
Verify before relying
- Completeness of MongoDB API coverage relative to pymongo v4—the description notes TDD-driven feature addition but does not enumerate which operations are supported.
- Whether the package works with pymongo v5 or later versions beyond v4.
- Monthly download volume and ranking position reflect current popularity but may not indicate active maintenance frequency.
Package facts
| License | permissive license permissive |
| Python support | Not specified |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 3 packagespackagingpytzsentinels |
| Maintenance | Aging 636 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 7,923,784 / month, #1,680 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: ISC License (ISCL)Operating System :: MacOS :: MacOS XOperating System :: Microsoft :: WindowsOperating System :: POSIXProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Database |
Evidence: mongomock-4.3.0-py2.py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “pymongo test double”
- mongomockMongomock provides an in-memory mock of MongoDB collections for…
- pymongo_inmemoryProvides an in-memory MongoDB instance for testing by wrapping…
- mock-firestoreProvides an in-memory mock of the Google Cloud Firestore Python…
Give your agent the search over MCP, or paste the wish link into any chat.
More Database packages
psycopg2-binary is a PostgreSQL database adapter for Python that implements the DB API 2.0 specification, enabling Python applications to connect to and query PostgreSQL databases with thread-safe concurrent operations.
Python client library for connecting to and executing commands against Redis key-value stores, supporting both synchronous and asynchronous operations.
Install it if your application needs to interact with Redis; the only prerequisite is a running Redis server instance.
YDB Python SDK is the official client library for connecting to and querying YDB databases from Python applications.
Install it if you need to connect Python applications to YDB databases.
Connects Python applications to Snowflake data warehouses using the DB API 2.0 specification, enabling SQL queries, data transfers, and warehouse operations.
sqlparse tokenizes SQL text into a tree of statements, clauses, and expressions, and provides functions to split scripts, format queries, and inspect parsed tokens without validating dialect or syntax.
Install it if you need to manipulate, format, or analyze SQL text programmatically.
Provides base adapter protocols and shared functionality that database adapters use to integrate with dbt-core, handling connections, dialect translation, relation caching, and core interface management.
See also mongomock-motor · pymongo_inmemory · pymongo · pymongoexplain · Flask-PyMongo · pymongo-auth-aws · pymongo-search-utils · pymongocrypt · bson · pymongoarrow