strands-session-dynamodb
Amazon DynamoDB session manager (storage backend) for Strands Agents. Persists an agent's sessions, agent state, conversation-manager state, and messages to a single DynamoDB table so conversations resume across runs.
It implements Strands' SessionRepository and mixes in RepositorySessionManager — exactly like the built-in S3SessionManager — so all the session lifecycle logic (message indexing, restore, removed_message_count offsetting, tool-use repair, change detection) is reused unchanged. This package only supplies the DynamoDB storage.
Storage only, by design. In Strands, message pruning is the job of a
ConversationManager(SlidingWindow,Summarizing), which is deliberately decoupled from storage. This package does not prune — pruning at the storage layer would corrupt Strands' message-index/offset restore logic. Use aconversation_managerfor that.
Why DynamoDB instead of S3
Strands ships an S3SessionManager out of the box, so why DynamoDB? Because agent sessions are a request-bound, small-item workload — the exact shape where DynamoDB wins on both cost and latency.
Strands writes one item per message plus an agent record re-synced each turn — lots of tiny (sub-KB) reads and writes. The bill is dominated by request count, not bytes stored, and that's where the two services price very differently:
| S3 Standard | DynamoDB on-demand | |
|---|---|---|
| Write | ~$5.00 / million PUT (any size) | ~$1.25 / million WRU (per 1 KB) |
| Read | ~$0.40 / million GET (per object) | ~$0.25 / million RRU (per 4 KB) |
| Free tier | none | 25 WCU + 25 RCU + 25 GB, perpetual |
| Latency | tens of ms | single-digit ms |
Two structural advantages for small items:
- Writes: S3 charges per request regardless of size — a 200-byte message costs the same PUT as a 4 MB one. DynamoDB bills per KB, so tiny messages hit the cheapest unit and the per-unit price is ~4× lower.
- Reads:
list_messagesis one Query in DynamoDB, and one RRU covers 4 KB — so several small messages per RRU. In S3 it's one GET per message object. Batching crushes the per-item read cost.
For a workload of ~1M small message-writes/month with periodic restores, this is roughly a 3–4× lower bill on DynamoDB — and often free under DynamoDB's perpetual free tier, which S3 has no equivalent of. Add native TTL for automatic session expiry and single-digit-ms access, and DynamoDB is the better default for hot session/agent-state storage.
When S3 still wins: very large message payloads (big tool results, images) that approach or exceed DynamoDB's 400 KB item limit, or cold/archival sessions rarely read (S3 storage is ~10× cheaper per GB). A robust production setup is DynamoDB for the session/message records + S3 overflow only for oversized blobs.
Installation
pip install strands-session-dynamodb
# or, via the family's extra:
pip install "strands-agents-session[dynamodb]"
Requires Python 3.10+.
Quick start
from strands import Agent
from strands_session_dynamodb import DynamoDBSessionManager
session_manager = DynamoDBSessionManager(
session_id="user-123",
table_name="strands-sessions",
region_name="us-east-1",
)
agent = Agent(session_manager=session_manager)
agent("Hi, I'm Kamal")
agent("What's my name?") # remembers within the session
Next run, same session_id → the agent restores its full history and state from DynamoDB. The table is created automatically (on-demand billing) if it does not exist.
API
DynamoDBSessionManager(session_id, table_name, *, region_name=None, boto_session=None, boto_client_config=None, endpoint_url=None, ttl_seconds=None)
| Parameter | Description |
|---|---|
session_id |
Session identifier |
table_name |
DynamoDB table (auto-created if absent) |
region_name |
AWS region |
boto_session |
Optional pre-built boto3.Session |
boto_client_config |
Optional botocore client config |
endpoint_url |
Custom endpoint (e.g. DynamoDB Local / LocalStack) |
ttl_seconds |
If set, writes a ttl epoch attribute and enables table TTL for automatic session expiry |
AWS setup
Standard AWS credential resolution (env vars, ~/.aws/credentials, profile, or IAM role). The credentials need permission to create the table (if absent) and read/write items.
Data model
Single table, both keys strings:
| Item | PK | SK |
|---|---|---|
| Session | SESSION#<session_id> |
META |
| Agent | SESSION#<session_id> |
AGENT#<agent_id> |
| Message | SESSION#<session_id>#AGENT#<agent_id> |
MSG#<zero-padded id> |
Messages live in a per-agent partition with a zero-padded, lexically ordered sort key, so list_messages(offset, limit) is a native range Query — matching the removed_message_count offset semantics Strands relies on. Payloads are stored as a JSON string.
Item-size note: DynamoDB items are capped at 400 KB. A single message with a very large payload (e.g. big tool results / images) could exceed that; S3 has no such limit. For such workloads, keep large blobs in S3 and reference them.
License
MIT
Metadata
Release files for strands_session_dynamodb 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| strands_session_dynamodb-0.2.0.tar.gz | 7.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| strands_session_dynamodb-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.5 kB
Release files / strands_session_dynamodb-0.2.0.tar.gz
| Download URL | strands_session_dynamodb-0.2.0.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e35030dceec8173cdce8bed6fb43cca376e5e729b1e5d9bf1a26f3200a31ca8f
|
|
BLAKE2b-256 checksum How to use checksums |
2886b6d7116be7442cd4cff4a119895ccaf2a1dcf155dab46b3e3aa5015520e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / strands_session_dynamodb-0.2.0-py3-none-any.whl
| Download URL | strands_session_dynamodb-0.2.0-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d086954b30ad6978847d563567ca8f9d9a02b4ced9aad463ffbfbb4315969ec7
|
|
BLAKE2b-256 checksum How to use checksums |
c5b6781f0e41b2ff2007fe87842c4490cd610960dec4baf18fe69c5d948e4734
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for strands_session_dynamodb 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.