Packages and Boundaries
The four Python packages, what each may import and why, for contributors who add code and adapter authors who build against the SDK.
The packages
| Package | Import name | Folder | Role |
|---|---|---|---|
nl2sql-sdk |
nl2sql_sdk |
packages/sdk/ |
The contract an adapter or plugin compiles against: protocols, policy types, store interfaces |
nl2sql-engine |
nl2sql |
packages/nl2sql/ |
The library: pipeline, indexing, conversations, dashboards, the bundled adapters and the MCP server |
nl2sql-api |
nl2sql_api |
packages/api/ |
The REST API and the web app's server; the built UI ships inside it |
nl2sql-cli |
nl2sql_cli |
nl2sql-cli/ |
The nl2sql command and the terminal app (nl2sql chat) |
The web app's source lives in nl2sql-ui/. It is built to nl2sql_api/web/static/ and shipped with the API.
flowchart TD
sdk["nl2sql-sdk"]
engine["nl2sql-engine (import nl2sql)"]
api["nl2sql-api"]
cli["nl2sql-cli"]
adapters["adapters inside the engine"]
engine --> sdk
adapters --> sdk
engine -.-> adapters
api --> engine
cli --> engine
cli -. "web extra" .-> api
The engine reaches adapters only through the nl2sql.adapters entry point group; the dotted arrow is that lookup, not an import.
What each may import
- The SDK core imports only pydantic and the standard library. Its extras add more:
nl2sql_sdk.sqlalchemy(thesqlalchemyextra) imports SQLAlchemy and sqlglot, andnl2sql_sdk.testing(thetestingextra) imports pytest and sqlglot. The core imports neither. Whatever the SDK imports, every adapter author inherits. - An adapter imports only the SDK, its driver, SQLAlchemy, sqlglot, pydantic and the standard library. An adapter that imported the engine would close the circle.
- Nothing outside
nl2sql/adapters/(and the SDK's SQLAlchemy base) imports an adapter, SQLAlchemy or a database driver. Adapters are found through the entry points and used throughDatasourceAdapter, so a datasource this repository has never seen works the same way. - The engine and the API never import the CLI, and the engine has no
clipackage. Knowledge an SDK or REST caller also needs belongs in the engine. - The CLI imports only the top-level
nl2sql. It never importsnl2sql_sdkornl2sql_api. Its one dependency on another package of this project isnl2sql-engine, plusnl2sql-apias thewebextra;nl2sql demoandnl2sql servestart the API as a child process (python -m nl2sql_api serve). - The REST API, the CLI and the MCP server import only the top-level
nl2sqlfacade. None reaches the runtime behind it (engine._runtime). What one of them needs is a facade method every caller can use. - Outside the adapters, only the storage package imports
sqlite3, and only the storage package importschromadb(the local embedding model borrows chromadb's embedding function, not its index); only the CLI'schatpackage importstextual; only the MCP package importsmcp. Each heavy dependency has one door.
Rules about loading and the environment
- The runtime never imports
nl2sql.evaluationornl2sql.feedbackat module scope. Both are opt-in tools; a lazy import inside a function is fine. import nl2sqlloads no vector store, database driver,textualoropentelemetry. The package__init__exports through__getattr__and the facade imports the runtime in its constructor, so a caller that only needs a name pays nothing.- A provider's API-key environment variable is read in
nl2sql/llm/only.PROVIDER_PRESETSinnl2sql/llm/registry.pyis the one table. - Nothing writes
os.environ, and it is read only from an allow-list. Configuration travels in the engine'sConfig, so two engines in one process share nothing. See Configuration loading.
Why one-way
A library that names its callers cannot be used without them, and an SDK that grows imports taxes every plugin author. Keeping the arrows pointing from apps to the engine to the SDK means a REST caller, a CLI user and a Python caller see the same behaviour, because they all go through the same facade.
Where it is enforced
packages/nl2sql/tests/architecture/test_boundaries.py walks every source file and fails with a message that names the rule. packages/nl2sql/tests/architecture/test_hooks_boundary.py covers the hook points. The full list of rules, with examples, is in Invariants.