strands-sql 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- strands_sql/__init__.py +5 -0
- strands_sql/models.py +42 -0
- strands_sql/sql_database.py +480 -0
- strands_sql-0.1.0.dist-info/METADATA +332 -0
- strands_sql-0.1.0.dist-info/RECORD +8 -0
- strands_sql-0.1.0.dist-info/WHEEL +4 -0
- strands_sql-0.1.0.dist-info/licenses/LICENSE +175 -0
- strands_sql-0.1.0.dist-info/licenses/NOTICE +1 -0
strands_sql/__init__.py
ADDED
strands_sql/models.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Input/output models for strands-sql."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Literal
|
|
6
|
+
|
|
7
|
+
from pydantic import BaseModel, Field, model_validator
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class SqlDatabaseInput(BaseModel):
|
|
11
|
+
"""Validated input for the sql_database tool."""
|
|
12
|
+
|
|
13
|
+
action: Literal["list_tables", "describe_table", "schema_summary", "query", "execute"]
|
|
14
|
+
|
|
15
|
+
sql: str | None = Field(None, description="SQL string for query/execute actions.")
|
|
16
|
+
table: str | None = Field(None, description="Table name for describe_table action.")
|
|
17
|
+
|
|
18
|
+
connection_string: str | None = Field(
|
|
19
|
+
None, description="SQLAlchemy connection string. Falls back to DATABASE_URL env var."
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
read_only: bool = Field(True, description="Block write queries when True.")
|
|
23
|
+
max_rows: int = Field(500, ge=1, le=10_000, description="Max rows returned by query.")
|
|
24
|
+
timeout: int = Field(30, ge=1, le=300, description="Query timeout in seconds.")
|
|
25
|
+
output_format: Literal["json", "markdown"] = Field(
|
|
26
|
+
"markdown", description="Output format for query results."
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
allowed_tables: list[str] | None = Field(
|
|
30
|
+
None, description="Allowlist — only these tables are accessible."
|
|
31
|
+
)
|
|
32
|
+
blocked_tables: list[str] | None = Field(
|
|
33
|
+
None, description="Blocklist — these tables are never accessible."
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
@model_validator(mode="after")
|
|
37
|
+
def check_sql_provided(self) -> SqlDatabaseInput:
|
|
38
|
+
if self.action in ("query", "execute") and not self.sql:
|
|
39
|
+
raise ValueError(f"'sql' is required when action='{self.action}'.")
|
|
40
|
+
if self.action == "describe_table" and not self.table:
|
|
41
|
+
raise ValueError("'table' is required when action='describe_table'.")
|
|
42
|
+
return self
|
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
"""
|
|
2
|
+
strands-sql — General-purpose SQL tool for Strands agents.
|
|
3
|
+
|
|
4
|
+
Supports PostgreSQL, MySQL, and SQLite via SQLAlchemy.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import os
|
|
10
|
+
import re
|
|
11
|
+
import textwrap
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
from sqlalchemy import create_engine, inspect, text
|
|
15
|
+
from sqlalchemy.engine import Engine
|
|
16
|
+
from sqlalchemy.pool import NullPool
|
|
17
|
+
from strands.types.tools import ToolResult, ToolUse
|
|
18
|
+
|
|
19
|
+
from .models import SqlDatabaseInput
|
|
20
|
+
|
|
21
|
+
# ---------------------------------------------------------------------------
|
|
22
|
+
# Engine cache — one engine per connection string, reused across tool calls
|
|
23
|
+
# ---------------------------------------------------------------------------
|
|
24
|
+
_ENGINE_CACHE: dict[str, Engine] = {}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _get_engine(connection_string: str, timeout: int) -> Engine:
|
|
28
|
+
key = connection_string
|
|
29
|
+
if key not in _ENGINE_CACHE:
|
|
30
|
+
_ENGINE_CACHE[key] = create_engine(
|
|
31
|
+
connection_string,
|
|
32
|
+
poolclass=NullPool, # safe default; no dangling connections
|
|
33
|
+
pool_pre_ping=True, # detect stale connections before use
|
|
34
|
+
connect_args=_timeout_args(connection_string, timeout),
|
|
35
|
+
)
|
|
36
|
+
return _ENGINE_CACHE[key]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _timeout_args(connection_string: str, timeout: int) -> dict:
|
|
40
|
+
"""Return driver-specific timeout connect_args."""
|
|
41
|
+
cs = connection_string.lower()
|
|
42
|
+
if cs.startswith("postgresql") or cs.startswith("postgres"):
|
|
43
|
+
return {"connect_timeout": timeout, "options": f"-c statement_timeout={timeout * 1000}"}
|
|
44
|
+
if cs.startswith("mysql"):
|
|
45
|
+
return {"connect_timeout": timeout, "read_timeout": timeout, "write_timeout": timeout}
|
|
46
|
+
# SQLite and others — no timeout args
|
|
47
|
+
return {}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# ---------------------------------------------------------------------------
|
|
51
|
+
# Security helpers
|
|
52
|
+
# ---------------------------------------------------------------------------
|
|
53
|
+
_WRITE_PATTERN = re.compile(
|
|
54
|
+
r"^\s*(insert|update|delete|drop|create|alter|truncate|replace|merge|call|exec)\b",
|
|
55
|
+
re.IGNORECASE,
|
|
56
|
+
)
|
|
57
|
+
_COMMENT_PATTERN = re.compile(r"(--[^\n]*|/\*.*?\*/)", re.DOTALL)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _is_write_query(sql: str) -> bool:
|
|
61
|
+
clean = _COMMENT_PATTERN.sub("", sql)
|
|
62
|
+
return bool(_WRITE_PATTERN.match(clean.strip()))
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _sanitize_error(exc: Exception) -> str:
|
|
66
|
+
"""Return a safe error message that doesn't leak internal stack details."""
|
|
67
|
+
msg = str(exc)
|
|
68
|
+
# Strip file paths and line references
|
|
69
|
+
msg = re.sub(r'File ".*?"', 'File "<hidden>"', msg)
|
|
70
|
+
# Truncate very long messages (e.g. full query echoed back by driver)
|
|
71
|
+
if len(msg) > 400:
|
|
72
|
+
msg = msg[:400] + "... [truncated]"
|
|
73
|
+
return msg
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _check_table_access(
|
|
77
|
+
table: str,
|
|
78
|
+
allowed_tables: list[str] | None,
|
|
79
|
+
blocked_tables: list[str] | None,
|
|
80
|
+
) -> str | None:
|
|
81
|
+
"""Return an error string if table access is denied, else None."""
|
|
82
|
+
if allowed_tables and table.lower() not in [t.lower() for t in allowed_tables]:
|
|
83
|
+
return f"Access denied: table '{table}' is not in allowed_tables."
|
|
84
|
+
if blocked_tables and table.lower() in [t.lower() for t in blocked_tables]:
|
|
85
|
+
return f"Access denied: table '{table}' is blocked."
|
|
86
|
+
return None
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _check_sql_table_access(
|
|
90
|
+
sql: str,
|
|
91
|
+
allowed_tables: list[str] | None,
|
|
92
|
+
blocked_tables: list[str] | None,
|
|
93
|
+
) -> str | None:
|
|
94
|
+
"""Best-effort check that a SQL query only touches allowed tables."""
|
|
95
|
+
if not allowed_tables and not blocked_tables:
|
|
96
|
+
return None
|
|
97
|
+
# Extract identifiers after FROM / JOIN — naive but catches the common case
|
|
98
|
+
identifiers = re.findall(r"(?:from|join)\s+[`\"]?(\w+)[`\"]?", sql, re.IGNORECASE)
|
|
99
|
+
for tbl in identifiers:
|
|
100
|
+
err = _check_table_access(tbl, allowed_tables, blocked_tables)
|
|
101
|
+
if err:
|
|
102
|
+
return err
|
|
103
|
+
return None
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
# ---------------------------------------------------------------------------
|
|
107
|
+
# Output formatting
|
|
108
|
+
# ---------------------------------------------------------------------------
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _rows_to_markdown(columns: list[str], rows: list[tuple[Any, ...]]) -> str:
|
|
112
|
+
if not rows:
|
|
113
|
+
return "*(no rows)*"
|
|
114
|
+
col_widths = [
|
|
115
|
+
max(len(c), max((len(str(r[i])) for r in rows), default=0)) for i, c in enumerate(columns)
|
|
116
|
+
]
|
|
117
|
+
header = " | ".join(c.ljust(col_widths[i]) for i, c in enumerate(columns))
|
|
118
|
+
separator = "-+-".join("-" * w for w in col_widths)
|
|
119
|
+
data_rows = [
|
|
120
|
+
" | ".join(str(row[i]).ljust(col_widths[i]) for i in range(len(columns))) for row in rows
|
|
121
|
+
]
|
|
122
|
+
return "\n".join([header, separator] + data_rows)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _format_results(
|
|
126
|
+
columns: list[str],
|
|
127
|
+
rows: list[tuple[Any, ...]],
|
|
128
|
+
output_format: str,
|
|
129
|
+
max_rows: int,
|
|
130
|
+
truncated: bool,
|
|
131
|
+
) -> str:
|
|
132
|
+
note = f"\n\n⚠️ Results truncated to {max_rows} rows." if truncated else ""
|
|
133
|
+
if output_format == "markdown":
|
|
134
|
+
return _rows_to_markdown(columns, rows) + note
|
|
135
|
+
# Default: JSON-like
|
|
136
|
+
result = [dict(zip(columns, row)) for row in rows]
|
|
137
|
+
import json
|
|
138
|
+
|
|
139
|
+
return json.dumps(result, default=str, indent=2) + note
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
# ---------------------------------------------------------------------------
|
|
143
|
+
# Action implementations
|
|
144
|
+
# ---------------------------------------------------------------------------
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _list_tables(
|
|
148
|
+
engine: Engine,
|
|
149
|
+
allowed_tables: list[str] | None,
|
|
150
|
+
blocked_tables: list[str] | None,
|
|
151
|
+
) -> str:
|
|
152
|
+
inspector = inspect(engine)
|
|
153
|
+
tables = inspector.get_table_names()
|
|
154
|
+
views = inspector.get_view_names()
|
|
155
|
+
all_objects = [("table", t) for t in tables] + [("view", v) for v in views]
|
|
156
|
+
|
|
157
|
+
filtered = []
|
|
158
|
+
for kind, name in all_objects:
|
|
159
|
+
if allowed_tables and name.lower() not in [t.lower() for t in allowed_tables]:
|
|
160
|
+
continue
|
|
161
|
+
if blocked_tables and name.lower() in [t.lower() for t in blocked_tables]:
|
|
162
|
+
continue
|
|
163
|
+
filtered.append((kind, name))
|
|
164
|
+
|
|
165
|
+
if not filtered:
|
|
166
|
+
return "No accessible tables or views found."
|
|
167
|
+
lines = [f"[{kind}] {name}" for kind, name in filtered]
|
|
168
|
+
return "\n".join(lines)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _describe_table(
|
|
172
|
+
engine: Engine,
|
|
173
|
+
table: str,
|
|
174
|
+
allowed_tables: list[str] | None,
|
|
175
|
+
blocked_tables: list[str] | None,
|
|
176
|
+
) -> str:
|
|
177
|
+
err = _check_table_access(table, allowed_tables, blocked_tables)
|
|
178
|
+
if err:
|
|
179
|
+
return err
|
|
180
|
+
|
|
181
|
+
inspector = inspect(engine)
|
|
182
|
+
try:
|
|
183
|
+
columns = inspector.get_columns(table)
|
|
184
|
+
pk_info = inspector.get_pk_constraint(table)
|
|
185
|
+
fk_info = inspector.get_foreign_keys(table)
|
|
186
|
+
except Exception as exc:
|
|
187
|
+
return f"Error describing table: {_sanitize_error(exc)}"
|
|
188
|
+
|
|
189
|
+
pk_cols = set(pk_info.get("constrained_columns", []))
|
|
190
|
+
lines = [f"Table: {table}", "", "Columns:"]
|
|
191
|
+
for col in columns:
|
|
192
|
+
flags = []
|
|
193
|
+
if col["name"] in pk_cols:
|
|
194
|
+
flags.append("PK")
|
|
195
|
+
if not col.get("nullable", True):
|
|
196
|
+
flags.append("NOT NULL")
|
|
197
|
+
flag_str = " [" + ", ".join(flags) + "]" if flags else ""
|
|
198
|
+
default = f" default={col['default']}" if col.get("default") is not None else ""
|
|
199
|
+
lines.append(f" {col['name']} {col['type']}{flag_str}{default}")
|
|
200
|
+
|
|
201
|
+
if fk_info:
|
|
202
|
+
lines += ["", "Foreign Keys:"]
|
|
203
|
+
for fk in fk_info:
|
|
204
|
+
cols = ", ".join(fk["constrained_columns"])
|
|
205
|
+
ref_table = fk["referred_table"]
|
|
206
|
+
ref_cols = ", ".join(fk["referred_columns"])
|
|
207
|
+
lines.append(f" ({cols}) → {ref_table}({ref_cols})")
|
|
208
|
+
|
|
209
|
+
return "\n".join(lines)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def _schema_summary(
|
|
213
|
+
engine: Engine,
|
|
214
|
+
allowed_tables: list[str] | None,
|
|
215
|
+
blocked_tables: list[str] | None,
|
|
216
|
+
max_tables: int = 30,
|
|
217
|
+
) -> str:
|
|
218
|
+
inspector = inspect(engine)
|
|
219
|
+
all_tables = inspector.get_table_names()
|
|
220
|
+
|
|
221
|
+
# Apply access filters
|
|
222
|
+
visible = []
|
|
223
|
+
for t in all_tables:
|
|
224
|
+
if allowed_tables and t.lower() not in [x.lower() for x in allowed_tables]:
|
|
225
|
+
continue
|
|
226
|
+
if blocked_tables and t.lower() in [x.lower() for x in blocked_tables]:
|
|
227
|
+
continue
|
|
228
|
+
visible.append(t)
|
|
229
|
+
|
|
230
|
+
truncated_tables = len(visible) > max_tables
|
|
231
|
+
visible = visible[:max_tables]
|
|
232
|
+
|
|
233
|
+
lines = []
|
|
234
|
+
for table in visible:
|
|
235
|
+
try:
|
|
236
|
+
columns = inspector.get_columns(table)
|
|
237
|
+
pk_info = inspector.get_pk_constraint(table)
|
|
238
|
+
pk_cols = set(pk_info.get("constrained_columns", []))
|
|
239
|
+
col_parts = []
|
|
240
|
+
for col in columns:
|
|
241
|
+
marker = "*" if col["name"] in pk_cols else ""
|
|
242
|
+
col_parts.append(f"{marker}{col['name']}:{col['type']}")
|
|
243
|
+
lines.append(f"{table}({', '.join(col_parts)})")
|
|
244
|
+
except Exception:
|
|
245
|
+
lines.append(f"{table}(schema unavailable)")
|
|
246
|
+
|
|
247
|
+
summary = "\n".join(lines)
|
|
248
|
+
if truncated_tables:
|
|
249
|
+
summary += f"\n\n... (showing {max_tables} of {len(all_tables)} tables)"
|
|
250
|
+
return summary
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def _run_query(
|
|
254
|
+
engine: Engine,
|
|
255
|
+
sql: str,
|
|
256
|
+
allowed_tables: list[str] | None,
|
|
257
|
+
blocked_tables: list[str] | None,
|
|
258
|
+
max_rows: int,
|
|
259
|
+
output_format: str,
|
|
260
|
+
timeout: int,
|
|
261
|
+
) -> str:
|
|
262
|
+
err = _check_sql_table_access(sql, allowed_tables, blocked_tables)
|
|
263
|
+
if err:
|
|
264
|
+
return err
|
|
265
|
+
|
|
266
|
+
try:
|
|
267
|
+
with engine.connect() as conn:
|
|
268
|
+
result = conn.execute(text(sql).execution_options(timeout=timeout))
|
|
269
|
+
columns = list(result.keys())
|
|
270
|
+
rows: list[tuple[Any, ...]] = [tuple(row) for row in result.fetchmany(max_rows + 1)]
|
|
271
|
+
truncated = len(rows) > max_rows
|
|
272
|
+
rows = rows[:max_rows]
|
|
273
|
+
return _format_results(columns, rows, output_format, max_rows, truncated)
|
|
274
|
+
except Exception as exc:
|
|
275
|
+
return f"Query error: {_sanitize_error(exc)}"
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def _run_execute(
|
|
279
|
+
engine: Engine,
|
|
280
|
+
sql: str,
|
|
281
|
+
allowed_tables: list[str] | None,
|
|
282
|
+
blocked_tables: list[str] | None,
|
|
283
|
+
timeout: int,
|
|
284
|
+
) -> str:
|
|
285
|
+
err = _check_sql_table_access(sql, allowed_tables, blocked_tables)
|
|
286
|
+
if err:
|
|
287
|
+
return err
|
|
288
|
+
|
|
289
|
+
try:
|
|
290
|
+
with engine.begin() as conn:
|
|
291
|
+
result = conn.execute(text(sql).execution_options(timeout=timeout))
|
|
292
|
+
rowcount = result.rowcount
|
|
293
|
+
return f"OK. Rows affected: {rowcount if rowcount >= 0 else 'unknown'}"
|
|
294
|
+
except Exception as exc:
|
|
295
|
+
return f"Execute error: {_sanitize_error(exc)}"
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
# ---------------------------------------------------------------------------
|
|
299
|
+
# Tool entry point — called by the Strands agent runtime
|
|
300
|
+
# ---------------------------------------------------------------------------
|
|
301
|
+
|
|
302
|
+
TOOL_SPEC = {
|
|
303
|
+
"name": "sql_database",
|
|
304
|
+
"description": textwrap.dedent("""\
|
|
305
|
+
General-purpose SQL tool. Supports list_tables, describe_table,
|
|
306
|
+
schema_summary, query (SELECT), and execute (write, if enabled).
|
|
307
|
+
Works with PostgreSQL, MySQL, and SQLite via SQLAlchemy.
|
|
308
|
+
"""),
|
|
309
|
+
"inputSchema": {
|
|
310
|
+
"json": {
|
|
311
|
+
"type": "object",
|
|
312
|
+
"properties": {
|
|
313
|
+
"action": {
|
|
314
|
+
"type": "string",
|
|
315
|
+
"enum": ["list_tables", "describe_table", "schema_summary", "query", "execute"],
|
|
316
|
+
"description": "The action to perform.",
|
|
317
|
+
},
|
|
318
|
+
"sql": {
|
|
319
|
+
"type": "string",
|
|
320
|
+
"description": "SQL string for 'query' or 'execute' actions.",
|
|
321
|
+
},
|
|
322
|
+
"table": {
|
|
323
|
+
"type": "string",
|
|
324
|
+
"description": "Table name for 'describe_table' action.",
|
|
325
|
+
},
|
|
326
|
+
"connection_string": {
|
|
327
|
+
"type": "string",
|
|
328
|
+
"description": (
|
|
329
|
+
"SQLAlchemy connection string. Falls back to DATABASE_URL env var."
|
|
330
|
+
),
|
|
331
|
+
},
|
|
332
|
+
"read_only": {
|
|
333
|
+
"type": "boolean",
|
|
334
|
+
"description": "Block write queries. Default true.",
|
|
335
|
+
},
|
|
336
|
+
"max_rows": {
|
|
337
|
+
"type": "integer",
|
|
338
|
+
"description": "Max rows returned by 'query'. Default 500.",
|
|
339
|
+
},
|
|
340
|
+
"timeout": {
|
|
341
|
+
"type": "integer",
|
|
342
|
+
"description": "Query timeout in seconds. Default 30.",
|
|
343
|
+
},
|
|
344
|
+
"output_format": {
|
|
345
|
+
"type": "string",
|
|
346
|
+
"enum": ["json", "markdown"],
|
|
347
|
+
"description": "Output format for query results. Default 'markdown'.",
|
|
348
|
+
},
|
|
349
|
+
"allowed_tables": {
|
|
350
|
+
"type": "array",
|
|
351
|
+
"items": {"type": "string"},
|
|
352
|
+
"description": "Allowlist of table names the agent may access.",
|
|
353
|
+
},
|
|
354
|
+
"blocked_tables": {
|
|
355
|
+
"type": "array",
|
|
356
|
+
"items": {"type": "string"},
|
|
357
|
+
"description": "Blocklist of table names the agent may not access.",
|
|
358
|
+
},
|
|
359
|
+
},
|
|
360
|
+
"required": ["action"],
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
def sql_database(tool: ToolUse, **kwargs: Any) -> ToolResult:
|
|
367
|
+
"""Strands tool handler for sql_database."""
|
|
368
|
+
tool_input = tool.get("input", {})
|
|
369
|
+
|
|
370
|
+
# Parse and validate input
|
|
371
|
+
try:
|
|
372
|
+
params = SqlDatabaseInput(**tool_input)
|
|
373
|
+
except Exception as exc:
|
|
374
|
+
return {
|
|
375
|
+
"toolUseId": tool["toolUseId"],
|
|
376
|
+
"status": "error",
|
|
377
|
+
"content": [{"text": f"Invalid input: {exc}"}],
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
# Resolve connection string
|
|
381
|
+
connection_string = params.connection_string or os.environ.get("DATABASE_URL")
|
|
382
|
+
if not connection_string:
|
|
383
|
+
return {
|
|
384
|
+
"toolUseId": tool["toolUseId"],
|
|
385
|
+
"status": "error",
|
|
386
|
+
"content": [
|
|
387
|
+
{
|
|
388
|
+
"text": (
|
|
389
|
+
"No connection string provided. Set DATABASE_URL or pass connection_string."
|
|
390
|
+
)
|
|
391
|
+
}
|
|
392
|
+
],
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
# Safety: block writes when read_only=True
|
|
396
|
+
if params.read_only and params.action == "execute":
|
|
397
|
+
return {
|
|
398
|
+
"toolUseId": tool["toolUseId"],
|
|
399
|
+
"status": "error",
|
|
400
|
+
"content": [
|
|
401
|
+
{"text": "Write queries are blocked. Set read_only=False to enable execute."}
|
|
402
|
+
],
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if params.read_only and params.action == "query" and params.sql and _is_write_query(params.sql):
|
|
406
|
+
return {
|
|
407
|
+
"toolUseId": tool["toolUseId"],
|
|
408
|
+
"status": "error",
|
|
409
|
+
"content": [
|
|
410
|
+
{
|
|
411
|
+
"text": (
|
|
412
|
+
"Write statement detected in read_only mode. "
|
|
413
|
+
"Use action='execute' with read_only=False."
|
|
414
|
+
)
|
|
415
|
+
}
|
|
416
|
+
],
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
# Get (or create) engine
|
|
420
|
+
try:
|
|
421
|
+
engine = _get_engine(connection_string, params.timeout)
|
|
422
|
+
except Exception as exc:
|
|
423
|
+
return {
|
|
424
|
+
"toolUseId": tool["toolUseId"],
|
|
425
|
+
"status": "error",
|
|
426
|
+
"content": [{"text": f"Connection failed: {_sanitize_error(exc)}"}],
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
# Dispatch
|
|
430
|
+
try:
|
|
431
|
+
if params.action == "list_tables":
|
|
432
|
+
result = _list_tables(engine, params.allowed_tables, params.blocked_tables)
|
|
433
|
+
|
|
434
|
+
elif params.action == "describe_table":
|
|
435
|
+
if not params.table:
|
|
436
|
+
result = "Error: 'table' parameter is required for describe_table."
|
|
437
|
+
else:
|
|
438
|
+
result = _describe_table(
|
|
439
|
+
engine, params.table, params.allowed_tables, params.blocked_tables
|
|
440
|
+
)
|
|
441
|
+
|
|
442
|
+
elif params.action == "schema_summary":
|
|
443
|
+
result = _schema_summary(engine, params.allowed_tables, params.blocked_tables)
|
|
444
|
+
|
|
445
|
+
elif params.action == "query":
|
|
446
|
+
if not params.sql:
|
|
447
|
+
result = "Error: 'sql' parameter is required for query."
|
|
448
|
+
else:
|
|
449
|
+
result = _run_query(
|
|
450
|
+
engine,
|
|
451
|
+
params.sql,
|
|
452
|
+
params.allowed_tables,
|
|
453
|
+
params.blocked_tables,
|
|
454
|
+
params.max_rows,
|
|
455
|
+
params.output_format,
|
|
456
|
+
params.timeout,
|
|
457
|
+
)
|
|
458
|
+
|
|
459
|
+
elif params.action == "execute":
|
|
460
|
+
if not params.sql:
|
|
461
|
+
result = "Error: 'sql' parameter is required for execute."
|
|
462
|
+
else:
|
|
463
|
+
result = _run_execute(
|
|
464
|
+
engine,
|
|
465
|
+
params.sql,
|
|
466
|
+
params.allowed_tables,
|
|
467
|
+
params.blocked_tables,
|
|
468
|
+
params.timeout,
|
|
469
|
+
)
|
|
470
|
+
else:
|
|
471
|
+
result = f"Unknown action: {params.action}"
|
|
472
|
+
|
|
473
|
+
except Exception as exc:
|
|
474
|
+
result = f"Unexpected error: {_sanitize_error(exc)}"
|
|
475
|
+
|
|
476
|
+
return {
|
|
477
|
+
"toolUseId": tool["toolUseId"],
|
|
478
|
+
"status": "success",
|
|
479
|
+
"content": [{"text": result}],
|
|
480
|
+
}
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: strands-sql
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: General-purpose SQL tool for Strands agents — supports PostgreSQL, MySQL, and SQLite.
|
|
5
|
+
Project-URL: Homepage, https://github.com/NithiN-1808/strands-sql
|
|
6
|
+
Project-URL: Repository, https://github.com/NithiN-1808/strands-sql
|
|
7
|
+
Project-URL: Issues, https://github.com/NithiN-1808/strands-sql/issues
|
|
8
|
+
Author-email: Nithin R <nithinr1808@gmail.com>
|
|
9
|
+
License:
|
|
10
|
+
Apache License
|
|
11
|
+
Version 2.0, January 2004
|
|
12
|
+
http://www.apache.org/licenses/
|
|
13
|
+
|
|
14
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
15
|
+
|
|
16
|
+
1. Definitions.
|
|
17
|
+
|
|
18
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
19
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
20
|
+
|
|
21
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
22
|
+
the copyright owner that is granting the License.
|
|
23
|
+
|
|
24
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
25
|
+
other entities that control, are controlled by, or are under common
|
|
26
|
+
control with that entity. For the purposes of this definition,
|
|
27
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
28
|
+
direction or management of such entity, whether by contract or
|
|
29
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
30
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
31
|
+
|
|
32
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
33
|
+
exercising permissions granted by this License.
|
|
34
|
+
|
|
35
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
36
|
+
including but not limited to software source code, documentation
|
|
37
|
+
source, and configuration files.
|
|
38
|
+
|
|
39
|
+
"Object" form shall mean any form resulting from mechanical
|
|
40
|
+
transformation or translation of a Source form, including but
|
|
41
|
+
not limited to compiled object code, generated documentation,
|
|
42
|
+
and conversions to other media types.
|
|
43
|
+
|
|
44
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
45
|
+
Object form, made available under the License, as indicated by a
|
|
46
|
+
copyright notice that is included in or attached to the work
|
|
47
|
+
(an example is provided in the Appendix below).
|
|
48
|
+
|
|
49
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
50
|
+
form, that is based on (or derived from) the Work and for which the
|
|
51
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
52
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
53
|
+
of this License, Derivative Works shall not include works that remain
|
|
54
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
55
|
+
the Work and Derivative Works thereof.
|
|
56
|
+
|
|
57
|
+
"Contribution" shall mean any work of authorship, including
|
|
58
|
+
the original version of the Work and any modifications or additions
|
|
59
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
60
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
61
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
62
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
63
|
+
means any form of electronic, verbal, or written communication sent
|
|
64
|
+
to the Licensor or its representatives, including but not limited to
|
|
65
|
+
communication on electronic mailing lists, source code control systems,
|
|
66
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
67
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
68
|
+
excluding communication that is conspicuously marked or otherwise
|
|
69
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
70
|
+
|
|
71
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
72
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
73
|
+
subsequently incorporated within the Work.
|
|
74
|
+
|
|
75
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
76
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
77
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
78
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
79
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
80
|
+
Work and such Derivative Works in Source or Object form.
|
|
81
|
+
|
|
82
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
83
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
84
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
85
|
+
(except as stated in this section) patent license to make, have made,
|
|
86
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
87
|
+
where such license applies only to those patent claims licensable
|
|
88
|
+
by such Contributor that are necessarily infringed by their
|
|
89
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
90
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
91
|
+
institute patent litigation against any entity (including a
|
|
92
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
93
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
94
|
+
or contributory patent infringement, then any patent licenses
|
|
95
|
+
granted to You under this License for that Work shall terminate
|
|
96
|
+
as of the date such litigation is filed.
|
|
97
|
+
|
|
98
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
99
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
100
|
+
modifications, and in Source or Object form, provided that You
|
|
101
|
+
meet the following conditions:
|
|
102
|
+
|
|
103
|
+
(a) You must give any other recipients of the Work or
|
|
104
|
+
Derivative Works a copy of this License; and
|
|
105
|
+
|
|
106
|
+
(b) You must cause any modified files to carry prominent notices
|
|
107
|
+
stating that You changed the files; and
|
|
108
|
+
|
|
109
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
110
|
+
that You distribute, all copyright, patent, trademark, and
|
|
111
|
+
attribution notices from the Source form of the Work,
|
|
112
|
+
excluding those notices that do not pertain to any part of
|
|
113
|
+
the Derivative Works; and
|
|
114
|
+
|
|
115
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
116
|
+
distribution, then any Derivative Works that You distribute must
|
|
117
|
+
include a readable copy of the attribution notices contained
|
|
118
|
+
within such NOTICE file, excluding those notices that do not
|
|
119
|
+
pertain to any part of the Derivative Works, in at least one
|
|
120
|
+
of the following places: within a NOTICE text file distributed
|
|
121
|
+
as part of the Derivative Works; within the Source form or
|
|
122
|
+
documentation, if provided along with the Derivative Works; or,
|
|
123
|
+
within a display generated by the Derivative Works, if and
|
|
124
|
+
wherever such third-party notices normally appear. The contents
|
|
125
|
+
of the NOTICE file are for informational purposes only and
|
|
126
|
+
do not modify the License. You may add Your own attribution
|
|
127
|
+
notices within Derivative Works that You distribute, alongside
|
|
128
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
129
|
+
that such additional attribution notices cannot be construed
|
|
130
|
+
as modifying the License.
|
|
131
|
+
|
|
132
|
+
You may add Your own copyright statement to Your modifications and
|
|
133
|
+
may provide additional or different license terms and conditions
|
|
134
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
135
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
136
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
137
|
+
the conditions stated in this License.
|
|
138
|
+
|
|
139
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
140
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
141
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
142
|
+
this License, without any additional terms or conditions.
|
|
143
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
144
|
+
the terms of any separate license agreement you may have executed
|
|
145
|
+
with Licensor regarding such Contributions.
|
|
146
|
+
|
|
147
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
148
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
149
|
+
except as required for reasonable and customary use in describing the
|
|
150
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
151
|
+
|
|
152
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
153
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
154
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
155
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
156
|
+
implied, including, without limitation, any warranties or conditions
|
|
157
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
158
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
159
|
+
appropriateness of using or redistributing the Work and assume any
|
|
160
|
+
risks associated with Your exercise of permissions under this License.
|
|
161
|
+
|
|
162
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
163
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
164
|
+
unless required by applicable law (such as deliberate and grossly
|
|
165
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
166
|
+
liable to You for damages, including any direct, indirect, special,
|
|
167
|
+
incidental, or consequential damages of any character arising as a
|
|
168
|
+
result of this License or out of the use or inability to use the
|
|
169
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
170
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
171
|
+
other commercial damages or losses), even if such Contributor
|
|
172
|
+
has been advised of the possibility of such damages.
|
|
173
|
+
|
|
174
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
175
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
176
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
177
|
+
or other liability obligations and/or rights consistent with this
|
|
178
|
+
License. However, in accepting such obligations, You may act only
|
|
179
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
180
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
181
|
+
defend, and hold each Contributor harmless for any liability
|
|
182
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
183
|
+
of your accepting any such warranty or additional liability.
|
|
184
|
+
License-File: LICENSE
|
|
185
|
+
License-File: NOTICE
|
|
186
|
+
Keywords: agents,mysql,postgresql,sql,sqlalchemy,sqlite,strands
|
|
187
|
+
Classifier: Development Status :: 4 - Beta
|
|
188
|
+
Classifier: Intended Audience :: Developers
|
|
189
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
190
|
+
Classifier: Programming Language :: Python :: 3
|
|
191
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
192
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
193
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
194
|
+
Classifier: Topic :: Database
|
|
195
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
196
|
+
Requires-Python: >=3.10
|
|
197
|
+
Requires-Dist: pydantic>=2.0
|
|
198
|
+
Requires-Dist: sqlalchemy>=2.0
|
|
199
|
+
Requires-Dist: strands-agents>=0.1.0
|
|
200
|
+
Provides-Extra: dev
|
|
201
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
202
|
+
Requires-Dist: pytest-asyncio>=0.26; extra == 'dev'
|
|
203
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
204
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
205
|
+
Requires-Dist: ruff>=0.4; extra == 'dev'
|
|
206
|
+
Requires-Dist: sqlalchemy>=2.0; extra == 'dev'
|
|
207
|
+
Provides-Extra: mysql
|
|
208
|
+
Requires-Dist: pymysql>=1.0; extra == 'mysql'
|
|
209
|
+
Provides-Extra: postgres
|
|
210
|
+
Requires-Dist: psycopg2-binary>=2.9; extra == 'postgres'
|
|
211
|
+
Description-Content-Type: text/markdown
|
|
212
|
+
|
|
213
|
+
# strands-sql
|
|
214
|
+
|
|
215
|
+
A general-purpose SQL tool for [Strands Agents](https://strandsagents.com) — supports PostgreSQL, MySQL, and SQLite via SQLAlchemy.
|
|
216
|
+
|
|
217
|
+
## Installation
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
# SQLite (no extra driver needed)
|
|
221
|
+
pip install strands-sql
|
|
222
|
+
|
|
223
|
+
# PostgreSQL
|
|
224
|
+
pip install "strands-sql[postgres]"
|
|
225
|
+
|
|
226
|
+
# MySQL
|
|
227
|
+
pip install "strands-sql[mysql]"
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Quick Start
|
|
231
|
+
|
|
232
|
+
```python
|
|
233
|
+
from strands import Agent
|
|
234
|
+
from strands_sql import sql_database
|
|
235
|
+
|
|
236
|
+
agent = Agent(tools=[sql_database])
|
|
237
|
+
|
|
238
|
+
# Discover the schema
|
|
239
|
+
agent.tool.sql_database(action="schema_summary")
|
|
240
|
+
|
|
241
|
+
# Describe a specific table
|
|
242
|
+
agent.tool.sql_database(action="describe_table", table="users")
|
|
243
|
+
|
|
244
|
+
# Run a query (returns a markdown table by default)
|
|
245
|
+
agent.tool.sql_database(
|
|
246
|
+
action="query",
|
|
247
|
+
sql="SELECT * FROM orders WHERE amount > 100 LIMIT 20",
|
|
248
|
+
)
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Configuration
|
|
252
|
+
|
|
253
|
+
### Connection String
|
|
254
|
+
|
|
255
|
+
Pass it directly or set the `DATABASE_URL` environment variable:
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
export DATABASE_URL="postgresql://user:password@localhost:5432/mydb"
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
```python
|
|
262
|
+
agent.tool.sql_database(
|
|
263
|
+
action="list_tables",
|
|
264
|
+
connection_string="sqlite:///./local.db",
|
|
265
|
+
)
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Actions
|
|
269
|
+
|
|
270
|
+
| Action | Required params | Description |
|
|
271
|
+
|---|---|---|
|
|
272
|
+
| `list_tables` | — | List all tables and views |
|
|
273
|
+
| `describe_table` | `table` | Columns, types, PKs, FKs |
|
|
274
|
+
| `schema_summary` | — | Compact schema of all tables (ideal as LLM context) |
|
|
275
|
+
| `query` | `sql` | Run a SELECT statement |
|
|
276
|
+
| `execute` | `sql`, `read_only=False` | Run a write query (blocked by default) |
|
|
277
|
+
|
|
278
|
+
## Safety Options
|
|
279
|
+
|
|
280
|
+
```python
|
|
281
|
+
agent.tool.sql_database(
|
|
282
|
+
action="query",
|
|
283
|
+
sql="SELECT * FROM users",
|
|
284
|
+
read_only=True, # Default: True — blocks INSERT/UPDATE/DELETE
|
|
285
|
+
max_rows=500, # Default: 500 — caps result size
|
|
286
|
+
timeout=30, # Default: 30s — kills hung queries
|
|
287
|
+
allowed_tables=["users", "orders"], # Allowlist
|
|
288
|
+
blocked_tables=["secrets"], # Blocklist
|
|
289
|
+
)
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
| Option | Default | Description |
|
|
293
|
+
|---|---|---|
|
|
294
|
+
| `read_only` | `True` | Blocks all write queries |
|
|
295
|
+
| `max_rows` | `500` | Maximum rows returned by `query` |
|
|
296
|
+
| `timeout` | `30` | Query timeout in seconds (1–300) |
|
|
297
|
+
| `allowed_tables` | `None` | Allowlist — only these tables are accessible |
|
|
298
|
+
| `blocked_tables` | `None` | Blocklist — these tables are never accessible |
|
|
299
|
+
|
|
300
|
+
## Output Formats
|
|
301
|
+
|
|
302
|
+
```python
|
|
303
|
+
# Markdown table (default — great for LLMs)
|
|
304
|
+
agent.tool.sql_database(action="query", sql="SELECT * FROM users", output_format="markdown")
|
|
305
|
+
|
|
306
|
+
# JSON array
|
|
307
|
+
agent.tool.sql_database(action="query", sql="SELECT * FROM users", output_format="json")
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
## Development
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
git clone https://github.com/NithiN-1808/strands-sql
|
|
314
|
+
cd strands-sql
|
|
315
|
+
pip install -e ".[dev]"
|
|
316
|
+
|
|
317
|
+
# Run tests
|
|
318
|
+
pytest
|
|
319
|
+
|
|
320
|
+
# Run tests with coverage
|
|
321
|
+
pytest --cov=strands_sql --cov-report=term-missing
|
|
322
|
+
|
|
323
|
+
# Lint
|
|
324
|
+
ruff check src/ tests/
|
|
325
|
+
|
|
326
|
+
# Type check
|
|
327
|
+
mypy src/strands_sql/
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## License
|
|
331
|
+
|
|
332
|
+
Apache 2.0
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
strands_sql/__init__.py,sha256=fCXJpBrV2UA9m1t8tGeulIMO7fh0DhhNR1xDciiEjUc,164
|
|
2
|
+
strands_sql/models.py,sha256=NN7JhxOfr0fLP9kfjqZPyo2DJCbggM1yluZDsx51aZ8,1751
|
|
3
|
+
strands_sql/sql_database.py,sha256=sg6RkIvLNjcP8vumV3t_vwcM-lCE33MmVz-uVYBCUjc,17072
|
|
4
|
+
strands_sql-0.1.0.dist-info/METADATA,sha256=HfydC7KO1jW-KA8fmB-_JdGmnfd-ZqrbEITg6B7JFEQ,16011
|
|
5
|
+
strands_sql-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
6
|
+
strands_sql-0.1.0.dist-info/licenses/LICENSE,sha256=iARr8i1bT0uMyFB5rmquVCSjoZmduVLtFSgo_zJbLG0,10317
|
|
7
|
+
strands_sql-0.1.0.dist-info/licenses/NOTICE,sha256=O5Ib3JPZOp2wNGhLCzFU8dS6uUsnW-L-N8y_bX8oW2Y,68
|
|
8
|
+
strands_sql-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|