A FastAPI application that provides AI-powered natural language querying of database tables, built with FastAPI, asyncpg, and pydantic-ai.
- Natural language querying of database tables
- CSV data import
- Multi-agent AI system for query understanding and data analysis
- RESTful API with OpenAPI documentation
- Clone the repository
git clone <repository-url>
cd <project-directory>- Install dependencies
pip install -r requirements.txt- Set up environment variables
Create a .env file based on .env.example with your configuration:
cp .env.example .env
# Edit .env with your settings- Set up the database
python scripts/setup_db.py- Run the application
Development mode:
uvicorn app.main:app --reloadProduction mode:
gunicorn app.main:app -k uvicorn.workers.UvicornWorker -w 4After starting the server, visit:
- API documentation: http://localhost:8000/docs
- ReDoc alternative documentation: http://localhost:8000/redoc
GET /api/v1/tables: List all available tablesGET /api/v1/tables/{table_name}: Get detailed table informationPOST /api/v1/query: Analyze a natural language queryPOST /api/v1/import/csv: Import data from CSV file
You can import CSV files directly from the command line:
python scripts/import_csv_cli.py path/to/your/file.csv --table optional_table_nameThe project follows a modular structure:
app/: Main application packagemain.py: FastAPI application entry pointconfig.py: Configuration settingsdatabase.py: Database connection handlingmodels/: Pydantic schemasapi/: API routes and dependenciesagents/: AI agents for various tasksservices/: Business logicutils/: Utilities and helpers