Skip to main content

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 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

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

nldb-0.3.8.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

nldb-0.3.8-py2.py3-none-any.whl (10.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file nldb-0.3.8.tar.gz.

File metadata

  • Download URL: nldb-0.3.8.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.30.0

File hashes

Hashes for nldb-0.3.8.tar.gz
Algorithm Hash digest
SHA256 fca72ac8f889a56ca64e243ba42a25de2ffcac4300da933f0d3e550b6b7fed97
MD5 a7843cc3a7ac62a69d10d220a7306a48
BLAKE2b-256 7f1a2b097376292a50162ce2deec30778b32c6f57488eb16bb91057aa4630305

See more details on using hashes here.

File details

Details for the file nldb-0.3.8-py2.py3-none-any.whl.

File metadata

  • Download URL: nldb-0.3.8-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.30.0

File hashes

Hashes for nldb-0.3.8-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ed6ab1623ca2c19bf15c322ac71a1bda84c92746d5e95f0831b5e5f9ca8a1d5b
MD5 f910f83e6993adcfc500517ad210eb03
BLAKE2b-256 7c0aaf2c7f70817a4ab37e541a7561be953893009088c23e44c2bc7f8f94443e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page