skillfed

pymongo_inmemory

A mongo mocking library with an ephemeral MongoDB running in memory.

pymongo-inmemory v0.5.0 117.4K downloads/30d#12,165 on PyPI53
Permissive license MIT AGING released

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-inmemory

uv

uv add pymongo-inmemory

poetry

poetry add pymongo-inmemory

Installing 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

Development Status :: 3 - AlphaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: MacOS :: MacOS XOperating System :: Microsoft :: WindowsOperating System :: POSIX :: LinuxProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.7Programming Language :: Python :: 3.9Topic :: Database :: Database Engines/ServersTopic :: Software Development :: TestingTopic :: Utilities

Tags

mongodb mocking for testsin-memory mongo databasepymongo testing libraryephemeral mongodb instancemongodb test fixturemongo mock servertesting without mongodb server
mongodb-testingtest-fixturesmocking

More Utilities packages