talk to your database
Project description
nldb
Natural Language Databasing. Talk to your data in English, via CLI, API or a simple web interface.
Installation
pip install nldb
An OpenAI API key should be available as the OPENAI_API_KEY
environment variable, e.g. using export OPENAI_API_KEY=sk-etc
.
Preparing your database
NLDB can talk to SQLite and DuckDB databases. Call yours nldb.db
or specify the name with a DATABASE
environment variable.
You may need to simplify and denormalise your database for NLDB to work well. Your columns should have names whose meaning is obvious. While NLDB can join across tables, combining your data into a single table will reduce your prompt size and improve the accuracy of NLDB's query generation.
Initialise NLDB
nldb init
This creates three files: index.html
, Dockerfile
and prompt.txt
. You can ignore the first two for now.
Edit your prompt
Edit prompt.txt
, following the example and instructions in the generated file. You can test the effectiveness of your prompt by pasting it into ChatGPT, replacing %s
with some example questions.
Ask questions from the command line
nldb "What were the most watched videos by Japanese users in 2022?"
Start the API server
nldb serve
This starts an API server, on port 8080, with a single endpoint at /api/ask
. This expects a GET request with a q
parameter for the natural language query. It returns a JSON object containing the SQL statement, the result of executing the statement, a plain English answer and some timing and cost information.
There is a simple web interface to the API at /
. If you don't want this, just delete index.html
.
Adjust
Edit prompt.txt
to refine the quality of the generated queries, restarting the server to see changes. Edit index.html
or replace it with your own front-end.
Deploy
Generate instructions for Fly.io and Google Cloud Run
nldb deploy
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
File details
Details for the file nldb-0.3.5.tar.gz
.
File metadata
- Download URL: nldb-0.3.5.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4db6f36984e9b4c5ac26c658ab04754cba0e20f195f7c2953306f51bdc92d8bd |
|
MD5 | a2f7bcba6b54781904f7db2b59f6aa71 |
|
BLAKE2b-256 | 1a6ab62835f7e5c9924e050da7705745fbf46f8a95541e490bba790546962bed |
File details
Details for the file nldb-0.3.5-py2.py3-none-any.whl
.
File metadata
- Download URL: nldb-0.3.5-py2.py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e32aec9dde454e902bfc331e9925d8d580488c9bc446e74cbaf583e941a4d0b4 |
|
MD5 | a0ebb0b0e44c8e8322d22311a72934c8 |
|
BLAKE2b-256 | 8963a76a3cad5acd2ab38d939c93e00b93a5ad8158db7702c2c71b574a53514e |