cosmodol.stores
Mapping stores over a Cosmos DB container.
Two store flavors — pick one based on whether you have a fixed partition key value or want to span the whole container:
CosmosItems— fixed partition; keys areidstrings; the simplest dict surface.CosmosPartitionedItems— whole container; keys are(pk_value, id)tuples.
See misc/docs/architecture.md Layer B and misc/docs/design_decisions.md §3.
- class cosmodol.stores.CosmosItems(container: ContainerProxy | dict | tuple, *, partition_key_value: Any, partition_key_path: str | None = None, connection: Any = None, inject_id: bool = True, inject_partition_key: bool = True, strict_keys: bool = True, strip_system_fields: bool = True, record_ru: Callable[[str, float], None] | None = None)[source]
MutableMapping[str, dict]over one fixed partition of a Cosmos container.Keys are item
idstrings; values are JSON-dict items. The store auto-injectsidand the partition-key property on writes.- Parameters:
container – An already-built
ContainerProxyor a(database, container)tuple /{"database": ..., "container": ...}dict to resolve viaconnection.partition_key_value – The single partition-key value this store is scoped to.
partition_key_path – Path of the partition-key property in items (e.g.
"/_pk","/id"). Read from the container if absent.connection –
CosmosConnection(or anythingfrom_anythingaccepts). Ignored ifcontaineris aContainerProxy.inject_id – If True, auto-inject
"id"into bodies on writes.inject_partition_key – If True, auto-inject the partition-key property into bodies.
strict_keys – Validate
idchars + length on writes.strip_system_fields – Strip
_etag/_ts/_rid/_self/_attachmentsfrom returned items.record_ru – Optional callback
(op_name, ru) -> Noneinvoked after each metal-layer op. Useful for Prometheus / logging.
- batch(operations: list[tuple]) list[dict][source]
Transactional batch within this partition. See
base.batch.
- class cosmodol.stores.CosmosPartitionedItems(container: ContainerProxy | dict | tuple, *, partition_key_path: str | None = None, connection: Any = None, inject_id: bool = True, inject_partition_key: bool = True, strict_keys: bool = True, strip_system_fields: bool = True, record_ru: Callable[[str, float], None] | None = None, len_via_query: bool = False, silent_full_scan: bool = False)[source]
MutableMapping[tuple[str, str], dict]over all partitions of a container.Keys are
(partition_key_value, id)tuples. UseCosmosItemsinstead if you have a fixed partition.Iteration is cross-partition; the first call emits a
UserWarning(silence withsilent_full_scan=True).__len__is not implemented by default; opt-in vialen_via_query=True. Seemisc/docs/design_decisions.md§§4, 6.- Parameters:
container – As in
CosmosItems.partition_key_path – Path of the partition-key property in items. Read from the container if absent.
connection – As in
CosmosItems.inject_id – As in
CosmosItems.inject_partition_key – As in
CosmosItems.strict_keys – As in
CosmosItems.strip_system_fields – As in
CosmosItems.record_ru – As in
CosmosItems.len_via_query – If True,
__len__runs a (cross-partition) COUNT query.silent_full_scan – If True,
__iter__does not emit the cross-partition warning.
- partition(pk_value) CosmosItems[source]
Narrow to a single partition; zero round-trips. Returns
CosmosItems.