Metadata-Version: 2.4
Name: text2sql-lite
Version: 0.1.0
Summary: Convert natural English to SQL with SQLite/Postgres dialects (offline heuristics).
Project-URL: Homepage, https://github.com/sriramsreedhar/text2sql-lite
Project-URL: Repository, https://github.com/sriramsreedhar/text2sql-lite
Project-URL: Issues, https://github.com/sriramsreedhar/text2sql-lite/issues
Author: text2sql-lite contributors
License-Expression: MIT
Keywords: nlp,postgres,sql,sqlite,text2sql
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Database
Requires-Python: >=3.10
Provides-Extra: dev
Requires-Dist: mypy>=1.11.0; extra == 'dev'
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Requires-Dist: ruff>=0.6.0; extra == 'dev'
Provides-Extra: postgres
Requires-Dist: psycopg[binary]>=3.1.0; extra == 'postgres'
Description-Content-Type: text/markdown

# text2sql-lite

Source: [github.com/sriramsreedhar/text2sql-lite](https://github.com/sriramsreedhar/text2sql-lite)

Turn short English requests into **SQLite** or **PostgreSQL** SQL using **offline heuristics** only—no API keys, no models, no network.

## Install

```bash
pip install text2sql-lite
```

Optional extra for Postgres schema introspection:

```bash
pip install "text2sql-lite[postgres]"
```

## Quick start

```python
from text2sql_lite import translate, Dialect
from text2sql_lite.schema import Table, Column, TableSchema

schema = TableSchema(
    (
        Table(
            "users",
            (Column("id"), Column("email"), Column("state")),
        ),
    )
)

result = translate(
    "show users from texas",
    dialect=Dialect.POSTGRES,
    schema=schema,
)
print(result.sql)
print(result.notes)
```

## API highlights

- **`translate(...)`** — pattern-based English → SQL; raises `ValueError` if the phrase is not recognized.
- **`Dialect.SQLITE` / `Dialect.POSTGRES`** — identifier quoting and string matching (`ILIKE` vs `LIKE`) tuned per engine.
- **`introspect_sqlite(path)`** — build a `TableSchema` from a `.db` file (`from text2sql_lite.introspect import introspect_sqlite`).
- **`introspect_postgres(conn)`** — same for a `psycopg` connection (`[postgres]` extra).

## Limits

Heuristics cover a **narrow** set of shapes (list rows, optional “from &lt;place&gt;” filters, simple `WHERE col op value`, `LIMIT`). Always **review** generated SQL before execution.

## Development

```bash
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest
```
