Skip to main content

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 or adding it to your project .env file.

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

Release files for nldb 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nldb 0.4.0
File Size Uploaded
nldb-0.4.0.tar.gz 11.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nldb 0.4.0
File Interpreter ABI Platform
nldb-0.4.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 22.0 kB

Release files / nldb-0.4.0.tar.gz

Download URL nldb-0.4.0.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
bc3a053aa32bfaf46cda9a1821305bafe06f92f936fa1c60e16063356889da10
BLAKE2b-256 checksum
How to use checksums
57d5830e5511d77d6f4aed90e2c2e388b0dabb893ffdba80477495727a3f60e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.30.0

Release files / nldb-0.4.0-py2.py3-none-any.whl

Download URL nldb-0.4.0-py2.py3-none-any.whl
Size 10.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
053513d8cdb322f42834550992791561d5555c21aa2c0b543e983fb8b49ee01a
BLAKE2b-256 checksum
How to use checksums
6427f3b3fbcb9098716b9ac5c3ef1c27f94832fe50136cbaf3ef2786f9fd9382
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.30.0

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page