Skip to main content

nl2data-postgres

An optional PostgreSQL backend integration for nl2data-core. It combines metadata discovery and governed read-only SQL execution behind the core provider-neutral contracts.

psycopg is an optional dependency and is loaded lazily at first use. The core import boundary never loads the PostgreSQL driver.

Install

pip install nl2data-postgres

Requires Python 3.11+, nl2data-core>=0.1.0, and psycopg[binary,pool]>=3.1,<4.

From a source checkout:

pip install -e packages/nl2data-postgres

Public surface

from nl2data_postgres import (
    PostgresAdapterConfig,
    PostgresMetadataDiscoverer,
    PostgresQueryAdapter,
)
  • PostgresAdapterConfig — bounded discovery/execution configuration with host-injected DSN references, object/field allowlists, and result bounds.
  • PostgresMetadataDiscoverer — the core MetadataDiscoverer port implementation for PostgreSQL.
  • PostgresQueryAdapter — the core QueryAdapter port implementation for read-only PostgreSQL SQL.

Configuration

Configuration is credential-free; hosts inject DSNs through a resolver or environment at runtime. PostgresAdapterConfig carries only bounded, fingerprintable settings.

from nl2data_postgres import PostgresAdapterConfig

config = PostgresAdapterConfig(
    dsn_reference="env:NL2DATA_POSTGRES_DSN",
    allowed_objects={"users", "orders"},
    max_objects=256,
    max_rows=10_000,
)

Discovery

from nl2data_postgres import PostgresAdapterConfig, PostgresMetadataDiscoverer
from nl2data_core.metadata.protocol import MetadataDiscoveryConfig

discoverer = PostgresMetadataDiscoverer(
    config=PostgresAdapterConfig(dsn_reference="env:NL2DATA_POSTGRES_DSN"),
    allowed_objects={"users", "orders"},
)
snapshot = await discoverer.discover(MetadataDiscoveryConfig())

Discovery returns a core MetadataSnapshot with normalized tables, columns, types, primary/foreign keys, and bounded protected statistics.

Query execution

from nl2data_postgres import PostgresAdapterConfig, PostgresQueryAdapter
from nl2data_core.adapters.models import ValidationContext

adapter = PostgresQueryAdapter(
    config=PostgresAdapterConfig(dsn_reference="env:NL2DATA_POSTGRES_DSN"),
    allowed_objects={"users"},
)
artifact = adapter.parse("SELECT id, name FROM users LIMIT 10", ValidationContext())
validated = adapter.validate(artifact, ValidationContext())
result = await adapter.execute(validated, ValidationContext())

Execution uses a read-only connection pool, enforces statement timeout, limits rows/columns/bytes, and maps every result value to the protected scalar set.

Failure classification

Condition Normalized result
Missing driver / unreachable service Retryable MetadataUnavailableError
Authorization or permission denial MetadataUnauthorizedError
Lifecycle misuse (unparsed/unvalidated artifacts) PostgresAdapterError
Guard rejection (scope/obligation/limit) SQLGuardError
Statement/result bounds exceeded PostgresExecutionError
Malformed SQL SQLParseError

DSNs, raw SQL, native exceptions, and credentials never cross the boundary.

Compatibility

The in-core nl2data_core.adapters.sql.SqlMetadataDiscoverer still accepts dialect="postgresql" as a temporary compatibility path, but it always uses the legacy in-core implementation and emits a deprecation warning; it does not delegate to this package. New code should import from nl2data_postgres directly.

More documentation

Metadata

Release files for nl2data-postgres 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-postgres 0.1.0
File Size Uploaded
nl2data_postgres-0.1.0.tar.gz 19.7 kB Details

Built distribution (wheel)

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

Total release size: 35.1 kB

Release files / nl2data_postgres-0.1.0.tar.gz

Download URL nl2data_postgres-0.1.0.tar.gz
Size 19.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4aaa5a4d26f7649495f056917498284a0047d144026d39ad807d3804e681c941
BLAKE2b-256 checksum
How to use checksums
727f6e1854a93bb6e938d0cf16747d540273be4f9e162620be74120464edc9ae
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 12, 2026.

Transparency log

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

Download URL nl2data_postgres-0.1.0-py3-none-any.whl
Size 15.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
92112e7c0e087adb307708083fdbbdbd2403594bdf24e654378ece6bea8eb020
BLAKE2b-256 checksum
How to use checksums
b88b06b4f1a960cdb873492ee15c07b06982af541dce721307ea3b5f270270a5
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 12, 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