Skip to main content

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

PyPI version Python 3.8+ License: MIT

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 language
  • set_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: Boolean
  • data: List of tuples (for SELECT queries)
  • columns: List of column names
  • row_count: Number of rows
  • query_type: SELECT, UPDATE, INSERT, DELETE
  • error: 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

  1. Never hardcode credentials - Use environment variables
  2. Use .env files for local development
  3. Restrict database permissions - Use read-only user for SELECT queries
  4. Review generated queries - Always check before executing modifications
  5. Backup your database - Before running UPDATE/DELETE queries

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

4f3d100 (Initial commit)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

woo_db_agent-0.1.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

woo_db_agent-0.1.1-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

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

Hashes for woo_db_agent-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2c14a15fada5c0b73e394e0a7f2f3d0f97511618f8c9b08a07ea1f28672dbd16
MD5 b7f2aa49f3641ed700d07bb874ba2d0c
BLAKE2b-256 2b5edfed7cb0a43e78973c0dfa52ce4667272e3886d4da0460d8114e56a71b61

See more details on using hashes here.

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

Hashes for woo_db_agent-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d17fecf497354b3ca34fc5e88bab34019186d6026d9fe03ac97173c26346f0a6
MD5 7dd250c2ab9036fe9d0057a903ca7d19
BLAKE2b-256 8a40019b25edaccd5f78648349f9b6c169ee0d5e922a768d811eb84ec13dd73e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page