Skip to main content

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 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

Project details


Download files

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

Source Distribution

strands_session_sql-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

strands_session_sql-0.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: strands_session_sql-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 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

Hashes for strands_session_sql-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f8c1fcccc755b5dfeff38fab9f074846fb5abaae0cb511c1476820c568d4b171
MD5 71fc6c643b0c9455d2cba46b132a330f
BLAKE2b-256 d443e52f73b37aa998288e427730fa7950fd7ffa3b20275e7a861ea06306ca5d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: strands_session_sql-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 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

Hashes for strands_session_sql-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ca4389f2fca81cdd9cf6507f1164d754e33831bff7c6e9d86456961a322b2df7
MD5 ce3f57fabfb4418384befea6e7ee2335
BLAKE2b-256 1b2260d0e415297ea52700ce90560e32227094e4f0119ed2a276e878bf212502

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page