Skip to main content

NL2SQL API

FastAPI REST service for the NL2SQL engine (nl2sql-engine). At startup it loads the .env next to nl2sql.yaml (never overriding a variable already set), builds one engine with NL2SQL.from_config() from the same config as the CLI (NL2SQL_CONFIG, else ./nl2sql.yaml), calls engine.check(), and serves it under /api/v1. A datasource marked required: true that cannot connect stops it from starting; any other one that fails is left out.

Running the API

pip install nl2sql-api
NL2SQL_CONFIG=nl2sql-demo/nl2sql.yaml nl2sql-api --host 127.0.0.1 --port 8000 [--reload]
# or: python -m nl2sql_api.server ..., or: uvicorn nl2sql_api.main:app

Interactive docs: Swagger UI at /docs, ReDoc at /redoc, the schema at /openapi.json.

The API's own settings are the api section of nl2sql.yaml; the engine ignores it:

api:
  role_header: X-NL2SQL-Role     # a header a trusted proxy sets on every request
  role: null                     # or one static role for every request
  trust_body_role: false         # local testing only: the body's user_context
  cors_origins: []               # browser origins allowed to call the API

The API does not authenticate callers and never takes the RBAC role from the request body unless api.trust_body_role is on (it logs a warning). With no role source, /api/v1/query and /api/v1/query/stream answer HTTP 401.

The routes that change datasources, LLMs or the index need a role listed in policies.admin_roles (default [admin]), else HTTP 403. With no role setting at all they answer loopback clients only.

The Docker image (packages/api/Dockerfile) reads /etc/nl2sql/nl2sql.yaml: mount a config folder there, and a volume for storage.path.

Endpoints

  • POST /api/v1/query - Ask a question as the configured role
  • POST /api/v1/query/stream - The same, as Server-Sent Events: each step as it runs, the result manifest, the answer as it is written, then the /query response
  • GET /api/v1/health - Liveness check
  • GET /api/v1/ready - Readiness check (does not yet check dependencies)
  • POST /api/v1/datasource - Register a datasource in the running process (config is one datasources entry: id, type, connection, ...)
  • GET /api/v1/datasource - List the datasources, with their status and masked connections
  • GET /api/v1/datasource/{datasource_id} - One datasource
  • DELETE /api/v1/datasource/{datasource_id} - Take a datasource out of the running process
  • PUT /api/v1/settings/llm - Replace the whole llm section in the running process (admin only; 422 with the config error)
  • GET /api/v1/llm - Each agent and the model it runs on
  • GET /api/v1/llm/{agent} - One agent's model
  • POST /api/v1/index/{datasource_id} - Index one datasource's schema
  • POST /api/v1/index-all - Index every configured datasource
  • DELETE /api/v1/index - Clear the vector store
  • GET /api/v1/index/status - Index health (status, entries by type, embedding model, problems)

Reference: https://github.com/nadeem4/nl2sql/blob/main/docs/api/rest/index.md.

Metadata

Release files for nl2sql-api 0.7.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 nl2sql-api 0.7.0
File Size Uploaded
nl2sql_api-0.7.0.tar.gz 30.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nl2sql-api 0.7.0
File Interpreter ABI Platform
nl2sql_api-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 51.4 kB

Release files / nl2sql_api-0.7.0.tar.gz

Download URL nl2sql_api-0.7.0.tar.gz
Size 30.2 kB
Tags Source
SHA-256 checksum
How to use checksums
eafe550ac979bb149011d24a0ae77bf03cadd6c577339af7e3adbe53a8206953
BLAKE2b-256 checksum
How to use checksums
95fa98dd394363b3322f03a76a940b38fa5d5d22c10c2b294c2ee4e09521aa7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / nl2sql_api-0.7.0-py3-none-any.whl

Download URL nl2sql_api-0.7.0-py3-none-any.whl
Size 21.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
28b5409c3e51acf30ef82dbf9cff63e58674b7db5e0ead41d82ffd2091734eeb
BLAKE2b-256 checksum
How to use checksums
31e1eddf192c0756b6f1b91adb102818ac0fdcf32953cb724d1a122b8e9a8b37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

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