No project description provided
Project description
<<<<<<< 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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file woo_db_agent-0.1.1.tar.gz.
File metadata
- Download URL: woo_db_agent-0.1.1.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c14a15fada5c0b73e394e0a7f2f3d0f97511618f8c9b08a07ea1f28672dbd16
|
|
| MD5 |
b7f2aa49f3641ed700d07bb874ba2d0c
|
|
| BLAKE2b-256 |
2b5edfed7cb0a43e78973c0dfa52ce4667272e3886d4da0460d8114e56a71b61
|
File details
Details for the file woo_db_agent-0.1.1-py3-none-any.whl.
File metadata
- Download URL: woo_db_agent-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d17fecf497354b3ca34fc5e88bab34019186d6026d9fe03ac97173c26346f0a6
|
|
| MD5 |
7dd250c2ab9036fe9d0057a903ca7d19
|
|
| BLAKE2b-256 |
8a40019b25edaccd5f78648349f9b6c169ee0d5e922a768d811eb84ec13dd73e
|