SQL session manager (storage backend) for Strands Agents via SQLAlchemy — one provider for SQLite, PostgreSQL, MySQL, and more
Project description
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
ConversationManagerconcern, 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file strands_session_sql-0.2.0.tar.gz.
File metadata
- Download URL: strands_session_sql-0.2.0.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
898cb0b67589c94df14d4e5ef8bfaefb82d347695f06f4475d0c590b78009b62
|
|
| MD5 |
baad53720902882d251bdc3e7ee3edcc
|
|
| BLAKE2b-256 |
5482e9393e298cf00ea0c9a056dffc70da51fa1b9a26845bf54d7085fa7a23e9
|
File details
Details for the file strands_session_sql-0.2.0-py3-none-any.whl.
File metadata
- Download URL: strands_session_sql-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9acf08796bc491f563fcac62fa911c1df08f29c5f562d5ddcd74ccc202035c53
|
|
| MD5 |
f30117283be32da4b1d2b2c195e47453
|
|
| BLAKE2b-256 |
48a6b650c289b8bb865c6242283196acbcbea30e511f6d7d865333f0c289bc93
|