Skip to main content

A tool for generating SQL queries

Project description

CogniDB 🚀

A utility that provides seamless database access to your agents with a single line of code.

📦 Installation

pip install cognidb

⚙️ Configuration

Using Environment Variables (.env)

# Database Settings
HOST=localhost
PORT=3306
DATABASE=your_database
USER=your_username
PASSWORD=your_password

# OpenAI API Key
OPENAI_API_KEY=your-openai-api-key

Using Python Code

from cognidb import CogniDB

db = CogniDB(
    db_type="mysql",  # or "postgresql"
    host="localhost",
    port=3306,
    dbname="your_database",
    user="your_username",
    password="your_password",
    api_key="your-openai-api-key"  # Optional if set in .env
)

🚀 Quick Start

from cognidb import CogniDB

# Initialize using environment variables
db = CogniDB(db_type="mysql")

# Simple query
result = db.query("Show me all customers")

# Query with potential clarification
result = db.query("Show transactions from last month")

💡 Features

  • 🔄 Natural Language to SQL conversion
  • 🤖 OpenAI API integration
  • 🎯 Interactive clarification handling
  • 🔒 Environment variable support
  • 📊 MySQL and PostgreSQL support

🔍 Example Queries

# Basic queries
customers = db.query("List all premium customers")

# Aggregations
summary = db.query("Total sales by product category")

# Complex queries
analysis = db.query("Find customers who spent more than average")

⚠️ Error Handling

try:
    db = CogniDB(db_type="mysql")
    result = db.query("Show customer accounts")
except ValueError as e:
    print(f"Configuration error: {e}")
except Exception as e:
    print(f"Query error: {e}")

🔧 Required Environment Variables

Variable Required Default
HOST No localhost
PORT No 3306/5432
DATABASE Yes None
USER Yes None
PASSWORD Yes None
OPENAI_API_KEY Yes None

📦 Dependencies

  • openai
  • psycopg2
  • mysql-connector-python
  • sqlparse
  • psycopg2-binary

📝 License

MIT License © 2024

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

📧 Support

For support or questions, contact: Rishabh Kumar rishabh.vaaiv@gmail.com

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

cognidb-0.2.4.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

cognidb-0.2.4-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file cognidb-0.2.4.tar.gz.

File metadata

  • Download URL: cognidb-0.2.4.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for cognidb-0.2.4.tar.gz
Algorithm Hash digest
SHA256 9998b4b008f68b6f8ddf5eaa5915b2889e4b32d462926e03f030491e5d60a66d
MD5 15a86a221ebc16d93c261853b0454a46
BLAKE2b-256 be798a4fd788af8639d1164b04b95f071b4ec085933551874b11a3db7d689fc2

See more details on using hashes here.

File details

Details for the file cognidb-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: cognidb-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for cognidb-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 6f01ee342ab0eadc3ea6761e769df1623737963e1891da1f448e6cdb9a870b93
MD5 a288d659693da5be591b4239e30c17cd
BLAKE2b-256 06ccb478c7232fe8abf8db05d486ff95f9ec563af4d945ff3135928cf8accf3e

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