strands-sql
strands-sql
Section titled “strands-sql”A general-purpose SQL tool for Strands Agents — supports PostgreSQL, MySQL, and SQLite via SQLAlchemy.
Installation
Section titled “Installation”# SQLite (no extra driver needed)pip install strands-sql
# PostgreSQLpip install "strands-sql[postgres]"
# MySQLpip install "strands-sql[mysql]"from strands import Agentfrom strands_sql import sql_database
agent = Agent(tools=[sql_database])
# Discover the schemaagent.tool.sql_database(action="schema_summary")
# Run a queryagent.tool.sql_database( action="query", sql="SELECT * FROM orders WHERE amount > 100 LIMIT 20",)Configuration
Section titled “Configuration”Set your database connection via environment variable:
export DATABASE_URL="postgresql://user:password@localhost:5432/mydb"Or pass it directly per call:
agent.tool.sql_database( action="list_tables", connection_string="sqlite:///./local.db",)Troubleshooting
Section titled “Troubleshooting”- No connection string found — make sure
DATABASE_URLis set or passconnection_stringexplicitly. - Write query blocked — write operations require
read_only=Falseexplicitly. - Timeout errors — increase the
timeoutparameter (default: 30s, max: 300s).