Skip to main content

Mongoeco

Local MongoDB testing and embedded persistence for Python, with PyMongo-style sync and async APIs.

Test application queries and writes locally, using a fresh in-memory database or SQLite. Start with the direct Python API, or keep real PyMongo clients and point them at an isolated local server with the optional pytest kit.

5.0.0 is being prepared; it has not been published yet. It aligns BSON, queries, writes and cursor behavior with the retained MongoDB dialects, adds an explicit optional PCRE2 backend and preferred bucket boundaries, and adopts CXP catalog 2.0.0. Read the migration guide and candidate release notes before upgrading. The pytest kit remains available since 4.10.0; wire diagnostics require 4.11.0 or later.

Install and try it

python -m pip install mongoeco
from mongoeco import MongoClient

with MongoClient() as client:
    users = client.demo.users
    users.insert_one({"_id": "ada", "name": "Ada"})
    assert users.find_one({"_id": "ada"})["name"] == "Ada"

The default engine is in memory. Mongoeco 5.0 supports CPython 3.13, 3.14 and 3.15, with Python 3.13 support through October 2028. See the support policy.

Test an application that uses MongoDB

If your application already accepts a database client or connection URI, start by changing that test fixture. Keep its queries, writes and assertions, then run the operations your application actually uses against both local engines.

Keep real PyMongo clients with pytest

Install Mongoeco 4.10 or later with the pytest extra:

python -m pip install "mongoeco[pytest]>=4.10"

Load the plugin explicitly in your root conftest.py:

pytest_plugins = ("mongoeco.pytest_plugin",)

Then use a managed, real pymongo.MongoClient in a test:

def test_create_user(mongoeco_client):
    users = mongoeco_client.app.users
    users.insert_one({"_id": "ada", "name": "Ada"})
    assert users.count_documents({}) == 1
python -m pytest --mongoeco-backend=both

Each test gets its own server, dynamic port and engine. The kit closes its clients and server and removes temporary SQLite files, including after failures. both runs only tests that depend on the kit against Memory and SQLite. To preserve your own client constructor and options, consume mongoeco_uri in your existing fixture instead.

For native async clients, install your runner and load its adapter:

python -m pip install "mongoeco[pytest]>=4.10" "pytest-asyncio>=1.4,<2"
# conftest.py: use this adapter instead of mongoeco.pytest_plugin
pytest_plugins = ("mongoeco.pytest_asyncio",)
import pytest

@pytest.mark.asyncio
async def test_create_user(mongoeco_async_client):
    users = mongoeco_async_client.app.users
    await users.insert_one({"_id": "ada", "name": "Ada"})
    assert await users.count_documents({}) == 1

An AnyIO adapter is also available for the asyncio backend. The pytest guide covers runners, options, ownership and parallel execution with pytest-xdist.

Use the direct async API

The base package also provides its own async client without a wire server:

import asyncio
from mongoeco import AsyncMongoClient

async def main():
    async with AsyncMongoClient() as client:
        await client.demo.users.insert_one({"_id": "ada", "name": "Ada"})
        assert await client.demo.users.count_documents({}) == 1

asyncio.run(main())

Coming from mongomock? Follow the migration guide for client injection, preserving PyMongo imports and testing one application path first. The application testing guide shows a complete fixture and application function.

Verified compatibility and limits

Mongoeco's regression corpus compares observable results with captured MongoDB 7.0.43, 8.0.32 and 9.0.2 results. It checks BSON types, error codes, write counters and partial effects through sync/async APIs and Memory/SQLite. Examples covered in 4.10 include:

Application operation Verified behavior Evidence and coverage
insert_many(..., ordered=True/False) with an invalid document or duplicate Preserve successful writes, original error indices, duplicate code 11000 and nInserted; continue later independent writes only when unordered Write corpus
Positional update on a field that contains a number instead of an array Reject the update without applying its other changes to that document Positional regression cases
Failed inserts and bulk models Preserve writeErrors[].op, BSON values and partial counts Error payload regressions

The compatibility guide and dialect guide define the supported subset. MongoDB dialect and PyMongo API profile are separate choices; defaults remain MongoDB 7.0 and PyMongo 4.9. The pytest acceptance report records the installed-wheel matrix, failure cleanup and anonymous consumer canary.

Use MongoDB integration tests for replication, sharding, server failover, network retry behavior, distributed transactions and Atlas-specific behavior. Local sessions, change streams and search have their own documented limits. The finite regression corpus does not establish universal MongoDB or PyMongo compatibility. See the comparison guide when choosing which tests to run locally and which to keep on a real server.

Keep data on disk without running a database service:

from mongoeco import MongoClient
from mongoeco.engines import SQLiteEngine

with MongoClient(SQLiteEngine("app.db")) as client:
    client.app.todos.update_one(
        {"_id": "ship"}, {"$set": {"done": False}}, upsert=True
    )
    assert client.app.todos.find_one({"_id": "ship"})["done"] is False

The local runtime supports aggregation, classic $text, a documented $search subset and ANN-backed $vectorSearch. explain() reports candidate selection, residual filtering and fallback behavior. This is local search, with its own ranking and supported operators; it does not establish Atlas Search parity.

Documentation and development

Start at the documentation index. Advanced topics have their own guides:

Mongoeco is a PEP 561 typed package. The documented public API and engine SPI v2 are supported contracts; see deprecations and migrations for version-specific changes. The engine SPI decision keeps v2 and shelves v3; no engine migration is planned for the next release.

License

Apache License 2.0. Bundled resources and adapted numerical algorithms retain their ICU notice and Intel BSD notice.

Metadata

Release files for mongoeco 5.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mongoeco 5.0.0
File Size Uploaded Provenance Actions
mongoeco-5.0.0.tar.gz 1.2 MB With provenance Details for mongoeco-5.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mongoeco 5.0.0
File Interpreter ABI Platform Actions
mongoeco-5.0.0-py3-none-any.whl Python 3 none any Details for mongoeco-5.0.0-py3-none-any.whl

Total release size: 2.4 MB

Release files / mongoeco-5.0.0.tar.gz

Download URL mongoeco-5.0.0.tar.gz
Size 1.2 MB
Tags Source
SHA-256 checksum
How to use checksums
9e9e28a60b8652a5434fe41c0096e23b8e3e3c7376c4fc4200e54957441fd4f6
BLAKE2b-256 checksum
How to use checksums
3fb7dd6d099ddb779bfaec535110b6c2fbc3d3ea623f8ef8a955c9b0ca6ce188
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 Nov 3, 2026.

Transparency log

Release files / mongoeco-5.0.0-py3-none-any.whl

Download URL mongoeco-5.0.0-py3-none-any.whl
Size 1.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
45340e8e9ee53f86ea3b1ffdf26ae295ee8e701dbbaae4cc227080097feaf372
BLAKE2b-256 checksum
How to use checksums
57474bd69e9580f877925e624eb1ab9a6c272ea6f74162f534f1839f81df2aa3
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 Nov 3, 2026.

Transparency log

Security for mongoeco 5.0.0

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mongoeco-5.0.0.tar.gz

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 Nov 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

5.0.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page