Metadata-Version: 2.4
Name: rdsai-cli
Version: 0.1.9
Summary: AI-powered CLI tool for Relation database management and analysis
Author-email: "yanpei.wyp" <yanpei.wyp@gmail.com>
License: MIT
License-File: LICENSE
Keywords: ai,cli,database,langchain,mysql
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Database
Classifier: Topic :: Database :: Database Engines/Servers
Classifier: Typing :: Typed
Requires-Python: >=3.13
Requires-Dist: aiohttp>=3.13.0
Requires-Dist: duckdb>=1.4.3
Requires-Dist: fastmcp>=2.13.3
Requires-Dist: langchain-anthropic>=1.2.0
Requires-Dist: langchain-core>=1.1.0
Requires-Dist: langchain-deepseek>=0.1.3
Requires-Dist: langchain-google-genai>=4.0.0
Requires-Dist: langchain-openai>=1.1.0
Requires-Dist: langchain-qwq>=0.3.1
Requires-Dist: langchain>=1.1.0
Requires-Dist: langgraph>=1.0.4
Requires-Dist: loguru>=0.7.0
Requires-Dist: mysql-connector-python>=9.3.0
Requires-Dist: packaging>=24.0
Requires-Dist: prompt-toolkit>=3.0.52
Requires-Dist: pydantic>=2.12.0
Requires-Dist: pyperclip>=1.11.0
Requires-Dist: pyyaml>=6.0.0
Requires-Dist: rich>=14.0.0
Requires-Dist: streamingjson>=0.0.5
Requires-Dist: tenacity>=9.1.0
Requires-Dist: trafilatura>=1.12.0
Requires-Dist: typer>=0.20.0
Provides-Extra: dev
Requires-Dist: mypy>=1.19.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.24.0; extra == 'dev'
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Requires-Dist: ruff>=0.14.8; extra == 'dev'
Description-Content-Type: text/markdown

<div align="center">

# RDSAI CLI

**AI-Powered Database Command-Line Interface**

[![Python 3.13+](https://img.shields.io/badge/python-3.13+-blue.svg)](https://www.python.org/downloads/)
[![License](https://img.shields.io/github/license/aliyun/rdsai-cli)](https://github.com/aliyun/rdsai-cli/blob/main/LICENSE)
[![GitHub issues](https://img.shields.io/github/issues/aliyun/rdsai-cli)](https://github.com/aliyun/rdsai-cli/issues)

[English](README.md) | [中文](README_zh.md)

<img src="docs/assets/img.png" alt="RDSAI CLI Screenshot" width="800">

<p>
RDSAI CLI is an AI-powered command-line interface for database management.<br>
It supports natural language queries and SQL execution, with built-in diagnostic tools,<br>
execution plan analysis, and multi-source data connections.
</p>

</div>

---

## Features

- **Multi-Source Connection** - Connect to MySQL databases or files (CSV, Excel) locally or remotely via HTTP/HTTPS
- **AI Assistant** - Natural language queries (English/Chinese), SQL optimization, diagnostics, and explanations
- **Smart SQL** - Auto-detects SQL vs natural language, query history, Ctrl+E for instant result explanations
- **Multi-Model LLM** - Support for Qwen, OpenAI, DeepSeek, Anthropic, Gemini, and OpenAI-compatible APIs
- **Schema Analysis** - AI-powered database analysis with compliance checking and optimization suggestions
- **Performance Benchmarking** - Automated sysbench testing with comprehensive analysis reports
- **MCP Integration** - Extend capabilities via Model Context Protocol servers
- **Safety First** - Read-only by default, DDL/DML requires confirmation (YOLO mode available)

## Requirements

- Python 3.13+
- Network access to MySQL
- API access to LLM provider

## Installation

```bash
# One-click installation (recommended)
curl -LsSf https://raw.githubusercontent.com/aliyun/rdsai-cli/main/install.sh | sh

# Or using uv
uv tool install --python 3.13 rdsai-cli

# Or using pip (recommend virtual environment)
pip install rdsai-cli
```

## Quick Start

### Launch and Connect

```bash
# Start without connection (interactive mode)
rdsai

# Connect via command line
rdsai --host localhost -u root -p secret -D mydb

# Connect to files
rdsai
> /connect flights.csv
> /connect https://example.com/data.csv
```

### Configure LLM

```text
mysql> /setup
```

Interactive wizard will guide you through LLM provider setup. Configuration is saved to `~/.rdsai-cli/config.json`.

### Basic Usage

**SQL Execution:**

```text
mysql> SELECT COUNT(*) FROM users;
mysql> EXPLAIN SELECT * FROM users WHERE email = 'test@example.com';
mysql> SELECT * FROM users LIMIT 10\G   -- Press Ctrl+E for AI explanation
```

**Natural Language:**

```text
mysql> analyze index usage on users table
mysql> show me slow queries from the last hour
mysql> design an orders table for e-commerce
mysql> why this query is slow: SELECT * FROM users WHERE name LIKE '%john%'
```

### Meta Commands

| Command | Description |
|---------|-------------|
| `/connect`, `/disconnect` | Connect/disconnect from database or files |
| `/setup` | Configure LLM provider |
| `/help` | Show help and status |
| `/explain` | Analyze SQL execution plan |
| `/research` | Generate database schema analysis report |
| `/benchmark` | Run performance benchmark test |
| `/yolo` | Toggle auto-approve mode (use with caution) |
| `/history` | Show query history |
| `/model` | Manage LLM models |

## Documentation

- [Complete Tutorial](docs/tutorial.md) - Comprehensive guide from beginner to advanced
- [Core Features](docs/features/) - Execution plan analysis, schema analysis, benchmarking, MCP integration
- [Usage Scenarios](docs/scenarios/) - SQL explanation, file analysis, slow query optimization, and more

## Security

- **Read-Only by Default** - DDL/DML require explicit confirmation unless YOLO mode is enabled
- **Confirmation Required** - Every write operation shows exact SQL for review before execution
- **Credential Storage** - API keys stored in `~/.rdsai-cli/config.json` (protect with proper permissions)

## Contributing

We welcome contributions. See [CONTRIBUTING.md](CONTRIBUTING.md) for details.


## License

MIT License - see [LICENSE](LICENSE) for details.
