Skip to main content

MongoDB DocumentStorePort adapter for muscles-data

Project description

muscles-data-mongodb

MongoDB adapter package for muscles-data.

This package is intentionally separate from muscles-data: the core package owns typed ports and runtime, while this package owns the PyMongo-backed DocumentStorePort adapter.

Related packages

Install

python -m pip install muscles-data-mongodb

For local framework development:

PYTHONPATH=../muscles-data/src:src python3 -m pytest -q

Configuration

data:
  resources:
    mongo.content:
      type: mongodb
      url: ${MONGO_URL}
      database: content
      timeout: 3
      max_limit: 100

Usage

Register the external factory in the project composition root:

from muscles_data.catalog import DataAdapterCatalog
from muscles_data.config import DataConfig
from muscles_data.ports import DocumentStorePort
from muscles_data.runtime import DataRuntime
from muscles_data_mongodb import MongoDocumentStoreFactory

catalog = DataAdapterCatalog.with_defaults()
catalog.register(MongoDocumentStoreFactory())

runtime = DataRuntime(config=DataConfig.from_raw(config), catalog=catalog)
store = runtime.require_port("mongo.content", DocumentStorePort)

Then use the narrow port:

store.upsert_document("profiles", "denis", {"name": "Denis"})
document = store.get_document("profiles", "denis")
documents = store.find_documents("profiles", filters={"role": "developer"}, limit=20)
store.delete_document("profiles", "denis")

The adapter maps document_id to MongoDB _id internally and returns public documents without _id to keep the port backend-neutral.

Capabilities

MongoDocumentStoreFactory provides:

  • document_store;
  • healthcheck;
  • native_client only when the resource declares native_client: true.

Native access is an advanced project escape hatch:

from muscles_data import DataCapability

client = runtime.require_resource("mongo.content", DataCapability.NATIVE_CLIENT).native_client()

Use the native client for backend-specific aggregations, indexes or operations that do not belong in DocumentStorePort.

Boundaries

This package owns:

  • lazy PyMongo client creation;
  • database binding;
  • simple document get/find/upsert/delete;
  • safe inspect() and doctor();
  • bounded find_documents() limits.

It does not own:

  • ORM/document model layers;
  • schema validation;
  • migrations;
  • complex aggregation abstraction;
  • business repository APIs.

data.doctor performs a MongoDB ping. data.resources.list and package initialization do not open a MongoDB connection.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

muscles_data_mongodb-0.1.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

muscles_data_mongodb-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file muscles_data_mongodb-0.1.0.tar.gz.

File metadata

  • Download URL: muscles_data_mongodb-0.1.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for muscles_data_mongodb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 65cde0c66f1ff4ed620f1a81e0e014efab53864e16553b1af03ff3a3aa287b7b
MD5 31e66ba29f8917f181185134bb0c1564
BLAKE2b-256 3dfde9472c72c575da96b44b9148e7fb358f227a059881f906c2193a9316364a

See more details on using hashes here.

Provenance

The following attestation bundles were made for muscles_data_mongodb-0.1.0.tar.gz:

Publisher: release.yml on butkoden/muscles-data-mongodb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file muscles_data_mongodb-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for muscles_data_mongodb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7022a20d7dd4216d5e6117e21f928acb4ffe73297a4e66fd7148dd9cf8cfa001
MD5 53df7661c8bbf1d6996a8de07a086aaa
BLAKE2b-256 434dabaf48f51d47e3e12e09655b1a14d1896ff3d281285f7b054c2a535d0e8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for muscles_data_mongodb-0.1.0-py3-none-any.whl:

Publisher: release.yml on butkoden/muscles-data-mongodb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page