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.

4.10.1 corrects command and write error details, validation timing and BSON preservation. See the release notes for changes, compatibility limits and validation. The pytest kit is available since 4.10.0.

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 4.10 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.

License

Apache License 2.0.

Metadata

Release files for mongoeco 4.10.1

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 4.10.1
File Size Uploaded
mongoeco-4.10.1.tar.gz 1.1 MB Details

Built distribution (wheel)

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

Total release size: 2.2 MB

Release files / mongoeco-4.10.1.tar.gz

Download URL mongoeco-4.10.1.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
15b62fffe166247ae5bd7e9c7d69bb290030a9afe53811f11eb4a4b5a9716c2b
BLAKE2b-256 checksum
How to use checksums
1bf925683c40eecd360a01654c15a6e91a2ae558ac0ad3cc998e74dedd62a30f
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 16, 2026.

Transparency log

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

Download URL mongoeco-4.10.1-py3-none-any.whl
Size 1.1 MB
Tags Python 3
SHA-256 checksum
How to use checksums
0b4419ec41777a2914e1a331473c5bc2dc3e9770c31a61061b894d89135a7ddd
BLAKE2b-256 checksum
How to use checksums
3b057d0e358ec2d3cbc313941d4d94a7a93ebde491a964bfa0c0402327f27b97
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 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

4.10.1 This release

2 release files

4.10.0

2 release files

4.9.1

2 release files

4.9.0

2 release files

4.8.1

2 release files

4.8.0

2 release files

4.7.0

2 release files

4.6.1

2 release files

4.6.0

2 release files

4.5.0

2 release files

4.4.0

2 release files

4.3.0

2 release files

4.2.1

2 release files

4.2.0

2 release files

4.1.1

2 release files

4.1.0

2 release files

4.0.0

2 release files

3.6.0

2 release files

3.5.1

2 release files

3.5.0

2 release files

3.4.0

2 release files

3.3.0

2 release files

3.2.0

2 release files

3.1.0

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

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