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.1.tar.gz (8.4 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.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: muscles_data_mongodb-0.1.1.tar.gz
  • Upload date:
  • Size: 8.4 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.1.tar.gz
Algorithm Hash digest
SHA256 bd6102c92829c3f76aa3b6dbb4b4cb684a418c0623dabc7e9604bf293276eb2c
MD5 38aa2d970a02df154cbfe841bbc0ea20
BLAKE2b-256 22906869eca5948400a3412abbea6e0ff77d0b8c7b7378909a5fb6efed5719f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for muscles_data_mongodb-0.1.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for muscles_data_mongodb-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 602f0253ef375613cbd200ddf9a948ef716526c3ec2f237c6013d37c0067719f
MD5 83a9c50571e772a2d71d726d59ef82ab
BLAKE2b-256 83523f1a2779b7d629e774a7e49b8f11eb1da6dfeb400fad7f8a1251c041a36a

See more details on using hashes here.

Provenance

The following attestation bundles were made for muscles_data_mongodb-0.1.1-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