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")
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}")
Dependencies
- openai
- psycopg2
- mysql-connector-python
- sqlparse
- psycopg2-binary
License
MIT License © 2024
Contributing
- Fork the repository
- Create a feature branch
- 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.5.tar.gz
(6.5 kB
view details)
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 cognidb-0.2.5.tar.gz.
File metadata
- Download URL: cognidb-0.2.5.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7f53e92ef50ef8f1e95852ae10c5963e332e5074947a02cbee055880f8a9b14
|
|
| MD5 |
53a361cfd7fb31ba8f0c10b29ca45cd5
|
|
| BLAKE2b-256 |
8c0805b153ed78fb3e993d75d9f4cf9a68cead09daddebd81e2af822988114b0
|
File details
Details for the file cognidb-0.2.5-py3-none-any.whl.
File metadata
- Download URL: cognidb-0.2.5-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
067c24a51a861884758fda9d82ea80245e86bf203cdbcde91be23326d3802280
|
|
| MD5 |
e8e618385a75ccbe8bc54c0209fcf9b3
|
|
| BLAKE2b-256 |
acc226ccdfdc7a8e81ecd1370aac6f7df1c9d79afe0c41c86c97dcf135085248
|