Skip to main content

Supabase Session Manager for Strands AI

A session manager for Strands Agents that uses Supabase (PostgreSQL) for persistent storage. Enables AI agents to maintain conversation history and state across sessions.

Features

  • Persistent Sessions: Store agent conversations and state in Supabase
  • Distributed Ready: Share sessions across multiple application instances
  • JSONB Storage: Native JSON support for complex data structures
  • Referential Integrity: CASCADE deletes ensure data consistency

Installation

pip install supabase-strands

Or with uv:

uv add supabase-strands

Quick Start

Choose the setup that fits your workflow:


Option A: Local (Supabase CLI)

1. Start Supabase locally

# Install the CLI (macOS)
brew install supabase/tap/supabase

# Initialize and start
supabase init
supabase start

After supabase start, the CLI prints a summary of local URLs and keys. Note the Project URL and the Publishable (anon) key — you'll need both in step 3.

2. Run the migrations

mkdir -p supabase/migrations
cp migrations/001_create_session_tables.sql supabase/migrations/
supabase db reset

Tip: Skip migrations/002_enable_rls.sql for local dev — RLS adds complexity you don't need while iterating. When you're ready to test auth policies, copy that file into supabase/migrations/ and run supabase db reset again.

3. Configure credentials

export SUPABASE_URL="<Project URL from supabase start>"
export SUPABASE_KEY="<Publishable key from supabase start>"

Or create a .env file:

SUPABASE_URL=<Project URL from supabase start>
SUPABASE_KEY=<Publishable key from supabase start>

You can re-print these values anytime with supabase status.

4. Run the example

uv sync --extra dev
uv run python examples/basic_usage.py

See examples/basic_usage.py for the full source.

5. Verify session storage

Open Supabase Studio at http://127.0.0.1:54323 and browse the sessions, agents, and messages tables in the Table Editor to confirm the data was persisted.


Option B: Hosted (Supabase Cloud)

1. Set up your Supabase project

Create a project at supabase.com and run migrations/001_create_session_tables.sql in the SQL Editor.

For production, also run migrations/002_enable_rls.sql and customize the RLS policies for your auth strategy (see Row-Level Security).

2. Configure credentials

export SUPABASE_URL="https://your-project.supabase.co"
export SUPABASE_KEY="your-anon-key"

3. Run the example

uv sync --extra dev
uv run python examples/basic_usage.py

See examples/basic_usage.py for the full source.

4. Verify session storage

Open your project's Table Editor in the Supabase dashboard and browse the sessions, agents, and messages tables to confirm the data was persisted.

Configuration

Credentials are read from SUPABASE_URL and SUPABASE_KEY environment variables by default. You can also pass them explicitly:

manager = SupabaseSessionManager(
    session_id="user-123",
    supabase_url="https://your-project.supabase.co",
    supabase_key="your-anon-key"
)

Database Schema

sessions (session_id PK, session_type, created_at, updated_at)
    └── agents (session_id FK, agent_id, state JSONB, conversation_manager_state JSONB)
        └── messages (session_id FK, agent_id, message_id, message JSONB, redact_message JSONB)

Foreign keys use ON DELETE CASCADE for referential integrity.

Row-Level Security

IMPORTANT: The basic schema migration (001_create_session_tables.sql) does not include Row-Level Security (RLS). For production deployments, enable RLS using migrations/002_enable_rls.sql.

The provided RLS policies assume Supabase Auth with auth.uid()::text = session_id. Customize the policies based on your authentication strategy:

  • Supabase Auth: Use auth.uid() to get the current user's ID
  • Custom Auth: Add a user_id column and filter on that
  • Service Account Pattern: Use the service role key in backend, anon key with RLS in frontend
  • Team/Org Isolation: Join to a teams table to implement org-level access control

Development

Setup

uv sync --extra dev

Running Tests

# Unit tests (no Supabase required)
uv run pytest tests/test_unit.py -v

# Integration tests (requires Supabase)
export SUPABASE_URL="your-test-url"
export SUPABASE_KEY="your-test-key"
uv run pytest tests/test_integration.py -v

# All tests with coverage
uv run pytest --cov=src/supabase_strands --cov-report=html

Requirements

License

MIT License - see LICENSE for details.

Contributing

Contributions welcome! Please open an issue or submit a pull request.

Metadata

Release files for supabase-strands 0.1.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 supabase-strands 0.1.0
File Size Uploaded Provenance
supabase_strands-0.1.0.tar.gz 165.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for supabase-strands 0.1.0
File Interpreter ABI Platform
supabase_strands-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 172.6 kB

Release files / supabase_strands-0.1.0.tar.gz

Download URL supabase_strands-0.1.0.tar.gz
Size 165.1 kB
Tags Source
SHA-256 checksum
How to use checksums
35957991c009c1c57e8a5aaec7c7fb6bcd899f75bb8649972679c58fe4130ccd
BLAKE2b-256 checksum
How to use checksums
43874dd525f543816800b4643cb06268d2f984ad4309d039d8eec039b8498f09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.8

Release files / supabase_strands-0.1.0-py3-none-any.whl

Download URL supabase_strands-0.1.0-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
06b8e36bd54496c86fddda23b2c8a72623fbc0559cb874b54a287bcddda4ebe3
BLAKE2b-256 checksum
How to use checksums
13accd1da48de1b28553584e94e4f8ede9eb089cc97a5c03155281401454aa43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.8

Security for supabase-strands 0.1.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.1.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