Metadata-Version: 2.5
Name: linksql
Version: 0.1.0
Summary: Python reference implementation of LinksQL — an associative query language built around a single substitution operation.
Project-URL: Homepage, https://github.com/link-foundation/linksql
Project-URL: Repository, https://github.com/link-foundation/linksql
Project-URL: Issues, https://github.com/link-foundation/linksql/issues
License: Unlicense
Keywords: associative,doublets,links,linksql,query
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: The Unlicense (Unlicense)
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.9
Provides-Extra: dev
Requires-Dist: mypy>=1.13.0; extra == 'dev'
Requires-Dist: pytest>=8.3.0; extra == 'dev'
Requires-Dist: ruff>=0.8.0; extra == 'dev'
Description-Content-Type: text/markdown

# LinksQL (Python reference implementation)

A faithful, behaviourally-identical Python port of the JavaScript reference
implementation of **LinksQL** — an associative query language built on **one data
primitive** (the link, a doublet) and **one operation** (substitution).

Everything is a link: a triple `(index: source target)` of positive integers. A
link whose `source` and `target` both equal its own `index` is a *point*, the
atom of the graph. A query is a pair of pattern lists — a *restriction* and a
*substitution* — written `(restriction) (substitution)`; the four CRUD
behaviours (read, create, update, delete) are derived from how the two lists line
up positionally.

The JavaScript implementation in `../js/src` is the ground truth, and the
normative behaviour is defined in
[`../docs/SPECIFICATION.md`](../docs/SPECIFICATION.md).

A link has exactly two endpoints, so a relation like "alice loves bob" is the
higher-order link `((alice loves) bob)` — every pattern carries 0 or 2 values.

## Quick start

```python
from linksql import Database

db = Database()
db.query("() (((alice loves) bob))")  # create the higher-order link
report = db.query("(($i: $s $t))")    # read every relation
print(report.operation, report.matched)
```

## Development

This package uses a src layout. Create a virtual environment and install it with
the development extras:

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

Then run the checks (all must pass):

```bash
ruff check .
ruff format --check .
mypy src
pytest tests/ -v
```

## Public API

The top-level `linksql` package re-exports the engine surface:

- `linksql.lino` — `tokenize`, `parse`, `serialize`, `serialize_all`, the AST
  types (`Ref`, `Link`/`LinkNode`, `Node`, `Token`) and `LinoSyntaxError`.
- `linksql.store` — `LinksStore`, `Link`, `LinkIntegrityError`.
- `linksql.names` — `Names`, `UnknownNameError`.
- `linksql.substitution` — `link_slots`, `match_restriction`, `execute`,
  `link_matches`, `Context`, and `SubstitutionError`.
- `linksql.query` — `Database`, `split_query`, `link_to_lino`, `QueryReport`,
  `QueryError`.
- `linksql.schema` — the GraphQL-class schema model: `Schema`, `Relation`,
  `NamedQuery`, `NamedSubscription`, and `SchemaError`.
