Metadata-Version: 2.5
Name: cypher2sql
Version: 0.1.0
Summary: Write Cypher graph patterns against your existing PostgreSQL schema; get back plain SQL that selects the matching primary keys.
Project-URL: Repository, https://github.com/OffworldNexus/cypher2sql
Project-URL: Issues, https://github.com/OffworldNexus/cypher2sql/issues
Author-email: Rémy Sanchez <remy.sanchez@hyperthese.net>
License-Expression: Apache-2.0
License-File: LICENSE
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Database
Classifier: Typing :: Typed
Requires-Python: >=3.12
Description-Content-Type: text/markdown

# cypher2sql

[![CI](https://github.com/OffworldNexus/cypher2sql/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/OffworldNexus/cypher2sql/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/cypher2sql.svg)](https://pypi.org/project/cypher2sql/)
[![Python](https://img.shields.io/badge/python-3.12%20%7C%203.13%20%7C%203.14-blue.svg)](https://github.com/OffworldNexus/cypher2sql/blob/develop/pyproject.toml)
[![Docs](https://img.shields.io/badge/docs-offworldnexus.github.io%2Fcypher2sql-blue.svg)](https://offworldnexus.github.io/cypher2sql/)
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://github.com/OffworldNexus/cypher2sql/blob/develop/LICENSE)

**Answer graph questions on the PostgreSQL schema you already have — up to 17.1× faster than Neo4j (median 6.1×), no migration.**

Install with `pip install cypher2sql`, describe your tables and foreign keys once, write Cypher, get one parameterized SQL query that returns the primary keys you asked for.

[Documentation](https://offworldnexus.github.io/cypher2sql/) · [Tutorial](https://offworldnexus.github.io/cypher2sql/tutorial/) · [API reference](https://offworldnexus.github.io/cypher2sql/api/) · [Performance](https://offworldnexus.github.io/cypher2sql/performance/) · [openCypher parity](https://offworldnexus.github.io/cypher2sql/api/#feature-parity-with-neo4j)

```python
from cypher2sql import Edge, Node, Schema

customer = Node("Customer", table="customer", key="id", properties={"country": str})
order = Node("Order", table="order", key="id", properties={"id": int})
shop = Schema(
    nodes=[customer, order],
    edges=[Edge("PLACED", customer, order, source_columns="customer_id")],
)

q = shop.to_sql(
    "MATCH (c:Customer {country: $country})-[:PLACED]->(:Order) RETURN c",
    {"country": "FR"},
)
print(q.sql)
print(q.params)
```
```text title="output"
SELECT n1."id"
FROM "customer" AS n1
WHERE n1."country" COLLATE "C" = %s::text
  AND EXISTS (
    SELECT 1
    FROM "order" AS n2
    WHERE n2."customer_id" = n1."id"
  )
('FR',)
```

Run it with any driver: `conn.execute(q.sql, q.params)` (psycopg), or feed it to your ORM. A single-column
key fits `WHERE id IN (...)`, a `psycopg.sql` wrapper still needs your own literal `%` as `%%`, and composite keys
join a CTE. Compiling never touches the database; on Python ≥ 3.14 a
[t-string](https://github.com/OffworldNexus/cypher2sql/blob/develop/docs/api.md#t-string-queries) carries its
values as `{expr}` and takes no `params` dict.

- Your database stays relational: no graph extension, no data migration, no runtime dependencies.
- Property values are always bound parameters; a label/type selector only chooses among identifiers from your
  declared schema.

Start with the
[tutorial](https://github.com/OffworldNexus/cypher2sql/blob/develop/docs/tutorial.md); every name
is in the
[API reference](https://github.com/OffworldNexus/cypher2sql/blob/develop/docs/api.md).

## Correctness

Correctness is checked on a real PostgreSQL against the official
[openCypher TCK](https://github.com/opencypher/openCypher/tree/main/tck), vendored in
`vendor/opencypher-tck/`: 220 features, 3,897 scenario instances (1,615 declarations; outlines expand to 3,897).
`tests/tck/scope.toml` classifies every instance and
[the design](https://github.com/OffworldNexus/cypher2sql/blob/develop/docs/design.md#tck) records why.
`make tck` prints the live split: its first line is
`in-scope passing: N / N, out-of-scope: M (by category)`, then `planned: P (must not pass)` and one
count line per category, including `in`; N, M and P are the live counts.
[The vision](https://github.com/OffworldNexus/cypher2sql/blob/develop/docs/VISION.md#correctness-bar-the-opencypher-tck)
states that split.

## License

Apache-2.0. The vendored openCypher TCK and grammar are Apache-2.0 (see `vendor/*/NOTICE`).
