dbagent-cli 0.1.8__tar.gz → 0.2.0__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.
- dbagent_cli-0.2.0/PKG-INFO +183 -0
- dbagent_cli-0.2.0/README.md +159 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/__init__.py +1 -1
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/cli.py +14 -14
- dbagent_cli-0.2.0/dbagent_cli.egg-info/PKG-INFO +183 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/pyproject.toml +1 -1
- dbagent_cli-0.1.8/PKG-INFO +0 -242
- dbagent_cli-0.1.8/README.md +0 -218
- dbagent_cli-0.1.8/dbagent_cli.egg-info/PKG-INFO +0 -242
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/agent/generator.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/agent/pipeline.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/agent/validator.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/config.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/connectors/base.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/connectors/factory.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/connectors/mongo.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/connectors/relational.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/llm/auto_setup.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/llm/base.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/llm/factory.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/llm/gemini_provider.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/llm/groq_provider.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/llm/mock_provider.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/llm/ollama_provider.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/llm/openrouter_provider.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/schema/formatter.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/schema/models.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/schema/selector.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/ui/console.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent/ui/viewer.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent_cli.egg-info/SOURCES.txt +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent_cli.egg-info/dependency_links.txt +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent_cli.egg-info/entry_points.txt +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent_cli.egg-info/requires.txt +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/dbagent_cli.egg-info/top_level.txt +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/setup.cfg +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/tests/test_cli.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/tests/test_connectors.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/tests/test_generator.py +0 -0
- {dbagent_cli-0.1.8 → dbagent_cli-0.2.0}/tests/test_schema.py +0 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dbagent-cli
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Universal Database Introspection and Script Generation AI Agent (CLI)
|
|
5
|
+
Author: Santhosh Gupta
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: typer>=0.9.0
|
|
9
|
+
Requires-Dist: rich>=13.0.0
|
|
10
|
+
Requires-Dist: prompt-toolkit>=3.0.0
|
|
11
|
+
Requires-Dist: pydantic>=2.0.0
|
|
12
|
+
Requires-Dist: sqlalchemy>=2.0.0
|
|
13
|
+
Requires-Dist: requests>=2.28.0
|
|
14
|
+
Requires-Dist: httpx>=0.24.0
|
|
15
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
16
|
+
Provides-Extra: all
|
|
17
|
+
Requires-Dist: psycopg2-binary>=2.9.0; extra == "all"
|
|
18
|
+
Requires-Dist: pymysql>=1.0.0; extra == "all"
|
|
19
|
+
Requires-Dist: pymongo>=4.0.0; extra == "all"
|
|
20
|
+
Requires-Dist: duckdb>=0.9.0; extra == "all"
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
23
|
+
Requires-Dist: pytest-asyncio>=0.20.0; extra == "dev"
|
|
24
|
+
|
|
25
|
+
# ⚡ DB-Agent
|
|
26
|
+
|
|
27
|
+
> **Universal Database AI CLI — Ask in plain English, get database results instantly.**
|
|
28
|
+
> *Author: Santhosh Gupta | 100% Free, Standalone, and works Offline (Ollama) or with Free Cloud AI (Gemini / Groq).*
|
|
29
|
+
|
|
30
|
+
[](https://pypi.org/project/dbagent-cli/)
|
|
31
|
+
[](https://pypi.org/project/dbagent-cli/)
|
|
32
|
+
[](https://opensource.org/licenses/MIT)
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 🚀 2-Minute Quickstart
|
|
37
|
+
|
|
38
|
+
### Step 1: Install from PyPI
|
|
39
|
+
Open your terminal (PowerShell, Command Prompt, or Bash) and run:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install "dbagent-cli[all]"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
### Step 2: Run 1-Click AI Setup
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
db-agent setup
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The interactive wizard gives you 3 options:
|
|
54
|
+
1. **Local Offline AI (Ollama)**: Automatically downloads and installs local Ollama and the `qwen2.5-coder` model. Zero API keys, 100% private, works offline.
|
|
55
|
+
2. **Free Cloud AI (Gemini / Groq)**: Enter your free API key for instant cloud processing.
|
|
56
|
+
3. **Normal Database CLI**: Use standard database tools (connect, scan, raw SQL) without AI.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
### Step 3: Connect Your Database & Save an Alias
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
db-agent connect postgresql://user:password@localhost:5432/mydb --alias my_db
|
|
64
|
+
```
|
|
65
|
+
*(Supports PostgreSQL, MySQL, SQLite, SQL Server, Oracle, DuckDB, and MongoDB).*
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
### Step 4: Ask Questions in Plain English!
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# 1. Ask a question and get instant live results table
|
|
73
|
+
db-agent ask "list top 10 recent users" --db my_db
|
|
74
|
+
|
|
75
|
+
# 2. Or start the interactive database shell
|
|
76
|
+
db-agent chat --db my_db
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## 📖 Complete Command Reference
|
|
82
|
+
|
|
83
|
+
| Command | How to Use | When to Use |
|
|
84
|
+
|---|---|---|
|
|
85
|
+
| **`ask`** | `db-agent ask "show top 10 users" --db my_db` | **Primary query tool.** Translates English to SQL, executes automatically, and shows live results. |
|
|
86
|
+
| **`chat`** | `db-agent chat --db my_db` | **Interactive terminal shell.** Type questions, inspect tables, and switch models on the fly. |
|
|
87
|
+
| **`connect`** | `db-agent connect <url> --alias my_db` | **Save connection.** Validates credentials in `< 0.1s` and saves an alias name. |
|
|
88
|
+
| **`scan`** | `db-agent scan --db my_db --export db.md` | **Schema catalog.** Discovers tables, columns, relations, indexes, and exports to Markdown/JSON. |
|
|
89
|
+
| **`use`** | `db-agent use gemini` | **Switch AI provider.** Switch default AI between `ollama`, `gemini`, `groq`, and `openrouter`. |
|
|
90
|
+
| **`run`** | `db-agent run "SELECT * FROM users" --db my_db` | **Direct SQL execution.** Run raw SQL directly with formatted table output. |
|
|
91
|
+
| **`generate`**| `db-agent generate "ETL pipeline" --db my_db -o etl.py` | **Code generation.** Export SQL, Alembic migrations, Python ETL, or FastAPI REST APIs to files. |
|
|
92
|
+
| **`setup`** | `db-agent setup` | **AI setup wizard.** 1-click installer for local Ollama or cloud provider configuration. |
|
|
93
|
+
| **`config`** | `db-agent config` | **Settings wizard.** Configure API keys, default models, and database profiles. |
|
|
94
|
+
| **`profiles`**| `db-agent profiles` | **Saved databases.** List all configured database aliases and connection URLs. |
|
|
95
|
+
| **`models`** | `db-agent models` | **Engine health check.** Check Online/Offline status of local and cloud models. |
|
|
96
|
+
| **`guide`** | `db-agent guide` | **In-terminal reference.** Display interactive command cheatsheet. |
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## 💬 Interactive Chat Shell (`db-agent chat`)
|
|
101
|
+
|
|
102
|
+
Launch the interactive REPL with `db-agent chat --db <alias>`.
|
|
103
|
+
|
|
104
|
+
Inside the chat session, you can ask questions in plain English or use built-in `:` commands:
|
|
105
|
+
|
|
106
|
+
```text
|
|
107
|
+
db-agent> list top 10 users with email and created_time from ivis_users
|
|
108
|
+
┌─────┬──────────────────────────┬─────────────────────────────┐
|
|
109
|
+
│ id │ email │ created_time │
|
|
110
|
+
├─────┼──────────────────────────┼─────────────────────────────┤
|
|
111
|
+
│ 101 │ john.doe@example.com │ 2026-08-28 17:30:00+00:00 │
|
|
112
|
+
│ 102 │ jane.smith@example.com │ 2026-08-28 17:15:00+00:00 │
|
|
113
|
+
└─────┴──────────────────────────┴─────────────────────────────┘
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### In-Chat Special Commands:
|
|
117
|
+
|
|
118
|
+
* **`:help`** — Show all in-chat commands.
|
|
119
|
+
* **`:tables`** — List all tables in the connected database.
|
|
120
|
+
* **`:table <name>`** — Inspect table columns, primary keys, data types, and sample rows.
|
|
121
|
+
* **`:fk <name>`** — View all mapped foreign keys and related tables (incoming and outgoing).
|
|
122
|
+
* **`:provider <name>`** — Switch AI provider on the fly (`ollama`, `gemini`, `groq`, `openrouter`).
|
|
123
|
+
* **`:model <name>`** — Switch active model name on the fly (e.g. `:model gemini-3.6-flash`).
|
|
124
|
+
* **`:models`** — View active AI engine and available models.
|
|
125
|
+
* **`:explain`** — View the SQL query and table matches generated for your last question.
|
|
126
|
+
* **`:history`** — View the history of queries executed in this session.
|
|
127
|
+
* **`:auto` / `:noauto`** — Toggle automatic execution of read queries.
|
|
128
|
+
* **`:run`** — Re-execute the last generated SQL query.
|
|
129
|
+
* **`:export <file>`** — Save the last generated SQL to a file.
|
|
130
|
+
* **`:exit`** — Exit the chat session.
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## 🔌 Supported Databases & Connection Examples
|
|
135
|
+
|
|
136
|
+
DB-Agent supports all major relational and NoSQL databases:
|
|
137
|
+
|
|
138
|
+
| Database | Connection URL Format |
|
|
139
|
+
|---|---|
|
|
140
|
+
| **PostgreSQL** | `postgresql://user:pass@localhost:5432/dbname` |
|
|
141
|
+
| **MySQL / MariaDB** | `mysql+pymysql://user:pass@localhost:3306/dbname` |
|
|
142
|
+
| **SQLite** | `sqlite:///path/to/database.db` or just `database.db` |
|
|
143
|
+
| **Microsoft SQL Server** | `mssql+pyodbc://user:pass@server/dbname?driver=ODBC+Driver+17+for+SQL+Server` |
|
|
144
|
+
| **Oracle** | `oracle+cx_oracle://user:pass@localhost:1521/?service_name=ORCLPDB1` |
|
|
145
|
+
| **DuckDB** | `duckdb:///path/to/analytics.duckdb` |
|
|
146
|
+
| **MongoDB** | `mongodb://user:pass@localhost:27017/dbname` |
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## 🤖 Supported AI Providers (100% Free Options)
|
|
151
|
+
|
|
152
|
+
| Provider | Type | API Key Needed? | Speed | Setup |
|
|
153
|
+
|---|---|---|---|---|
|
|
154
|
+
| **Ollama** | Local & Offline | **No** (Zero keys) | Fast (Local GPU/CPU) | `db-agent setup` |
|
|
155
|
+
| **Google Gemini** | Cloud (Free Tier) | Free key at [aistudio.google.com](https://aistudio.google.com/apikey) | Very Fast | `db-agent config` |
|
|
156
|
+
| **Groq** | Cloud (Free Tier) | Free key at [console.groq.com](https://console.groq.com) | Ultra-Fast | `db-agent config` |
|
|
157
|
+
| **OpenRouter** | Cloud (Free Models) | Free key at [openrouter.ai](https://openrouter.ai) | Standard | `db-agent config` |
|
|
158
|
+
|
|
159
|
+
### Switch Providers Anytime:
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
# Switch to Google Gemini
|
|
163
|
+
db-agent use gemini
|
|
164
|
+
|
|
165
|
+
# Switch to local Ollama (Offline)
|
|
166
|
+
db-agent use ollama
|
|
167
|
+
|
|
168
|
+
# Switch to Groq
|
|
169
|
+
db-agent use groq
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## 🛡️ Safety & Auto-Execution Rules
|
|
175
|
+
|
|
176
|
+
* **Read Queries (`SELECT`, `SHOW`, `EXPLAIN`)**: Automatically executed for high productivity.
|
|
177
|
+
* **Write/DDL Queries (`INSERT`, `UPDATE`, `DELETE`, `DROP`, `ALTER`)**: DB-Agent detects destructive statements and **prompts you for explicit confirmation** before running. Pass `--force` to bypass confirmation if desired.
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## 📄 License
|
|
182
|
+
|
|
183
|
+
MIT License © 2026 Santhosh Gupta.
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# ⚡ DB-Agent
|
|
2
|
+
|
|
3
|
+
> **Universal Database AI CLI — Ask in plain English, get database results instantly.**
|
|
4
|
+
> *Author: Santhosh Gupta | 100% Free, Standalone, and works Offline (Ollama) or with Free Cloud AI (Gemini / Groq).*
|
|
5
|
+
|
|
6
|
+
[](https://pypi.org/project/dbagent-cli/)
|
|
7
|
+
[](https://pypi.org/project/dbagent-cli/)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 🚀 2-Minute Quickstart
|
|
13
|
+
|
|
14
|
+
### Step 1: Install from PyPI
|
|
15
|
+
Open your terminal (PowerShell, Command Prompt, or Bash) and run:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install "dbagent-cli[all]"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
### Step 2: Run 1-Click AI Setup
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
db-agent setup
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The interactive wizard gives you 3 options:
|
|
30
|
+
1. **Local Offline AI (Ollama)**: Automatically downloads and installs local Ollama and the `qwen2.5-coder` model. Zero API keys, 100% private, works offline.
|
|
31
|
+
2. **Free Cloud AI (Gemini / Groq)**: Enter your free API key for instant cloud processing.
|
|
32
|
+
3. **Normal Database CLI**: Use standard database tools (connect, scan, raw SQL) without AI.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
### Step 3: Connect Your Database & Save an Alias
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
db-agent connect postgresql://user:password@localhost:5432/mydb --alias my_db
|
|
40
|
+
```
|
|
41
|
+
*(Supports PostgreSQL, MySQL, SQLite, SQL Server, Oracle, DuckDB, and MongoDB).*
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
### Step 4: Ask Questions in Plain English!
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# 1. Ask a question and get instant live results table
|
|
49
|
+
db-agent ask "list top 10 recent users" --db my_db
|
|
50
|
+
|
|
51
|
+
# 2. Or start the interactive database shell
|
|
52
|
+
db-agent chat --db my_db
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 📖 Complete Command Reference
|
|
58
|
+
|
|
59
|
+
| Command | How to Use | When to Use |
|
|
60
|
+
|---|---|---|
|
|
61
|
+
| **`ask`** | `db-agent ask "show top 10 users" --db my_db` | **Primary query tool.** Translates English to SQL, executes automatically, and shows live results. |
|
|
62
|
+
| **`chat`** | `db-agent chat --db my_db` | **Interactive terminal shell.** Type questions, inspect tables, and switch models on the fly. |
|
|
63
|
+
| **`connect`** | `db-agent connect <url> --alias my_db` | **Save connection.** Validates credentials in `< 0.1s` and saves an alias name. |
|
|
64
|
+
| **`scan`** | `db-agent scan --db my_db --export db.md` | **Schema catalog.** Discovers tables, columns, relations, indexes, and exports to Markdown/JSON. |
|
|
65
|
+
| **`use`** | `db-agent use gemini` | **Switch AI provider.** Switch default AI between `ollama`, `gemini`, `groq`, and `openrouter`. |
|
|
66
|
+
| **`run`** | `db-agent run "SELECT * FROM users" --db my_db` | **Direct SQL execution.** Run raw SQL directly with formatted table output. |
|
|
67
|
+
| **`generate`**| `db-agent generate "ETL pipeline" --db my_db -o etl.py` | **Code generation.** Export SQL, Alembic migrations, Python ETL, or FastAPI REST APIs to files. |
|
|
68
|
+
| **`setup`** | `db-agent setup` | **AI setup wizard.** 1-click installer for local Ollama or cloud provider configuration. |
|
|
69
|
+
| **`config`** | `db-agent config` | **Settings wizard.** Configure API keys, default models, and database profiles. |
|
|
70
|
+
| **`profiles`**| `db-agent profiles` | **Saved databases.** List all configured database aliases and connection URLs. |
|
|
71
|
+
| **`models`** | `db-agent models` | **Engine health check.** Check Online/Offline status of local and cloud models. |
|
|
72
|
+
| **`guide`** | `db-agent guide` | **In-terminal reference.** Display interactive command cheatsheet. |
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## 💬 Interactive Chat Shell (`db-agent chat`)
|
|
77
|
+
|
|
78
|
+
Launch the interactive REPL with `db-agent chat --db <alias>`.
|
|
79
|
+
|
|
80
|
+
Inside the chat session, you can ask questions in plain English or use built-in `:` commands:
|
|
81
|
+
|
|
82
|
+
```text
|
|
83
|
+
db-agent> list top 10 users with email and created_time from ivis_users
|
|
84
|
+
┌─────┬──────────────────────────┬─────────────────────────────┐
|
|
85
|
+
│ id │ email │ created_time │
|
|
86
|
+
├─────┼──────────────────────────┼─────────────────────────────┤
|
|
87
|
+
│ 101 │ john.doe@example.com │ 2026-08-28 17:30:00+00:00 │
|
|
88
|
+
│ 102 │ jane.smith@example.com │ 2026-08-28 17:15:00+00:00 │
|
|
89
|
+
└─────┴──────────────────────────┴─────────────────────────────┘
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### In-Chat Special Commands:
|
|
93
|
+
|
|
94
|
+
* **`:help`** — Show all in-chat commands.
|
|
95
|
+
* **`:tables`** — List all tables in the connected database.
|
|
96
|
+
* **`:table <name>`** — Inspect table columns, primary keys, data types, and sample rows.
|
|
97
|
+
* **`:fk <name>`** — View all mapped foreign keys and related tables (incoming and outgoing).
|
|
98
|
+
* **`:provider <name>`** — Switch AI provider on the fly (`ollama`, `gemini`, `groq`, `openrouter`).
|
|
99
|
+
* **`:model <name>`** — Switch active model name on the fly (e.g. `:model gemini-3.6-flash`).
|
|
100
|
+
* **`:models`** — View active AI engine and available models.
|
|
101
|
+
* **`:explain`** — View the SQL query and table matches generated for your last question.
|
|
102
|
+
* **`:history`** — View the history of queries executed in this session.
|
|
103
|
+
* **`:auto` / `:noauto`** — Toggle automatic execution of read queries.
|
|
104
|
+
* **`:run`** — Re-execute the last generated SQL query.
|
|
105
|
+
* **`:export <file>`** — Save the last generated SQL to a file.
|
|
106
|
+
* **`:exit`** — Exit the chat session.
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## 🔌 Supported Databases & Connection Examples
|
|
111
|
+
|
|
112
|
+
DB-Agent supports all major relational and NoSQL databases:
|
|
113
|
+
|
|
114
|
+
| Database | Connection URL Format |
|
|
115
|
+
|---|---|
|
|
116
|
+
| **PostgreSQL** | `postgresql://user:pass@localhost:5432/dbname` |
|
|
117
|
+
| **MySQL / MariaDB** | `mysql+pymysql://user:pass@localhost:3306/dbname` |
|
|
118
|
+
| **SQLite** | `sqlite:///path/to/database.db` or just `database.db` |
|
|
119
|
+
| **Microsoft SQL Server** | `mssql+pyodbc://user:pass@server/dbname?driver=ODBC+Driver+17+for+SQL+Server` |
|
|
120
|
+
| **Oracle** | `oracle+cx_oracle://user:pass@localhost:1521/?service_name=ORCLPDB1` |
|
|
121
|
+
| **DuckDB** | `duckdb:///path/to/analytics.duckdb` |
|
|
122
|
+
| **MongoDB** | `mongodb://user:pass@localhost:27017/dbname` |
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## 🤖 Supported AI Providers (100% Free Options)
|
|
127
|
+
|
|
128
|
+
| Provider | Type | API Key Needed? | Speed | Setup |
|
|
129
|
+
|---|---|---|---|---|
|
|
130
|
+
| **Ollama** | Local & Offline | **No** (Zero keys) | Fast (Local GPU/CPU) | `db-agent setup` |
|
|
131
|
+
| **Google Gemini** | Cloud (Free Tier) | Free key at [aistudio.google.com](https://aistudio.google.com/apikey) | Very Fast | `db-agent config` |
|
|
132
|
+
| **Groq** | Cloud (Free Tier) | Free key at [console.groq.com](https://console.groq.com) | Ultra-Fast | `db-agent config` |
|
|
133
|
+
| **OpenRouter** | Cloud (Free Models) | Free key at [openrouter.ai](https://openrouter.ai) | Standard | `db-agent config` |
|
|
134
|
+
|
|
135
|
+
### Switch Providers Anytime:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# Switch to Google Gemini
|
|
139
|
+
db-agent use gemini
|
|
140
|
+
|
|
141
|
+
# Switch to local Ollama (Offline)
|
|
142
|
+
db-agent use ollama
|
|
143
|
+
|
|
144
|
+
# Switch to Groq
|
|
145
|
+
db-agent use groq
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## 🛡️ Safety & Auto-Execution Rules
|
|
151
|
+
|
|
152
|
+
* **Read Queries (`SELECT`, `SHOW`, `EXPLAIN`)**: Automatically executed for high productivity.
|
|
153
|
+
* **Write/DDL Queries (`INSERT`, `UPDATE`, `DELETE`, `DROP`, `ALTER`)**: DB-Agent detects destructive statements and **prompts you for explicit confirmation** before running. Pass `--force` to bypass confirmation if desired.
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## 📄 License
|
|
158
|
+
|
|
159
|
+
MIT License © 2026 Santhosh Gupta.
|
|
@@ -787,30 +787,30 @@ def config_command():
|
|
|
787
787
|
config_mgr.set_setting("default_provider", provider_choice)
|
|
788
788
|
print_success(f"Default provider updated to [bold]{provider_choice}[/bold]")
|
|
789
789
|
|
|
790
|
-
if provider_choice == "gemini"
|
|
791
|
-
|
|
790
|
+
if provider_choice == "gemini":
|
|
791
|
+
console.print("[dim]Get your free Gemini API key at: [bold]https://aistudio.google.com/apikey[/bold][/dim]")
|
|
792
|
+
key = Prompt.ask("Enter GEMINI_API_KEY", default=config_mgr.get_setting("gemini_api_key", "")).strip()
|
|
792
793
|
if key:
|
|
793
794
|
config_mgr.set_setting("gemini_api_key", key)
|
|
794
795
|
print_success("Gemini API key saved.")
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
key = Prompt.ask("Enter GROQ_API_KEY
|
|
796
|
+
elif provider_choice == "groq":
|
|
797
|
+
console.print("[dim]Get your free Groq API key at: [bold]https://console.groq.com[/bold][/dim]")
|
|
798
|
+
key = Prompt.ask("Enter GROQ_API_KEY", default=config_mgr.get_setting("groq_api_key", "")).strip()
|
|
798
799
|
if key:
|
|
799
800
|
config_mgr.set_setting("groq_api_key", key)
|
|
800
801
|
print_success("Groq API key saved.")
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
key = Prompt.ask("Enter OPENROUTER_API_KEY
|
|
802
|
+
elif provider_choice == "openrouter":
|
|
803
|
+
console.print("[dim]Get your OpenRouter API key at: [bold]https://openrouter.ai[/bold][/dim]")
|
|
804
|
+
key = Prompt.ask("Enter OPENROUTER_API_KEY", default=config_mgr.get_setting("openrouter_api_key", "")).strip()
|
|
804
805
|
if key:
|
|
805
806
|
config_mgr.set_setting("openrouter_api_key", key)
|
|
806
807
|
print_success("OpenRouter API key saved.")
|
|
808
|
+
elif provider_choice == "ollama":
|
|
809
|
+
base_url = Prompt.ask("Ollama Base URL", default=config_mgr.get_setting("ollama_base_url", "http://localhost:11434")).strip()
|
|
810
|
+
config_mgr.set_setting("ollama_base_url", base_url)
|
|
811
|
+
print_success("Ollama base URL configured.")
|
|
807
812
|
|
|
808
|
-
|
|
809
|
-
p_name = Prompt.ask("Profile Name (e.g. prod_pg, staging, local_dev)")
|
|
810
|
-
p_url = Prompt.ask("Connection URL (e.g. postgresql://user:pass@localhost:5432/dbname)")
|
|
811
|
-
p_desc = Prompt.ask("Description", default=f"{p_name} database")
|
|
812
|
-
config_mgr.save_profile(name=p_name, connection_url=p_url, description=p_desc)
|
|
813
|
-
print_success(f"Profile '[bold]{p_name}[/bold]' saved successfully!")
|
|
813
|
+
print_success("Configuration updated successfully!\n")
|
|
814
814
|
|
|
815
815
|
|
|
816
816
|
# ---- profiles ----
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dbagent-cli
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Universal Database Introspection and Script Generation AI Agent (CLI)
|
|
5
|
+
Author: Santhosh Gupta
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: typer>=0.9.0
|
|
9
|
+
Requires-Dist: rich>=13.0.0
|
|
10
|
+
Requires-Dist: prompt-toolkit>=3.0.0
|
|
11
|
+
Requires-Dist: pydantic>=2.0.0
|
|
12
|
+
Requires-Dist: sqlalchemy>=2.0.0
|
|
13
|
+
Requires-Dist: requests>=2.28.0
|
|
14
|
+
Requires-Dist: httpx>=0.24.0
|
|
15
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
16
|
+
Provides-Extra: all
|
|
17
|
+
Requires-Dist: psycopg2-binary>=2.9.0; extra == "all"
|
|
18
|
+
Requires-Dist: pymysql>=1.0.0; extra == "all"
|
|
19
|
+
Requires-Dist: pymongo>=4.0.0; extra == "all"
|
|
20
|
+
Requires-Dist: duckdb>=0.9.0; extra == "all"
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
23
|
+
Requires-Dist: pytest-asyncio>=0.20.0; extra == "dev"
|
|
24
|
+
|
|
25
|
+
# ⚡ DB-Agent
|
|
26
|
+
|
|
27
|
+
> **Universal Database AI CLI — Ask in plain English, get database results instantly.**
|
|
28
|
+
> *Author: Santhosh Gupta | 100% Free, Standalone, and works Offline (Ollama) or with Free Cloud AI (Gemini / Groq).*
|
|
29
|
+
|
|
30
|
+
[](https://pypi.org/project/dbagent-cli/)
|
|
31
|
+
[](https://pypi.org/project/dbagent-cli/)
|
|
32
|
+
[](https://opensource.org/licenses/MIT)
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 🚀 2-Minute Quickstart
|
|
37
|
+
|
|
38
|
+
### Step 1: Install from PyPI
|
|
39
|
+
Open your terminal (PowerShell, Command Prompt, or Bash) and run:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install "dbagent-cli[all]"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
### Step 2: Run 1-Click AI Setup
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
db-agent setup
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The interactive wizard gives you 3 options:
|
|
54
|
+
1. **Local Offline AI (Ollama)**: Automatically downloads and installs local Ollama and the `qwen2.5-coder` model. Zero API keys, 100% private, works offline.
|
|
55
|
+
2. **Free Cloud AI (Gemini / Groq)**: Enter your free API key for instant cloud processing.
|
|
56
|
+
3. **Normal Database CLI**: Use standard database tools (connect, scan, raw SQL) without AI.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
### Step 3: Connect Your Database & Save an Alias
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
db-agent connect postgresql://user:password@localhost:5432/mydb --alias my_db
|
|
64
|
+
```
|
|
65
|
+
*(Supports PostgreSQL, MySQL, SQLite, SQL Server, Oracle, DuckDB, and MongoDB).*
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
### Step 4: Ask Questions in Plain English!
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# 1. Ask a question and get instant live results table
|
|
73
|
+
db-agent ask "list top 10 recent users" --db my_db
|
|
74
|
+
|
|
75
|
+
# 2. Or start the interactive database shell
|
|
76
|
+
db-agent chat --db my_db
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## 📖 Complete Command Reference
|
|
82
|
+
|
|
83
|
+
| Command | How to Use | When to Use |
|
|
84
|
+
|---|---|---|
|
|
85
|
+
| **`ask`** | `db-agent ask "show top 10 users" --db my_db` | **Primary query tool.** Translates English to SQL, executes automatically, and shows live results. |
|
|
86
|
+
| **`chat`** | `db-agent chat --db my_db` | **Interactive terminal shell.** Type questions, inspect tables, and switch models on the fly. |
|
|
87
|
+
| **`connect`** | `db-agent connect <url> --alias my_db` | **Save connection.** Validates credentials in `< 0.1s` and saves an alias name. |
|
|
88
|
+
| **`scan`** | `db-agent scan --db my_db --export db.md` | **Schema catalog.** Discovers tables, columns, relations, indexes, and exports to Markdown/JSON. |
|
|
89
|
+
| **`use`** | `db-agent use gemini` | **Switch AI provider.** Switch default AI between `ollama`, `gemini`, `groq`, and `openrouter`. |
|
|
90
|
+
| **`run`** | `db-agent run "SELECT * FROM users" --db my_db` | **Direct SQL execution.** Run raw SQL directly with formatted table output. |
|
|
91
|
+
| **`generate`**| `db-agent generate "ETL pipeline" --db my_db -o etl.py` | **Code generation.** Export SQL, Alembic migrations, Python ETL, or FastAPI REST APIs to files. |
|
|
92
|
+
| **`setup`** | `db-agent setup` | **AI setup wizard.** 1-click installer for local Ollama or cloud provider configuration. |
|
|
93
|
+
| **`config`** | `db-agent config` | **Settings wizard.** Configure API keys, default models, and database profiles. |
|
|
94
|
+
| **`profiles`**| `db-agent profiles` | **Saved databases.** List all configured database aliases and connection URLs. |
|
|
95
|
+
| **`models`** | `db-agent models` | **Engine health check.** Check Online/Offline status of local and cloud models. |
|
|
96
|
+
| **`guide`** | `db-agent guide` | **In-terminal reference.** Display interactive command cheatsheet. |
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## 💬 Interactive Chat Shell (`db-agent chat`)
|
|
101
|
+
|
|
102
|
+
Launch the interactive REPL with `db-agent chat --db <alias>`.
|
|
103
|
+
|
|
104
|
+
Inside the chat session, you can ask questions in plain English or use built-in `:` commands:
|
|
105
|
+
|
|
106
|
+
```text
|
|
107
|
+
db-agent> list top 10 users with email and created_time from ivis_users
|
|
108
|
+
┌─────┬──────────────────────────┬─────────────────────────────┐
|
|
109
|
+
│ id │ email │ created_time │
|
|
110
|
+
├─────┼──────────────────────────┼─────────────────────────────┤
|
|
111
|
+
│ 101 │ john.doe@example.com │ 2026-08-28 17:30:00+00:00 │
|
|
112
|
+
│ 102 │ jane.smith@example.com │ 2026-08-28 17:15:00+00:00 │
|
|
113
|
+
└─────┴──────────────────────────┴─────────────────────────────┘
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### In-Chat Special Commands:
|
|
117
|
+
|
|
118
|
+
* **`:help`** — Show all in-chat commands.
|
|
119
|
+
* **`:tables`** — List all tables in the connected database.
|
|
120
|
+
* **`:table <name>`** — Inspect table columns, primary keys, data types, and sample rows.
|
|
121
|
+
* **`:fk <name>`** — View all mapped foreign keys and related tables (incoming and outgoing).
|
|
122
|
+
* **`:provider <name>`** — Switch AI provider on the fly (`ollama`, `gemini`, `groq`, `openrouter`).
|
|
123
|
+
* **`:model <name>`** — Switch active model name on the fly (e.g. `:model gemini-3.6-flash`).
|
|
124
|
+
* **`:models`** — View active AI engine and available models.
|
|
125
|
+
* **`:explain`** — View the SQL query and table matches generated for your last question.
|
|
126
|
+
* **`:history`** — View the history of queries executed in this session.
|
|
127
|
+
* **`:auto` / `:noauto`** — Toggle automatic execution of read queries.
|
|
128
|
+
* **`:run`** — Re-execute the last generated SQL query.
|
|
129
|
+
* **`:export <file>`** — Save the last generated SQL to a file.
|
|
130
|
+
* **`:exit`** — Exit the chat session.
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## 🔌 Supported Databases & Connection Examples
|
|
135
|
+
|
|
136
|
+
DB-Agent supports all major relational and NoSQL databases:
|
|
137
|
+
|
|
138
|
+
| Database | Connection URL Format |
|
|
139
|
+
|---|---|
|
|
140
|
+
| **PostgreSQL** | `postgresql://user:pass@localhost:5432/dbname` |
|
|
141
|
+
| **MySQL / MariaDB** | `mysql+pymysql://user:pass@localhost:3306/dbname` |
|
|
142
|
+
| **SQLite** | `sqlite:///path/to/database.db` or just `database.db` |
|
|
143
|
+
| **Microsoft SQL Server** | `mssql+pyodbc://user:pass@server/dbname?driver=ODBC+Driver+17+for+SQL+Server` |
|
|
144
|
+
| **Oracle** | `oracle+cx_oracle://user:pass@localhost:1521/?service_name=ORCLPDB1` |
|
|
145
|
+
| **DuckDB** | `duckdb:///path/to/analytics.duckdb` |
|
|
146
|
+
| **MongoDB** | `mongodb://user:pass@localhost:27017/dbname` |
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## 🤖 Supported AI Providers (100% Free Options)
|
|
151
|
+
|
|
152
|
+
| Provider | Type | API Key Needed? | Speed | Setup |
|
|
153
|
+
|---|---|---|---|---|
|
|
154
|
+
| **Ollama** | Local & Offline | **No** (Zero keys) | Fast (Local GPU/CPU) | `db-agent setup` |
|
|
155
|
+
| **Google Gemini** | Cloud (Free Tier) | Free key at [aistudio.google.com](https://aistudio.google.com/apikey) | Very Fast | `db-agent config` |
|
|
156
|
+
| **Groq** | Cloud (Free Tier) | Free key at [console.groq.com](https://console.groq.com) | Ultra-Fast | `db-agent config` |
|
|
157
|
+
| **OpenRouter** | Cloud (Free Models) | Free key at [openrouter.ai](https://openrouter.ai) | Standard | `db-agent config` |
|
|
158
|
+
|
|
159
|
+
### Switch Providers Anytime:
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
# Switch to Google Gemini
|
|
163
|
+
db-agent use gemini
|
|
164
|
+
|
|
165
|
+
# Switch to local Ollama (Offline)
|
|
166
|
+
db-agent use ollama
|
|
167
|
+
|
|
168
|
+
# Switch to Groq
|
|
169
|
+
db-agent use groq
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## 🛡️ Safety & Auto-Execution Rules
|
|
175
|
+
|
|
176
|
+
* **Read Queries (`SELECT`, `SHOW`, `EXPLAIN`)**: Automatically executed for high productivity.
|
|
177
|
+
* **Write/DDL Queries (`INSERT`, `UPDATE`, `DELETE`, `DROP`, `ALTER`)**: DB-Agent detects destructive statements and **prompts you for explicit confirmation** before running. Pass `--force` to bypass confirmation if desired.
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## 📄 License
|
|
182
|
+
|
|
183
|
+
MIT License © 2026 Santhosh Gupta.
|