strands-sql 0.1.4__tar.gz → 0.1.7__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: strands-sql
3
- Version: 0.1.4
3
+ Version: 0.1.7
4
4
  Summary: General-purpose SQL tool for Strands agents — supports PostgreSQL, MySQL, and SQLite.
5
5
  Project-URL: Homepage, https://github.com/NithiN-1808/strands-sql
6
6
  Project-URL: Repository, https://github.com/NithiN-1808/strands-sql
@@ -211,7 +211,6 @@ Requires-Dist: psycopg2-binary>=2.9; extra == 'postgres'
211
211
  Description-Content-Type: text/markdown
212
212
 
213
213
  # strands-sql
214
-
215
214
  [![PyPI](https://img.shields.io/pypi/v/strands-sql)](https://pypi.org/project/strands-sql/)
216
215
  [![Python](https://img.shields.io/pypi/pyversions/strands-sql)](https://pypi.org/project/strands-sql/)
217
216
 
@@ -232,25 +231,46 @@ pip install "strands-sql[mysql]"
232
231
 
233
232
  ## Quick Start
234
233
 
235
- ```python
236
- from strands import Agent
237
- from strands_sql import sql_database
234
+ ### Direct Usage
238
235
 
239
- agent = Agent(tools=[sql_database])
236
+ ```python
237
+ from strands_sql import run_sql_database
240
238
 
241
239
  # Discover the schema
242
- agent.tool.sql_database(action="schema_summary")
240
+ run_sql_database(
241
+ action="schema_summary",
242
+ connection_string="sqlite:///./local.db"
243
+ )
243
244
 
244
245
  # Describe a specific table
245
- agent.tool.sql_database(action="describe_table", table="users")
246
+ run_sql_database(
247
+ action="describe_table",
248
+ table="users",
249
+ connection_string="sqlite:///./local.db"
250
+ )
246
251
 
247
252
  # Run a query (returns a markdown table by default)
248
- agent.tool.sql_database(
253
+ run_sql_database(
249
254
  action="query",
250
255
  sql="SELECT * FROM orders WHERE amount > 100 LIMIT 20",
256
+ connection_string="sqlite:///./local.db"
251
257
  )
252
258
  ```
253
259
 
260
+ ### With a Strands Agent
261
+
262
+ ```python
263
+ from strands import Agent
264
+ from strands_sql import sql_database
265
+
266
+ agent = Agent(tools=[sql_database])
267
+
268
+ # The agent decides when and how to invoke the tool
269
+ agent("List all tables in my database")
270
+ agent("Show me all orders above 100")
271
+ agent("How many users are there?")
272
+ ```
273
+
254
274
  ## Configuration
255
275
 
256
276
  ### Connection String
@@ -262,7 +282,7 @@ export DATABASE_URL="postgresql://user:password@localhost:5432/mydb"
262
282
  ```
263
283
 
264
284
  ```python
265
- agent.tool.sql_database(
285
+ run_sql_database(
266
286
  action="list_tables",
267
287
  connection_string="sqlite:///./local.db",
268
288
  )
@@ -281,9 +301,10 @@ agent.tool.sql_database(
281
301
  ## Safety Options
282
302
 
283
303
  ```python
284
- agent.tool.sql_database(
304
+ run_sql_database(
285
305
  action="query",
286
306
  sql="SELECT * FROM users",
307
+ connection_string="sqlite:///./local.db",
287
308
  read_only=True, # Default: True — blocks INSERT/UPDATE/DELETE
288
309
  max_rows=500, # Default: 500 — caps result size
289
310
  timeout=30, # Default: 30s — kills hung queries
@@ -297,6 +318,7 @@ agent.tool.sql_database(
297
318
  | `read_only` | `True` | Blocks all write queries |
298
319
  | `max_rows` | `500` | Maximum rows returned by `query` |
299
320
  | `timeout` | `30` | Query timeout in seconds (1–300) |
321
+ | `output_format` | `markdown` | Output format: `markdown` or `json` |
300
322
  | `allowed_tables` | `None` | Allowlist — only these tables are accessible |
301
323
  | `blocked_tables` | `None` | Blocklist — these tables are never accessible |
302
324
 
@@ -304,10 +326,33 @@ agent.tool.sql_database(
304
326
 
305
327
  ```python
306
328
  # Markdown table (default — great for LLMs)
307
- agent.tool.sql_database(action="query", sql="SELECT * FROM users", output_format="markdown")
329
+ run_sql_database(
330
+ action="query",
331
+ sql="SELECT * FROM users",
332
+ connection_string="sqlite:///./local.db",
333
+ output_format="markdown"
334
+ )
308
335
 
309
336
  # JSON array
310
- agent.tool.sql_database(action="query", sql="SELECT * FROM users", output_format="json")
337
+ run_sql_database(
338
+ action="query",
339
+ sql="SELECT * FROM users",
340
+ connection_string="sqlite:///./local.db",
341
+ output_format="json"
342
+ )
343
+ ```
344
+
345
+ ## Execute (Write Queries)
346
+
347
+ Write queries are blocked by default. To enable:
348
+
349
+ ```python
350
+ run_sql_database(
351
+ action="execute",
352
+ sql="INSERT INTO users (name, age) VALUES ('Eve', 22)",
353
+ connection_string="sqlite:///./local.db",
354
+ read_only=False
355
+ )
311
356
  ```
312
357
 
313
358
  ## Development
@@ -1,5 +1,4 @@
1
1
  # strands-sql
2
-
3
2
  [![PyPI](https://img.shields.io/pypi/v/strands-sql)](https://pypi.org/project/strands-sql/)
4
3
  [![Python](https://img.shields.io/pypi/pyversions/strands-sql)](https://pypi.org/project/strands-sql/)
5
4
 
@@ -20,25 +19,46 @@ pip install "strands-sql[mysql]"
20
19
 
21
20
  ## Quick Start
22
21
 
23
- ```python
24
- from strands import Agent
25
- from strands_sql import sql_database
22
+ ### Direct Usage
26
23
 
27
- agent = Agent(tools=[sql_database])
24
+ ```python
25
+ from strands_sql import run_sql_database
28
26
 
29
27
  # Discover the schema
30
- agent.tool.sql_database(action="schema_summary")
28
+ run_sql_database(
29
+ action="schema_summary",
30
+ connection_string="sqlite:///./local.db"
31
+ )
31
32
 
32
33
  # Describe a specific table
33
- agent.tool.sql_database(action="describe_table", table="users")
34
+ run_sql_database(
35
+ action="describe_table",
36
+ table="users",
37
+ connection_string="sqlite:///./local.db"
38
+ )
34
39
 
35
40
  # Run a query (returns a markdown table by default)
36
- agent.tool.sql_database(
41
+ run_sql_database(
37
42
  action="query",
38
43
  sql="SELECT * FROM orders WHERE amount > 100 LIMIT 20",
44
+ connection_string="sqlite:///./local.db"
39
45
  )
40
46
  ```
41
47
 
48
+ ### With a Strands Agent
49
+
50
+ ```python
51
+ from strands import Agent
52
+ from strands_sql import sql_database
53
+
54
+ agent = Agent(tools=[sql_database])
55
+
56
+ # The agent decides when and how to invoke the tool
57
+ agent("List all tables in my database")
58
+ agent("Show me all orders above 100")
59
+ agent("How many users are there?")
60
+ ```
61
+
42
62
  ## Configuration
43
63
 
44
64
  ### Connection String
@@ -50,7 +70,7 @@ export DATABASE_URL="postgresql://user:password@localhost:5432/mydb"
50
70
  ```
51
71
 
52
72
  ```python
53
- agent.tool.sql_database(
73
+ run_sql_database(
54
74
  action="list_tables",
55
75
  connection_string="sqlite:///./local.db",
56
76
  )
@@ -69,9 +89,10 @@ agent.tool.sql_database(
69
89
  ## Safety Options
70
90
 
71
91
  ```python
72
- agent.tool.sql_database(
92
+ run_sql_database(
73
93
  action="query",
74
94
  sql="SELECT * FROM users",
95
+ connection_string="sqlite:///./local.db",
75
96
  read_only=True, # Default: True — blocks INSERT/UPDATE/DELETE
76
97
  max_rows=500, # Default: 500 — caps result size
77
98
  timeout=30, # Default: 30s — kills hung queries
@@ -85,6 +106,7 @@ agent.tool.sql_database(
85
106
  | `read_only` | `True` | Blocks all write queries |
86
107
  | `max_rows` | `500` | Maximum rows returned by `query` |
87
108
  | `timeout` | `30` | Query timeout in seconds (1–300) |
109
+ | `output_format` | `markdown` | Output format: `markdown` or `json` |
88
110
  | `allowed_tables` | `None` | Allowlist — only these tables are accessible |
89
111
  | `blocked_tables` | `None` | Blocklist — these tables are never accessible |
90
112
 
@@ -92,10 +114,33 @@ agent.tool.sql_database(
92
114
 
93
115
  ```python
94
116
  # Markdown table (default — great for LLMs)
95
- agent.tool.sql_database(action="query", sql="SELECT * FROM users", output_format="markdown")
117
+ run_sql_database(
118
+ action="query",
119
+ sql="SELECT * FROM users",
120
+ connection_string="sqlite:///./local.db",
121
+ output_format="markdown"
122
+ )
96
123
 
97
124
  # JSON array
98
- agent.tool.sql_database(action="query", sql="SELECT * FROM users", output_format="json")
125
+ run_sql_database(
126
+ action="query",
127
+ sql="SELECT * FROM users",
128
+ connection_string="sqlite:///./local.db",
129
+ output_format="json"
130
+ )
131
+ ```
132
+
133
+ ## Execute (Write Queries)
134
+
135
+ Write queries are blocked by default. To enable:
136
+
137
+ ```python
138
+ run_sql_database(
139
+ action="execute",
140
+ sql="INSERT INTO users (name, age) VALUES ('Eve', 22)",
141
+ connection_string="sqlite:///./local.db",
142
+ read_only=False
143
+ )
99
144
  ```
100
145
 
101
146
  ## Development
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "strands-sql"
7
- version = "0.1.4"
7
+ version = "0.1.7"
8
8
  description = "General-purpose SQL tool for Strands agents — supports PostgreSQL, MySQL, and SQLite."
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -114,7 +114,7 @@ def select_components() -> list[str]:
114
114
 
115
115
  def replace_in_file(filepath: str, replacements: dict[str, str]) -> None:
116
116
  """Replace all occurrences in a file."""
117
- with open(filepath, "r", encoding="utf-8") as f:
117
+ with open(filepath, encoding="utf-8") as f:
118
118
  content = f.read()
119
119
 
120
120
  for old, new in replacements.items():
@@ -0,0 +1,5 @@
1
+ """strands-sql — General-purpose SQL tool for Strands agents."""
2
+
3
+ from .sql_database import get_tool, run_sql_database, sql_database
4
+
5
+ __all__ = ["sql_database", "get_tool", "run_sql_database"]
@@ -479,4 +479,26 @@ def sql_database(tool: ToolUse, **kwargs: Any) -> ToolResult:
479
479
  "content": [{"text": result}],
480
480
  }
481
481
  sql_database.TOOL_SPEC = TOOL_SPEC # type: ignore[attr-defined]
482
- sql_database.tool_spec = TOOL_SPEC # type: ignore[attr-defined]
482
+ sql_database.tool_spec = TOOL_SPEC # type: ignore[attr-defined]
483
+
484
+ def get_tool():
485
+ """Return a properly registered Strands Tool."""
486
+ from strands.tools import Tool
487
+
488
+ return Tool.from_function(
489
+ func=sql_database,
490
+ name=TOOL_SPEC["name"],
491
+ description=TOOL_SPEC["description"],
492
+ input_schema=TOOL_SPEC["inputSchema"]["json"],
493
+ )
494
+
495
+
496
+ def run_sql_database(**kwargs):
497
+ """Direct usage without needing ToolUse format."""
498
+ result = sql_database(
499
+ tool={
500
+ "toolUseId": "direct",
501
+ "input": kwargs,
502
+ }
503
+ )
504
+ return result["content"][0]["text"]
@@ -1,5 +0,0 @@
1
- """strands-sql — General-purpose SQL tool for Strands agents."""
2
-
3
- from .sql_database import TOOL_SPEC, sql_database
4
-
5
- __all__ = ["sql_database", "TOOL_SPEC"]
File without changes
File without changes
File without changes
File without changes