Skip to main content

strands-session-sql

SQL session manager (storage backend) for Strands Agents, via SQLAlchemy. One provider for any SQLAlchemy-supported database — SQLite, PostgreSQL, MySQL, and more — selected purely by connection URL. The Python equivalent of "JDBC backends": one API, many databases.

Part of the strands-agents-session family — it implements the base SessionStorage interface, so all the Strands session-repository logic comes from the core.

Storage only, by design. Message pruning in Strands is a ConversationManager concern, decoupled from storage. This package does not prune.

Installation

pip install strands-session-sql              # SQLite works out of the box (built-in)
pip install "strands-session-sql[postgres]"  # + psycopg (PostgreSQL)
pip install "strands-session-sql[mysql]"     # + pymysql (MySQL)
# or via the family extra:
pip install "strands-agents-session[sql]"

Requires Python 3.10+. SQLite needs no driver; other databases need their SQLAlchemy driver (the extras above).

Quick start

from strands import Agent
from strands_session_sql import SQLSessionManager

# SQLite (zero infra)
agent = Agent(session_manager=SQLSessionManager(
    session_id="user-123", url="sqlite:///sessions.db",
))

# PostgreSQL
mgr = SQLSessionManager(session_id="user-123",
                        url="postgresql+psycopg://user:pass@localhost:5432/mydb")

# MySQL
mgr = SQLSessionManager(session_id="user-123",
                        url="mysql+pymysql://user:pass@localhost:3306/mydb")

The table is created automatically if it does not exist.

API

SQLSessionManager(session_id, *, url=None, table_name="strands_sessions", engine=None)

Parameter Description
session_id Session identifier
url SQLAlchemy connection URL
table_name Table name (default strands_sessions; created if absent)
engine Optional pre-built SQLAlchemy Engine to reuse — supply this or url

Authentication

Auth is carried in the connection URL (user/password, host, TLS query args), or via a pre-built SQLAlchemy Engine for advanced setups (custom pools, SSL, IAM plugins):

postgresql+psycopg://user:pass@host:5432/db?sslmode=require
mysql+pymysql://user:pass@host/db?ssl_ca=/path/ca.pem
sqlite:///sessions.db

Data model

A single table with a composite primary key (pk, sk) and a data column:

CREATE TABLE strands_sessions (
    pk VARCHAR(255) NOT NULL,
    sk VARCHAR(255) NOT NULL,
    data TEXT NOT NULL,
    PRIMARY KEY (pk, sk)
);

list_messages(offset, limit) maps to WHERE pk = ? AND sk >= ? ORDER BY sk LIMIT ?. Message sort keys are zero-padded so lexical order matches numeric order.

License

MIT

Metadata

Release files for strands_session_sql 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 strands_session_sql 0.2.0
File Size Uploaded Provenance
strands_session_sql-0.2.0.tar.gz 5.5 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 9.9 kB

Release files / strands_session_sql-0.2.0.tar.gz

Download URL strands_session_sql-0.2.0.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
898cb0b67589c94df14d4e5ef8bfaefb82d347695f06f4475d0c590b78009b62
BLAKE2b-256 checksum
How to use checksums
5482e9393e298cf00ea0c9a056dffc70da51fa1b9a26845bf54d7085fa7a23e9
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_sql-0.2.0-py3-none-any.whl

Download URL strands_session_sql-0.2.0-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9acf08796bc491f563fcac62fa911c1df08f29c5f562d5ddcd74ccc202035c53
BLAKE2b-256 checksum
How to use checksums
48a6b650c289b8bb865c6242283196acbcbea30e511f6d7d865333f0c289bc93
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_sql 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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

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