<<<<<<< HEAD
woo-db-agent
An A.I Agent responsible for Generating and executing SQL queries for WooCommerce using Google Gemini API as LLM
🛍️ WooCommerce Gemini Query Generator
Generate and execute SQL queries for WooCommerce stores using natural language, powered by Google Gemini AI.
✨ Features
- 🤖 Natural Language to SQL - Convert plain English queries to SQL
- 🛍️ WooCommerce-Specific - Understands WooCommerce database schema
- 📊 Beautiful Output - Results displayed in formatted tables
- ✏️ Full CRUD Support - SELECT, UPDATE, INSERT, DELETE queries
- 🔒 Safe Transactions - Automatic commit/rollback handling
- 🎯 CLI & Library - Use as command-line tool or Python library
🚀 Installation
pip install woo-db-agent
📋 Requirements
- Python 3.8 or higher
- MySQL database with WooCommerce
- Google Gemini API key (Get one here)
🎯 Quick Start
As a Command-Line Tool
# Set environment variables (recommended)
export GEMINI_API_KEY="your-gemini-api-key"
export DB_HOST="localhost"
export DB_NAME="your_wordpress_db"
export DB_USER="your_db_user"
export DB_PASSWORD="your_db_password"
# Run the CLI
woo-gemini-query
As a Python Library
from woodbagent import WooCommerceQueryGenerator, execute_query
# Initialize the generator
generator = WooCommerceQueryGenerator(api_key="your-gemini-api-key")
# Generate a query from natural language
sql = generator.generate_query("Show all products under $50")
print(sql)
# Execute the query
result = execute_query(
sql_query=sql,
host="localhost",
database="wordpress_db",
user="db_user",
password="db_password"
)
# Display results
if result['success']:
print(f"Found {result['row_count']} products")
for row in result['data']:
print(row)
💡 Usage Examples
Example Queries
from woo-db-agent import WooCommerceQueryGenerator, execute_query, display_results
generator = WooCommerceQueryGenerator(api_key="your-api-key")
# Query 1: Find products by price
query = generator.generate_query("Show all products priced between $20 and $100")
result = execute_query(query, host="localhost", database="mydb", user="root", password="pass")
display_results(result)
# Query 2: Check inventory
query = generator.generate_query("List all out of stock products")
result = execute_query(query, host="localhost", database="mydb", user="root", password="pass")
display_results(result)
# Query 3: Update prices
query = generator.generate_query("Increase price by 10% for products in Electronics category")
result = execute_query(query, host="localhost", database="mydb", user="root", password="pass")
display_results(result)
Interactive CLI Session
🛍️ What would you like to know about your products?
➤ Show me the top 10 best selling products
⏳ Generating SQL query...
📝 Generated SQL Query:
----------------------------------------------------------------------
SELECT p.ID, p.post_title, SUM(oi.order_item_qty) as total_sold
FROM wp_posts p
INNER JOIN wp_order_itemmeta oim ON p.ID = oim.meta_value
...
----------------------------------------------------------------------
✅ Query executed successfully!
📊 Results (10 rows):
╔════╦═══════════════════╦════════════╗
║ ID ║ post_title ║ total_sold ║
╠════╬═══════════════════╬════════════╣
║ 23 ║ Wireless Mouse ║ 156 ║
║ 45 ║ USB Cable ║ 142 ║
...
🔧 API Reference
WooCommerceQueryGenerator
generator = WooCommerceQueryGenerator(api_key, model="gemini-2.5-flash")
Methods:
generate_query(user_prompt: str) -> str- Generate SQL from natural languageset_custom_schema(schema_context: str)- Override default schema
execute_query
result = execute_query(
sql_query: str,
host: str,
database: str,
user: str,
password: str,
port: int = 3306
)
Returns: Dictionary with:
success: Booleandata: List of tuples (for SELECT queries)columns: List of column namesrow_count: Number of rowsquery_type: SELECT, UPDATE, INSERT, DELETEerror: Error message (if any)
display_results
display_results(result: Dict)
Formats and prints query results in a table.
🔐 Environment Variables
| Variable | Description | Required |
|---|---|---|
GEMINI_API_KEY |
Your Google Gemini API key | Yes |
DB_HOST |
Database host | No (default: localhost) |
DB_NAME |
Database name | Yes |
DB_USER |
Database username | Yes |
DB_PASSWORD |
Database password | Yes |
DB_PORT |
Database port | No (default: 3306) |
🛡️ Security Best Practices
- Never hardcode credentials - Use environment variables
- Use .env files for local development
- Restrict database permissions - Use read-only user for SELECT queries
- Review generated queries - Always check before executing modifications
- Backup your database - Before running UPDATE/DELETE queries
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Powered by Google Gemini AI
4f3d100 (Initial commit)
Metadata
Release files for woo-db-agent 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| woo_db_agent-0.1.1.tar.gz | 9.3 kB | Without provenance | Details for woo_db_agent-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| woo_db_agent-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for woo_db_agent-0.1.1-py3-none-any.whl |
Total release size: 20.1 kB
Release files / woo_db_agent-0.1.1.tar.gz
| Download URL | woo_db_agent-0.1.1.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2c14a15fada5c0b73e394e0a7f2f3d0f97511618f8c9b08a07ea1f28672dbd16
|
|
BLAKE2b-256 checksum How to use checksums |
2b5edfed7cb0a43e78973c0dfa52ce4667272e3886d4da0460d8114e56a71b61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.7
|
Release files / woo_db_agent-0.1.1-py3-none-any.whl
| Download URL | woo_db_agent-0.1.1-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d17fecf497354b3ca34fc5e88bab34019186d6026d9fe03ac97173c26346f0a6
|
|
BLAKE2b-256 checksum How to use checksums |
8a40019b25edaccd5f78648349f9b6c169ee0d5e922a768d811eb84ec13dd73e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.7
|
Security for woo-db-agent 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.