dbagent-cli 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.
@@ -0,0 +1,242 @@
1
+ Metadata-Version: 2.4
2
+ Name: dbagent-cli
3
+ Version: 0.1.0
4
+ Summary: Universal Database Introspection and Script Generation AI Agent (CLI)
5
+ Author: DB-Agent Team
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 Introspector & AI Script Generator CLI**
28
+ > *100% Free, Standalone, and runs with Local (Ollama) or Free Cloud AI models.*
29
+
30
+ `db-agent` connects to any database using provided credentials or connection URLs, introspects the complete schema (tables, columns, data types, primary/foreign keys, indexes, and sample values), and generates dialect-specific SQL queries, migrations, ETL data pipelines, and backend APIs from natural language instructions.
31
+
32
+ ---
33
+
34
+ ## ๐ŸŒŸ Key Features
35
+
36
+ - **Universal Database Support**:
37
+ - **Relational**: PostgreSQL, MySQL, MariaDB, SQLite, Microsoft SQL Server (MSSQL), Oracle, DuckDB, Snowflake.
38
+ - **Document DBs**: MongoDB (schema inference via document sampling).
39
+ - **100% Free & Standalone AI Engine**:
40
+ - **Ollama (Local & Offline)**: Zero cost, private, runs on your machine (`qwen2.5-coder`, `llama3.2`, `deepseek-r1`, `mistral`).
41
+ - **Google Gemini (Free Tier)**: Direct access to `gemini-2.0-flash` & `gemini-1.5-flash`.
42
+ - **Groq (Free Ultra-Fast Tier)**: `llama-3.3-70b-versatile`, `qwen-2.5-32b`.
43
+ - **OpenRouter (Free Community Models)**: Free open models.
44
+ - **Deep Schema Introspection**:
45
+ - Auto-discovers tables, views, primary keys, foreign key relations, unique/composite indexes, nullability, defaults, comments, and row counts.
46
+ - Generates schema catalogs in Rich terminal tables, Markdown, or JSON.
47
+ - **Smart Script & Code Generation**:
48
+ - **Dialect-Specific SQL**: Joins, subqueries, CTEs, window functions.
49
+ - **Database Migrations**: Alembic (Python), Flyway, Prisma, raw SQL DDL.
50
+ - **ETL & Data Pipelines**: Python (Pandas/Polars/SQLAlchemy), CSV/JSON exporters.
51
+ - **Backend REST APIs**: FastAPI CRUD endpoints, Pydantic schemas.
52
+ - **Interactive Multi-Turn REPL & Safe Execution**:
53
+ - Multi-turn terminal chat with live database schema loaded in memory.
54
+ - Safe query dry-run and results preview with detection of destructive statements.
55
+
56
+ ---
57
+
58
+ ## ๐Ÿš€ Quick Start
59
+
60
+ ### 1. Installation
61
+
62
+ ```bash
63
+ # Clone the repository
64
+ cd fearless-fermi
65
+
66
+ # Install dependencies and editable CLI package
67
+ pip install -e .
68
+ ```
69
+
70
+ ### 2. Supported AI Providers (Zero Cost)
71
+
72
+ You can run DB-Agent using any free option:
73
+
74
+ | Provider | Type | Setup | Recommended Model |
75
+ |---|---|---|---|
76
+ | **Ollama** | 100% Local & Offline | Run `ollama serve` | `qwen2.5-coder` or `llama3.2` |
77
+ | **Google Gemini** | Free Cloud API | Get free key at [Google AI Studio](https://aistudio.google.com) | `gemini-2.0-flash` |
78
+ | **Groq** | Free Fast Cloud API | Get free key at [Groq Console](https://console.groq.com) | `llama-3.3-70b-versatile` |
79
+ | **OpenRouter** | Free Open Models | Get free key at [OpenRouter](https://openrouter.ai) | `meta-llama/llama-3.3-70b-instruct:free` |
80
+
81
+ Set keys via environment variables or use the interactive setup wizard:
82
+ ```bash
83
+ # Interactive setup wizard
84
+ db-agent config
85
+
86
+ # Or set directly in your shell / .env file
87
+ export GEMINI_API_KEY="your-gemini-api-key"
88
+ # or
89
+ export GROQ_API_KEY="your-groq-api-key"
90
+ ```
91
+
92
+ ---
93
+
94
+ ## ๐Ÿ’ป CLI Commands & Usage
95
+
96
+ ### 1. Connect & Save with an Alias (`connect` or `--alias`)
97
+
98
+ Save your connection credentials under an alias so you don't need to retype the URL each time:
99
+
100
+ ```bash
101
+ # Connect and save with an alias name
102
+ db-agent connect postgresql://user:password@localhost:5432/mydb --alias prod_db
103
+
104
+ # Connect to a local SQLite file with an alias
105
+ db-agent connect ecommerce_demo.db --alias my_shop
106
+
107
+ # Or scan and save alias in one step
108
+ db-agent scan --db postgresql://user:pass@localhost:5432/analytics --alias analytics_db
109
+ ```
110
+
111
+ After saving with an alias, you can use that alias directly anywhere in place of the connection URL:
112
+ ```bash
113
+ db-agent scan --db prod_db
114
+ db-agent chat --db prod_db
115
+ db-agent generate "Show total revenue this month" --db prod_db
116
+ ```
117
+
118
+ ### 2. Introspect and Scan Database (`scan`)
119
+
120
+ ```bash
121
+ # Scan a local SQLite database
122
+ db-agent scan --db ecommerce_demo.db
123
+
124
+ # Scan a PostgreSQL database
125
+ db-agent scan --db postgresql://user:password@localhost:5432/mydb
126
+
127
+ # Drill down into a specific table's columns and indexes
128
+ db-agent scan --db ecommerce_demo.db --table products
129
+
130
+ # Export schema catalog to JSON or Markdown
131
+ db-agent scan --db ecommerce_demo.db --export schema_catalog.md
132
+ ```
133
+
134
+ ### 2. Generate Scripts & Code (`generate`)
135
+
136
+ ```bash
137
+ # Generate an optimized SQL analytical query
138
+ db-agent generate "Calculate customer lifetime value and total orders per country" --db ecommerce_demo.db
139
+
140
+ # Generate a Python ETL script to export sales data to CSV
141
+ db-agent generate "Write a Pandas ETL script to export all completed orders to sales.csv" --db ecommerce_demo.db --type etl --output etl_export.py
142
+
143
+ # Generate a FastAPI CRUD backend for products and categories
144
+ db-agent generate "Generate FastAPI CRUD routes for products" --db ecommerce_demo.db --type api --output api_routes.py
145
+
146
+ # Generate an Alembic migration
147
+ db-agent generate "Add loyalty_points column to users table" --db ecommerce_demo.db --type migration
148
+
149
+ # Generate and execute SQL query directly (with safety checks)
150
+ db-agent generate "Find top 5 highest priced active products" --db ecommerce_demo.db --run
151
+ ```
152
+
153
+ ### 3. Interactive Terminal Chat REPL (`chat`)
154
+
155
+ Start an interactive session with the database schema held in context:
156
+
157
+ ```bash
158
+ db-agent chat --db ecommerce_demo.db
159
+ ```
160
+
161
+ Inside the interactive chat:
162
+ - Ask questions: `> Show me total sales grouped by category`
163
+ - Execute last query: `> :run`
164
+ - Export last code: `> :export report_query.sql`
165
+ - View database tables: `> :tables`
166
+ - View single table detail: `> :table products`
167
+ - Exit session: `> :exit`
168
+
169
+ ### 4. Execute Queries Safely (`run`)
170
+
171
+ ```bash
172
+ db-agent run "SELECT username, country FROM users WHERE role = 'admin'" --db ecommerce_demo.db
173
+ ```
174
+
175
+ ### 5. Manage Database Connection Profiles (`profiles`)
176
+
177
+ Save your database connection strings so you don't need to retype them:
178
+
179
+ ```bash
180
+ db-agent config
181
+ # Prompts you to add a profile (e.g. 'analytics_prod', 'local_dev')
182
+
183
+ # List saved profiles
184
+ db-agent profiles
185
+
186
+ # Use saved profile in any command
187
+ db-agent scan --db analytics_prod
188
+ db-agent chat --db analytics_prod
189
+ ```
190
+
191
+ ### 6. Check Available AI Models (`models`)
192
+
193
+ ```bash
194
+ db-agent models
195
+ ```
196
+
197
+ ---
198
+
199
+ ## ๐Ÿงช Running Tests
200
+
201
+ ```bash
202
+ pytest -v
203
+ ```
204
+
205
+ ---
206
+
207
+ ## ๐Ÿ“‚ Project Structure
208
+
209
+ ```
210
+ .
211
+ โ”œโ”€โ”€ pyproject.toml # Build config & dependencies
212
+ โ”œโ”€โ”€ README.md # Documentation
213
+ โ”œโ”€โ”€ scripts/
214
+ โ”‚ โ””โ”€โ”€ seed_demo_db.py # Realistic demo database generator
215
+ โ”œโ”€โ”€ dbagent/
216
+ โ”‚ โ”œโ”€โ”€ cli.py # Typer CLI application & REPL
217
+ โ”‚ โ”œโ”€โ”€ config.py # Profile & credential manager
218
+ โ”‚ โ”œโ”€โ”€ connectors/ # Universal database connectors
219
+ โ”‚ โ”‚ โ”œโ”€โ”€ base.py # Abstract DB connector interface
220
+ โ”‚ โ”‚ โ”œโ”€โ”€ relational.py # SQLAlchemy universal connector (PG, MySQL, SQLite, MSSQL, Oracle, DuckDB)
221
+ โ”‚ โ”‚ โ”œโ”€โ”€ mongo.py # MongoDB introspector & sampling
222
+ โ”‚ โ”‚ โ””โ”€โ”€ factory.py # Connector factory
223
+ โ”‚ โ”œโ”€โ”€ schema/ # Schema catalog & context builder
224
+ โ”‚ โ”‚ โ”œโ”€โ”€ models.py # Pydantic schema data models
225
+ โ”‚ โ”‚ โ”œโ”€โ”€ formatter.py # Markdown/compact schema formatters
226
+ โ”‚ โ”‚ โ””โ”€โ”€ selector.py # Smart table selector for large schemas
227
+ โ”‚ โ”œโ”€โ”€ llm/ # 100% Free & Standalone LLM providers
228
+ โ”‚ โ”‚ โ”œโ”€โ”€ base.py # Base LLM provider
229
+ โ”‚ โ”‚ โ”œโ”€โ”€ ollama_provider.py # Local offline Ollama client
230
+ โ”‚ โ”‚ โ”œโ”€โ”€ gemini_provider.py # Google Gemini Free API client
231
+ โ”‚ โ”‚ โ”œโ”€โ”€ groq_provider.py # Groq Free API client
232
+ โ”‚ โ”‚ โ”œโ”€โ”€ openrouter_provider.py # OpenRouter Free models
233
+ โ”‚ โ”‚ โ”œโ”€โ”€ mock_provider.py # Offline fallback provider
234
+ โ”‚ โ”‚ โ””โ”€โ”€ factory.py # LLM provider factory
235
+ โ”‚ โ”œโ”€โ”€ agent/ # AI Script Generation & Validation
236
+ โ”‚ โ”‚ โ”œโ”€โ”€ generator.py # Prompt templates & generator engine
237
+ โ”‚ โ”‚ โ””โ”€โ”€ validator.py # SQL syntax & safety validator
238
+ โ”‚ โ””โ”€โ”€ ui/ # Rich terminal UI
239
+ โ”‚ โ”œโ”€โ”€ console.py # Console banners, badges & code syntax
240
+ โ”‚ โ””โ”€โ”€ viewer.py # Rich schema visualizer tables
241
+ โ””โ”€โ”€ tests/ # Automated test suite (100% passing)
242
+ ```
@@ -0,0 +1,28 @@
1
+ dbagent/__init__.py,sha256=uAK7lyT38FvuTw0sfY5duSLSKCDca6Y_6Pvuw_t7-yY,112
2
+ dbagent/cli.py,sha256=ITwc1QzQ_BCdwxOciUYWPFw_eCJAPVKjTEEUrtTKU_E,31108
3
+ dbagent/config.py,sha256=UeDS1tXWaGdy0zL5vNGxC_vuzhbZwvv2RgtskZXzALA,3020
4
+ dbagent/agent/generator.py,sha256=7tByR_xjvbTc3VRC0rwjq5d2nKmByqzCqVyMjqKqFog,9771
5
+ dbagent/agent/pipeline.py,sha256=mgdKheGLOz4WinYB31PqdA4ktxMBUwKnKe3CIp37m6o,9271
6
+ dbagent/agent/validator.py,sha256=a2qYghWpYEBtaiydMM4Yhg4AJ6SrkXytuIDExG-RBRo,3463
7
+ dbagent/connectors/base.py,sha256=kjL_7J-Y4xsdAvvg6tyfSvtobvufrfkOfjk-9aAhMiw,2255
8
+ dbagent/connectors/factory.py,sha256=OsMmdibFrrpTol7hyIDim_BXPv6JDr9kNuPLkwqtmZc,930
9
+ dbagent/connectors/mongo.py,sha256=vrTQCyl45x7gDSrpl5KKYRTtM8nBbod4L3O1oVKRHOk,8408
10
+ dbagent/connectors/relational.py,sha256=P_oYuOvhyfxQhqp-hso7uM16et4dpdKecGprB-Bcojw,17327
11
+ dbagent/llm/auto_setup.py,sha256=pNmU-XIKmrYBSy7Xk3oUpGShAfWrGvXP6bdzjgqNuTA,9039
12
+ dbagent/llm/base.py,sha256=KWBtnRe_Y-0B_-Y7Fg3GjciAieyYZ7Sm-hmFKEa7DQQ,940
13
+ dbagent/llm/factory.py,sha256=MJW-4yxBld8EeIXbZUQRr4bCbD6CQkmEOsQbtsrvzLM,2825
14
+ dbagent/llm/gemini_provider.py,sha256=YwR7CAluNvP1y1qVD8ktEwJKOAo8wS6WOWiPFU5M6CY,4158
15
+ dbagent/llm/groq_provider.py,sha256=34H53MPjLL9fck945s-d2eU1d2JbTXbV7BQrp76u33M,3689
16
+ dbagent/llm/mock_provider.py,sha256=hsF70amZ0Uk3mNrSAh4GTbYQMQdBAs6zNVUF7tyx2xE,1302
17
+ dbagent/llm/ollama_provider.py,sha256=8mPFQq0Pj8bdG9j3l2ZrbMvan_-_2uAk0MEkm5qy4Yo,5076
18
+ dbagent/llm/openrouter_provider.py,sha256=gxP6Vt-OgkxfhObgrSSCGIMcBZtQlbnFo7Kn6vx8MGE,3896
19
+ dbagent/schema/formatter.py,sha256=l5BjW_TUEDiwdS3URya7wRNYfyN7pxmVw_w6acHBc-Q,5374
20
+ dbagent/schema/models.py,sha256=-Ri33VEPvOOEduxKRFNSqkcwhSKHRuwsJSrYIvTtUaY,2104
21
+ dbagent/schema/selector.py,sha256=H9QxDk1Y7FBysBG62PjgepeKgim_Gncs_ZnjU7YYukI,2554
22
+ dbagent/ui/console.py,sha256=QCA3uRDBdyM9kEmVJK36Lhn09PgZ53nHeRh0PmSkqAk,2543
23
+ dbagent/ui/viewer.py,sha256=_9WUQ9XUU9ToMDeTNYgQyojzdsKLbre4iX7ggpiG9To,3718
24
+ dbagent_cli-0.1.0.dist-info/METADATA,sha256=zAx9XXOdwt14p3639Ycuq9pD3ekqM3MWpYsvVK37AcI,9465
25
+ dbagent_cli-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
26
+ dbagent_cli-0.1.0.dist-info/entry_points.txt,sha256=cveRtS77cQqdlnuebFvcqLVoLhK1yWuBrqFTOMQ6YRI,71
27
+ dbagent_cli-0.1.0.dist-info/top_level.txt,sha256=KQ8bRD08ixWrmzCkJxI9kkuh1hXGhrKp82HXu3QXLcc,8
28
+ dbagent_cli-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ db-agent = dbagent.cli:app
3
+ dbagent = dbagent.cli:app
@@ -0,0 +1 @@
1
+ dbagent