Skip to main content

strands-dynamodb-storage (Python)

Python implementation of the Amazon DynamoDB Storage backend for the Strands Agents SDK — at parity with ../typescript/. Implements the SDK's strands.storage.Storage protocol (write/read/delete/list, plus namespace) so one DynamoDB-backed instance serves Session Manager, Memory Manager, and any subsystem that persists bytes.

Install

pip install strands-dynamodb-storage

Usage

from strands import Agent
from strands.session import SessionManager
from strands_dynamodb_storage import DynamoDBStorage

storage = DynamoDBStorage("agent-data", region_name="us-east-1")
agent = Agent(session_manager=SessionManager(storage=storage))

Direct byte usage (async):

store = DynamoDBStorage("agent-data", region_name="us-east-1")
await store.write("sessions/s1/snapshot.json", b'{"turn": 1}')
data = await store.read("sessions/s1/snapshot.json")           # bytes | None
keys = await store.list("sessions/s1/")                         # native Query
# Note: prefixes must cover at least a full scope and identifier ("scope/id/").
# list("") and single-segment prefixes are rejected as too broad -- they would
# require a cross-partition Scan. This deliberately narrows the SDK Storage
# contract (whose in-memory backends list everything on ""); SDK subsystems
# always pass namespaced prefixes and are unaffected.
scoped = await store.list(DynamoDBListQuery(pk="sessions/s1", sk_prefix="scopes/"))
await store.delete("sessions/s1/snapshot.json")

Features (parity with the TypeScript package)

  • Single-table design (pk/sk), with a structured DynamoDBListQuery extension point.
  • Optional Amazon S3 offload for values above the item-size limit (s3_bucket=...).
  • Optional gzip compression="gzip" (applied before the offload check).
  • Optional per-item TTL (ttl_seconds=...) with read/list expiry filtering.
  • Native vector search() via Amazon DynamoDB vector indexes (SearchVectors, requires boto3 >= 1.43.64); a vector_search adapter can override the call.

Semantic search

search() gives an agent semantic long-term memory over the same table: write each memory with its embedding, then query by meaning. Scoring runs in the database against a DynamoDB vector index (no second vector store, no ETL), and because the index is partitioned on pk, every search is scoped to the caller's key space -- one tenant's memories can never surface in another's results. Creating the table with a vector index (and the IAM permissions needed) is covered in the repository README's Provisioning and permissions.

from strands_dynamodb_storage import DynamoDBStorage, SearchQuery

store = DynamoDBStorage("agent-memory", region_name="us-east-1", prefix="user/u1")

# store a memory with its embedding (kept inline even when the payload offloads to S3)
await store.write(
    "memories/m1",
    b"likes window seats",
    vector=embed("likes window seats"),   # your embedding model, e.g. 1024 floats
    metadata={"kind": "preference"},
)

# recall by meaning, scoped to this store's partition
results = await store.search(SearchQuery(
    vector=embed("seating preferences?"),
    top_k=5,
    pk="user/u1/memories",                # required: the index declares a HASH element
    filter={"kind": "preference"},        # optional metadata equality filter
    include_values=True,                  # hydrate each match's stored bytes
))
for r in results:
    print(r.key, r.score, r.data)
# ordered most-similar-first; score direction follows the index's distance function
# (COSINE/EUCLIDEAN: lower = nearer; DOT_PRODUCT: higher = more similar)

Like a global secondary index, the vector index is eventually consistent, and a freshly created index backfills before it is searchable. Requires boto3 >= 1.43.64; a vector_search adapter, when configured, overrides the native call (testing, custom routing).

Development

python -m venv .venv && .venv/bin/pip install -e ".[dev]"
.venv/bin/python -m pytest -q            # unit tests (moto, offline)
.venv/bin/ruff check src tests && .venv/bin/mypy src
RUN_INTEG=1 AWS_REGION=us-east-1 .venv/bin/python -m pytest tests/integ -q   # real DynamoDB + S3

Download files

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

Source Distribution

strands_dynamodb_storage-0.1.0.tar.gz (23.2 kB view details)

Uploaded Source

Built Distribution

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

strands_dynamodb_storage-0.1.0-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for strands_dynamodb_storage-0.1.0.tar.gz
Algorithm Hash digest
SHA256 43ecce5eccf935f25ff3cd1d8e62b0221f2d86790ffdac64f994ea87192c346a
MD5 ce20bd43d11d593506bfdbc5e82d6df5
BLAKE2b-256 7e31a8de33a90b1a75fc9bbb999f2bccac6dc0f3bd65d832fd80c347a0cde9f5

See more details on using hashes here.

Provenance

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

Publisher: publish-python.yml on aws/strands-dynamodb-storage

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

File details

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

File metadata

File hashes

Hashes for strands_dynamodb_storage-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d4181e71773e3a0cd6b38568690ebb87baf76b5f9a084fcee6c6c79fff90331d
MD5 bfde604c38f6a9c037171e7150d272cd
BLAKE2b-256 450087bbd24e66b680808230af323a20d3aca00e3b6bb6649706746e43635b17

See more details on using hashes here.

Provenance

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

Publisher: publish-python.yml on aws/strands-dynamodb-storage

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 Sentry Error logging StatusPage Status page