Skip to main content

nl2data-core

An embeddable Python framework for adding governed natural-language data access to an application. The host keeps control of identity, tenancy, deployment, and credentials; NL2Data supplies semantic query planning and a bounded execution path behind one public facade (import nl2data).

The runtime resolves requests against an authorized Semantic View, builds a typed Semantic IR, and compiles only operations supported by the configured adapter. Governance, authorization, and the artifact guard gate database execution; results are normalized and protected before they cross the facade. The base package imports only pydantic and PyYAML; database drivers, LLM SDKs, and service backends load only when explicitly composed.

Product fit

NL2Data is designed for Python applications that need natural-language queries without handing the model unrestricted database access. Teams define business entities, fields, relationships, and policies; the host supplies trusted context and backends; the runtime validates each query against those boundaries and returns a protected outcome with safe evidence.

  • Semantic onboarding: author a semantic assembly or convert the supported WrenAI MDL JSON subset offline with nl2data-mdl.
  • Governed SQL analytics: filters, common aggregations, grouping, ordering, bounded results, authorized multi-entity inner joins, and a closed set of computed expressions.
  • Composable runtimes: use SQL (SQLite/PostgreSQL), MongoDB, and optional model, memory, and workflow-state packages through explicit composition.

This is a library, not a hosted query service: there is no HTTP host, and the query language is intentionally bounded rather than arbitrary SQL. See the capability matrix for backend differences and verification status.

Packaging

Aspect Value
Distribution nl2data-core (Python 3.11+)
Public API import nl2data
Internal API nl2data_core — contributor-only, applications must not import it
Optional extras sql, postgres, redis
Optional sibling nl2data-openai (OpenAI structured-output provider), nl2data-mongodb (MongoDB adapter), nl2data-workflow-postgres (PostgreSQL workflow state backend)

Install

pip install nl2data-core

The core facade and MDL importer need only the base package. To compile SQL queries locally, install the SQL extra:

pip install "nl2data-core[sql]"

For development (editable install with test/type/lint tooling):

pip install -e ".[dev]"

Facade behavior without a runtime

An empty profile is intentionally non-executable. This small example shows the safe fallback contract; it does not run a data query. For an executable governed flow, start with the mainflow demo or bind a configured runtime as described in the CompositionProfile reference.

import asyncio

from nl2data import CompositionProfile, create_facade, OutcomeStatus, QueryRequest


async def main() -> None:
    facade = create_facade(composition=CompositionProfile())
    await facade.initialize()

    outcome = await facade.aquery(
        QueryRequest(request_id="req-1", prompt="How many orders shipped yesterday?")
    )

    # Without a configured runtime the facade returns an explicit,
    # protected not-configured outcome instead of fabricating a result.
    assert outcome.status == OutcomeStatus.NOT_CONFIGURED

    await facade.close()


asyncio.run(main())

Every query returns a protected QueryOutcome; internal details never cross the public boundary. A deterministic runtime requires an adapter, policy scope, authorized view, and plan resolver. A model provider, state store, tenant context, and other services are composed as required by the host. See the quickstart.

Capability and support status

Capability Status Prerequisites
Public facade, lifecycle, protected outcomes Implemented + conformant None
Semantic IR, View/Bundle resolution Implemented + conformant None
Governed workflow runtime (deterministic) Implemented + conformant None
SQL adapter and bounded query compiler (SQLite fixtures) Implemented + conformant sql extra (sqlglot)
SQL multi-entity inner joins and computed expressions Implemented + conformant SQL adapter; authorized relationship path
SQL adapter (PostgreSQL) Implemented; service-verified in CI nl2data-postgres package + service
MongoDB adapter (single-collection queries and aggregation) Implemented; service-verified in CI nl2data-mongodb package + service
Durable workflow state (SQLite) Implemented + conformant None
Shared workflow state (PostgreSQL) Implemented; service-verified in CI nl2data-workflow-postgres package + service
Memory (in-memory) Implemented + conformant None
Memory (Redis) Implemented; service-verified in CI redis extra + service
Metadata discovery (PostgreSQL/MongoDB) Implemented; service-verified in CI nl2data-postgres/nl2data-mongodb package + service
AI intent resolution + evaluation Implemented + conformant nl2data-openai for live provider
Value-level semantics (enum value mapping) Implemented + conformant None
WrenAI MDL to semantic-assembly importer Implemented + conformant nl2data-mdl CLI; supported MDL JSON subset
OpenAI structured-output provider Implemented; live-verified on demand nl2data-openai + credentials

Status vocabulary: Implemented (exists in source), Conformant (passes the deterministic conformance suite), Verified (passed a real-service/live-provider run). Nothing in this repository claims general production support for unverified adapters, transports, or deployment topologies — see Production readiness.

Value-level semantics (v4.1): enum-coded fields may declare a governed value_mapping. Filter values resolve by deterministic lookup at the intent-resolution stage — before the IR freezes — never by model invention (invariant N4: no probabilistic construction; deterministic governed lookup permitted). Unknown values fail at the resolution stage (VS_001), not at the compiler. See the Semantic layer.

Limitations

  • At-least-once execution: interrupted workflows may re-run stages; this core never claims exactly-once external execution.
  • No HTTP hosting: there is no nl2data_http package yet; hosting behind HTTP is out of scope (a future host programs against the transport-neutral FacadePort).
  • Bounded query language: SQL supports authorized inner joins and a closed computed-expression subset; outer joins, arbitrary SQL/CTEs, and general-purpose window expressions are not exposed. MongoDB does not support cross-collection joins or SQL computed expressions.
  • No streaming, agent loops, or autonomous repair beyond the bounded extension points; approval-required is an internal runtime event only.
  • Process-local metadata ledger: cross-process metadata lifecycle coordination is a host responsibility.
  • Real-service verification is environment-dependent: without a service or driver, real-service profiles skip explicitly — never a false pass.

Documentation

Development

python -m pytest                      # full unit/contract/integration/security suite
python -m mypy src packages/nl2data-openai/src  # static type checking
python -m ruff check src tests packages/nl2data-openai/src  # lint
python scripts/check_docs.py          # documentation quality gates

See Local development.

Metadata

Release files for nl2data-core 0.1.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 nl2data-core 0.1.0
File Size Uploaded
nl2data_core-0.1.0.tar.gz 398.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nl2data-core 0.1.0
File Interpreter ABI Platform
nl2data_core-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 898.6 kB

Release files / nl2data_core-0.1.0.tar.gz

Download URL nl2data_core-0.1.0.tar.gz
Size 398.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6a0fae5545da7f049736736be8fab0c3591013e9e935b83e9836283fc09f5ac3
BLAKE2b-256 checksum
How to use checksums
89ce84c3eaa39c4c3ee16fc1ce624f3f6bb41fa64df03abcf325d03749f79aef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 9, 2026.

Transparency log

Release files / nl2data_core-0.1.0-py3-none-any.whl

Download URL nl2data_core-0.1.0-py3-none-any.whl
Size 500.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cdc65697877357c6cc260be4e550ca0f40622db965c93543389f9f4d3fb5b9a1
BLAKE2b-256 checksum
How to use checksums
a9afe60af2e5036f48564e66a4bce628eb7f97710fc5d07b77ef250f033ca109
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 9, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

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