Skip to main content

CI

kv-dict

KV backed dictionary, similar to RedisJSONDict

Install Package

  • pip: pip install kv-dict
  • uv: uv add kv-dict
    • add --optional FEATURE to add as an optional dependency
  • pixi: pixi add --pypi kv-dict
    • add --feature FEATURE to add as an optional dependency

Development

This project uses uv for managing project dependencies. Installation instructions may be found here.

git clone https://github.com/Canadian-Light-Source/kv-dict.git
cd kv-dict
uv sync --all-extras

Remote Mapping + In-Memory Backend Example

Run a basic RemoteKVMapping flow backed by InMemoryAsyncBackend:

uv run python examples/remote_mapping_in_memory_example.py

Remote Mapping + Redis/Dragonfly Backend Example

Run a basic RemoteKVMapping flow backed by a Redis-compatible server:

uv run python examples/remote_mapping_redis_example.py

[!NOTE] In the devcontainer compose setup, the Redis-compatible service hostname is redis.

Remote Mapping + PostgreSQL Backend Example

Run a basic RemoteKVMapping flow backed by PostgreSQL:

uv run python examples/remote_mapping_postgres_example.py

[!NOTE] In the devcontainer compose setup, PostgreSQL is available on the internal hostname/port postgres:5432.

Remote Mapping + NATS JetStream KV Backend Example

Run a basic RemoteKVMapping flow backed by NATS JetStream KV:

uv run python examples/remote_mapping_nats_example.py

[!IMPORTANT] This example uses create_bucket=False (production-style). Ensure the kv_dict bucket already exists.

[!NOTE] In the devcontainer compose setup, NATS is also available to host-side tools at nats://127.0.0.1:14222.

Watch the changes in the NATS KV with the CLI client:

nats -s localhost:14222 kv watch kv_dict
Create the kv_dict bucket locally (for testing)

Run this once before executing the NATS example:

uv run python - <<'PY'
import asyncio
import nats


async def main() -> None:
  nc = await nats.connect(servers=["nats://nats:4222"])
  try:
    js = nc.jetstream()
    try:
      await js.key_value("kv_dict")
      print("Bucket already exists: kv_dict")
    except Exception:
      await js.create_key_value(bucket="kv_dict")
      print("Created bucket: kv_dict")
  finally:
    await nc.close()


asyncio.run(main())
PY

Differences from Python dict

RemoteKVMapping is intentionally dict-like, but not a byte-for-byte replacement of the built-in dict behavior.

Key behavioral differences

  • Iteration order is sorted by key, not insertion order.
  • Values are persisted through backend round-trips, so operations are not purely in-memory.
  • Nested dict and list mutations are write-through.
  • Mutable non-dict/non-list values are not automatically write-through.

Missing / non-parity APIs

  • fromkeys() is not implemented.

Practical guidance

[!WARNING] RemoteKVMapping is backend-backed, not purely in-memory. Avoid relying on insertion-order behavior and reassignment-free updates for mutable non-list, non-dict nested values.

  • Treat this mapping as a backend-backed structure, not an in-memory object.
  • For nested non-dict updates, reassign the modified value to persist changes.
  • If strict insertion-order semantics are required, do not rely on iteration order from RemoteKVMapping.

Dict parity roadmap

  • Implement copy() semantics for backend-backed snapshots.
  • Implement in-place dict union operator (|=).
  • Implement dict union operator (|).
  • Implement fromkeys() with explicit persistence semantics.
  • Add write-through wrappers for list operations.
  • Add write-through wrappers for additional mutable container types (if required).
  • Decide and document stable ordering strategy (sorted vs insertion-order).
  • Add dedicated parity tests against a reference dict behavior matrix.

Metadata

Release files for kv-dict 0.2.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 kv-dict 0.2.0
File Size Uploaded Provenance Actions
kv_dict-0.2.0.tar.gz 104.1 kB Without provenance Details for kv_dict-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kv-dict 0.2.0
File Interpreter ABI Platform Actions
kv_dict-0.2.0-py3-none-any.whl Python 3 none any Details for kv_dict-0.2.0-py3-none-any.whl

Total release size: 131.7 kB

Release files / kv_dict-0.2.0.tar.gz

Download URL kv_dict-0.2.0.tar.gz
Size 104.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ce5d3eacfb00c1f18ddf9f9687b9c6479e52ed0710e0b56306d530a391a06cb6
BLAKE2b-256 checksum
How to use checksums
a0e1ef2419946805aee26ce013e570ce9a7c8641bd45de2f18a95357613d7cd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / kv_dict-0.2.0-py3-none-any.whl

Download URL kv_dict-0.2.0-py3-none-any.whl
Size 27.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
09baf452700cdc85c5d6023de9bfc48d92a7a139be1247e0f41152995b74cc71
BLAKE2b-256 checksum
How to use checksums
1807ac0dacd53bb3fa91393b1fda21fc5342e16815613d8a9db037849b356e4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Security for kv-dict 0.2.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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