Metadata-Version: 2.4
Name: prograph
Version: 1.4.0
Summary: A multi-language graph query engine for Python with multiple execution backends
License-Expression: Apache-2.0
Project-URL: Homepage, https://gitlab.com/briceg/prograph
Project-URL: Documentation, https://briceg.gitlab.io/prograph/
Project-URL: Source, https://gitlab.com/briceg/prograph
Project-URL: Issues, https://gitlab.com/briceg/prograph/-/issues
Project-URL: Changelog, https://gitlab.com/briceg/prograph/-/blob/main/docs/changelog.md
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Database
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: antlr4-python3-runtime>=4.13.0
Requires-Dist: structlog>=24.0.0
Requires-Dist: pyyaml>=6.0.0
Requires-Dist: pyarrow>=20
Requires-Dist: rdflib>=7.0.0
Provides-Extra: dev
Requires-Dist: pytest==9.0.3; extra == "dev"
Requires-Dist: pytest-bdd==8.1.0; extra == "dev"
Requires-Dist: pytest-cov==7.1.0; extra == "dev"
Requires-Dist: pytest-xdist==3.8.0; extra == "dev"
Requires-Dist: duckdb==1.5.6; extra == "dev"
Requires-Dist: pyarrow==23.0.1; extra == "dev"
Requires-Dist: pandas==2.3.3; extra == "dev"
Requires-Dist: pyspark==4.1.3; extra == "dev"
Requires-Dist: numpy==2.4.5; extra == "dev"
Requires-Dist: mcp==1.27.1; extra == "dev"
Requires-Dist: rdflib==7.6.0; extra == "dev"
Requires-Dist: pyoxigraph==0.5.13; extra == "dev"
Requires-Dist: pyshacl==0.31.0; extra == "dev"
Requires-Dist: owlrl==7.1.4; extra == "dev"
Requires-Dist: antlr4-python3-runtime==4.13.2; extra == "dev"
Requires-Dist: structlog==25.5.0; extra == "dev"
Requires-Dist: pyyaml==6.0.3; extra == "dev"
Requires-Dist: adbc-driver-postgresql==1.12.0; extra == "dev"
Requires-Dist: adbc-driver-manager==1.12.0; extra == "dev"
Requires-Dist: oracledb==26.0.1; extra == "dev"
Requires-Dist: pyodbc==5.3.0; extra == "dev"
Requires-Dist: mysql-connector-python==9.7.0; extra == "dev"
Requires-Dist: databricks-sql-connector[kernel]==4.9.0; extra == "dev"
Requires-Dist: databricks-sql-kernel==1.4.0; extra == "dev"
Requires-Dist: graphql-core==3.2.13; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"
Requires-Dist: isort>=5.12.0; extra == "dev"
Requires-Dist: mypy>=1.0.0; extra == "dev"
Requires-Dist: flake8>=6.0.0; extra == "dev"
Requires-Dist: sqlglot==28.7.0; extra == "dev"
Requires-Dist: fastapi==0.136.1; extra == "dev"
Requires-Dist: uvicorn==0.47.0; extra == "dev"
Requires-Dist: python-multipart==0.0.29; extra == "dev"
Requires-Dist: httpx==0.28.1; extra == "dev"
Provides-Extra: pandas
Requires-Dist: pandas<3,>=2.0.0; extra == "pandas"
Provides-Extra: duckdb
Requires-Dist: duckdb<2,>=1.5.3; extra == "duckdb"
Requires-Dist: pandas<3,>=2.0.0; extra == "duckdb"
Provides-Extra: postgresql
Requires-Dist: adbc-driver-postgresql>=1.12; extra == "postgresql"
Provides-Extra: oracle
Requires-Dist: oracledb>=26.0.1; extra == "oracle"
Provides-Extra: spark
Requires-Dist: pyspark>=4.1.0; extra == "spark"
Provides-Extra: ontology
Provides-Extra: shacl
Requires-Dist: pyshacl>=0.31.0; extra == "shacl"
Provides-Extra: r2rml
Provides-Extra: logging
Requires-Dist: structlog>=24.0.0; extra == "logging"
Provides-Extra: nlp
Requires-Dist: openai>=1.0.0; extra == "nlp"
Provides-Extra: nlp-databricks
Requires-Dist: openai>=1.0.0; extra == "nlp-databricks"
Requires-Dist: databricks-sdk>=0.20.0; extra == "nlp-databricks"
Provides-Extra: nlp-langchain
Requires-Dist: openai>=1.0.0; extra == "nlp-langchain"
Requires-Dist: databricks-langchain>=0.1.0; extra == "nlp-langchain"
Requires-Dist: langchain>=0.1.0; extra == "nlp-langchain"
Provides-Extra: ui
Requires-Dist: fastapi>=0.109.0; extra == "ui"
Requires-Dist: jinja2>=3.1.0; extra == "ui"
Requires-Dist: uvicorn>=0.27.0; extra == "ui"
Requires-Dist: python-multipart>=0.0.6; extra == "ui"
Provides-Extra: endpoint
Requires-Dist: fastapi>=0.109.0; extra == "endpoint"
Requires-Dist: uvicorn>=0.27.0; extra == "endpoint"
Requires-Dist: python-multipart>=0.0.6; extra == "endpoint"
Requires-Dist: duckdb<2,>=1.5.3; extra == "endpoint"
Requires-Dist: pandas<3,>=2.0.0; extra == "endpoint"
Provides-Extra: databricks
Requires-Dist: databricks-sql-connector>=4.9; extra == "databricks"
Requires-Dist: databricks-sdk>=0.40.0; extra == "databricks"
Provides-Extra: databricks-rt
Requires-Dist: databricks-sql-connector[kernel]>=4.9.0; extra == "databricks-rt"
Requires-Dist: databricks-sdk>=0.40.0; extra == "databricks-rt"
Provides-Extra: cli
Requires-Dist: pandas<3,>=2.0.0; extra == "cli"
Provides-Extra: graphql
Requires-Dist: graphql-core<3.3,>=3.2; extra == "graphql"
Provides-Extra: mcp
Requires-Dist: mcp<2,>=1.27; extra == "mcp"
Requires-Dist: duckdb<2,>=1.5.3; extra == "mcp"
Requires-Dist: pandas<3,>=2.0.0; extra == "mcp"
Requires-Dist: openai>=1.0.0; extra == "mcp"
Provides-Extra: genie
Requires-Dist: databricks-sdk>=0.40.0; extra == "genie"
Requires-Dist: databricks-sql-connector>=3.0.0; extra == "genie"
Requires-Dist: rdflib>=7.0.0; extra == "genie"
Requires-Dist: pandas<3,>=2.0.0; extra == "genie"
Requires-Dist: pyyaml>=6.0; extra == "genie"
Provides-Extra: test-sql
Requires-Dist: adbc-driver-postgresql>=1.12; extra == "test-sql"
Requires-Dist: mysql-connector-python>=8.0; extra == "test-sql"
Requires-Dist: oracledb>=26.0.1; extra == "test-sql"
Requires-Dist: pyodbc>=5.0; extra == "test-sql"
Provides-Extra: docs
Requires-Dist: mkdocs==1.6.1; extra == "docs"
Requires-Dist: mkdocs-material==9.8.2; extra == "docs"
Requires-Dist: pymdown-extensions==13.1.2; extra == "docs"
Dynamic: license-file

# ProGraph

ProGraph is a virtual knowledge graph that answers SPARQL and Cypher queries over the tables you already have. You describe how your tables map to a graph. ProGraph translates each query into one SQL statement, and your database runs it. Nothing is copied or loaded, and ProGraph doesn't write to your tables (unless you mark a mapping `mutable` and call `set_properties`).

## Why consider it

- **No copy, no pipeline.** The graph is a view over live tables: a query sees the data as it is now. There's no export to a graph database, no extract-transform-load job, and nothing to keep in sync.
- **SPARQL and Cypher over one mapping.** One mapping serves both the RDF view (SPARQL 1.1) and the property-graph view (openCypher). Teams that think in triples and teams that think in nodes and relationships query the same data.
- **Reasoning without materialising everything.** Give ProGraph an OWL ontology, and queries answer with what the ontology implies, not only what the tables state. OWL 2 QL is answered by rewriting the query, so nothing is stored and answers are always current. OWL 2 RL is materialised into ProGraph's own tables, never yours, and by default read only while your tables are provably unchanged. **Cypher reads the RL facts too: derived labels, relationships and properties, and one node per `owl:sameAs` entity.**
- **Built for Databricks.** It runs on serverless SQL warehouses and Lakehouse RT over Unity Catalog tables, in place. It recognises which kind of warehouse it is on, and plans with the rewrites measured on that kind.
- **Checked against the standards.** SPARQL is checked on the W3C test suites, and its own test corpus against Apache Jena and Oxigraph. Cypher is checked with the openCypher TCK: on 1.3.0 it gave no wrong answers across 2,880 scenarios on DuckDB and Spark.
- **Runs where your data is.** Databricks (serverless SQL warehouses and Lakehouse RT), Apache Spark with Delta Lake, DuckDB (databases, Parquet and CSV files, pandas DataFrames), PostgreSQL and Lakebase, Oracle, SQL Server and MySQL.
- **Python first.** Answers come back as Apache Arrow tables (or lists, or pandas DataFrames). A SPARQL endpoint and an MCP server, with a natural-language `ask` tool, are included.

## Install

```bash
pip install "prograph[duckdb]"          # DuckDB, over files or pandas DataFrames
pip install "prograph[databricks]"      # Databricks SQL warehouses
pip install "prograph[databricks-rt]"   # Lakehouse RT (the connector's kernel path)
```

Python 3.11 or later. The extras, from `pyproject.toml`; install the ones you use:

| Extra | Adds |
|---|---|
| `duckdb` | DuckDB and pandas: the default engine over DataFrames, and DuckDB databases |
| `pandas` | pandas 2 |
| `postgresql` | the ADBC PostgreSQL driver |
| `oracle` | `oracledb` |
| `spark` | PySpark 4.1 or later |
| `databricks` | the Databricks SQL connector and SDK |
| `databricks-rt` | the connector's kernel path, for Lakehouse RT warehouses |
| `shacl` | pyshacl, for `engine.validate_shapes()` |
| `endpoint` | the SPARQL Protocol server, `prograph serve` |
| `mcp` | the MCP server and the model client its `ask` tool uses |
| `cli` | `prograph load-ttl` and `prograph infer-schema` |
| `nlp`, `nlp-databricks`, `nlp-langchain` | the natural-language interface |
| `genie` | the Databricks Genie integration |
| `logging`, `ui`, `graphql` | structlog; the web UI; GraphQL (experimental) |

## Quickstart

One table, one mapping, the same question in SPARQL and in Cypher:

```python
import duckdb
from prograph import ProGraph

con = duckdb.connect()
con.execute("CREATE TABLE people (id INTEGER, name VARCHAR, age INTEGER)")
con.execute("INSERT INTO people VALUES (1, 'Alice', 30), (2, 'Bob', 25)")

engine = ProGraph.from_yaml("""
version: "1.0"
graph: {name: people}
sources: {people: {table: people}}
nodes:
  - label: Person
    source: people
    id_column: id
    iri_template: "http://example.org/person/{id}"
    class_iri: "http://example.org/Person"
    properties: {name: name, age: age}
rdf: {vocab_iri: "http://example.org/", auto_generate: true}
""", connection=con)

engine.execute("""
PREFIX ex: <http://example.org/>
SELECT ?name WHERE { ?p a ex:Person ; ex:name ?name ; ex:age ?age . FILTER(?age > 26) }
""", return_type="list")
# [{'name': 'Alice'}]

engine.execute("MATCH (p:Person) WHERE p.age > 26 RETURN p.name AS name",
               language="cypher", return_type="list")
# [{'name': 'Alice'}]
```

`ProGraph.from_r2rml(path, connection=con)` reads a W3C R2RML mapping instead. An R2RML mapping serves SPARQL, with OWL 2 QL or RL reasoning and SHACL; Cypher needs the YAML mapping, which names the labels and relationship types it uses. More: [your first knowledge graph](https://gitlab.com/briceg/prograph/-/blob/main/docs/start/first-knowledge-graph.md), [map your tables](https://gitlab.com/briceg/prograph/-/blob/main/docs/sparql/mapping.md), [R2RML tutorial](https://gitlab.com/briceg/prograph/-/blob/main/docs/start/r2rml-tutorial.md).

## On Databricks

```python
from databricks import sql
from prograph import ProGraph

con = sql.connect(server_hostname=..., http_path=..., credentials_provider=...)
engine = ProGraph.from_config("graph.yaml", connection=con, backend="databricks_sql")
```

- **Warehouses.** Serverless SQL warehouses and Lakehouse RT. ProGraph reads which kind it is connected to when the engine starts, and the rewrites whose gain depends on the engine run only on the kinds where they were timed faster. On Lakehouse RT, install the `databricks-rt` extra.
- **Tables.** Unity Catalog names (`catalog.schema.table`) in the mapping. ProGraph reads the tables in place.
- **Runs as the user.** In a notebook or your own code, ProGraph uses whatever connection you give it, so it runs as you. As a shared server on a Databricks App, `prograph serve` (and `--mcp`) runs every request as the signed-in user (on-behalf-of-user authorization): each user gets their own engine and connection, and Unity Catalog applies their grants, row filters and column masks, with the person in the audit log. Off an App, `prograph serve --per-user` does the same with each request's bearer token.
- **Keys.** ProGraph reads primary keys declared `RELY` and uses them to drop joins and duplicate checks that can't change the answer. Lakehouse RT doesn't report `RELY`: there, declare keys in the mapping (`keys: trusted`). Declaring your keys is the single biggest performance step.
- **Reasoning.** OWL 2 QL works on every warehouse. OWL 2 RL writes its facts to ProGraph's own Delta tables; that is checked on a serverless SQL warehouse, not yet on Lakehouse RT.
- **Every statement accounted for.** `engine.startup_statements` lists what building the engine sent to the warehouse, and `engine.last_statements` what the last query sent, each with its purpose and time (the query by a fingerprint, never its text).
- **Agents and Genie.** The MCP server's `ask` tool turns a question into SPARQL or Cypher, runs it, and retries on an error. A Genie integration is included (`genie` extra).

See [ProGraph on Databricks](https://gitlab.com/briceg/prograph/-/blob/main/docs/guides/deploy-for-a-team.md).

## Reasoning

Pass an ontology, and reasoning is on:

```python
from prograph.ontology import OntologyLayer
from prograph.store import Store

model = OntologyLayer.from_owl("model.ttl")
engine = ProGraph.from_config("graph.yaml", connection=con, ontology=model)          # OWL 2 QL
engine = ProGraph.from_config("graph.yaml", connection=con, ontology=model,
                              profile="rl", store=Store(con))                        # OWL 2 RL
```

| | SPARQL | Cypher |
|---|---|---|
| RDFS core (subclass, sub-property, domain, range) | yes, always on with an ontology | yes: inferred labels, relationship types and property keys |
| OWL 2 QL (`profile="ql"`, the default), by rewriting | every QL axiom: inverses, symmetric and reflexive properties, existentials, `owl:Thing`, … | hierarchies, domain and range, inverse and symmetric properties, `owl:Thing` |
| OWL 2 RL (`profile="rl"`), materialised into ProGraph's store | yes, with `owl:sameAs` | yes: derived labels, relationships and properties; one node per `owl:sameAs` entity |
| Consistency checks | yes: contradictions raise `InconsistentOntologyError`, or are reported | the same engine checks |

On the W3C tests: the OWL 2 QL positive entailment tests all pass (19 of 19), the OWL 2 RL inconsistency tests all raise (14 of 14), and the SPARQL entailment tests of the RDF and RDFS regimes all pass (58 of 58).

`owl:imports` is read from local files only. See [OWL and ontology](https://gitlab.com/briceg/prograph/-/blob/main/docs/guides/owl-and-ontology.md) and [OWL 2 RL](https://gitlab.com/briceg/prograph/-/blob/main/docs/reference/owl.md).

## Backends

| Backend | Extra | Checked |
|---|---|---|
| Databricks SQL warehouse, Lakehouse RT | `databricks`, `databricks-rt` | every release |
| DuckDB, over a database or pandas DataFrames | `duckdb` | every release |
| Spark (a SparkSession, with Delta Lake) | `spark` | every release |
| PostgreSQL (and Lakebase) | `postgresql` | every release |
| Oracle, SQL Server, MySQL 8.0+ | `oracle`; none (install `pyodbc` and ODBC Driver 18, or `mysql-connector-python`) | at milestones; Cypher unchecked |

"Every release": the release gate runs the SPARQL corpus and the Cypher TCK there. "At milestones": checked at each milestone, and a fault found only there is fixed after the others. See [what differs by backend](https://gitlab.com/briceg/prograph/-/blob/main/docs/reference/backend-differences.md).

## Know before you start

- **Keys.** Cypher trusts a node mapping's key by default (one row per key value); `check_keys=True` checks keys in every query, and `keys: check` checks a mapping's key once per version of a versioned source (Delta, DataFrames). SPARQL removes duplicates unless keys are declared, as the standard's set semantics require. Declaring keys is the main performance advice for both.
- **Read-only.** ProGraph answers queries; it doesn't update your tables (unless a mapping is marked `mutable`). Cypher `CREATE`, `MERGE` and `SET` write only to ProGraph's own store (`store=`).
- **Cypher needs a YAML mapping.** An R2RML mapping serves SPARQL, with OWL 2 QL or RL and SHACL; Cypher needs YAML.
- **No table statistics in planning.** ProGraph applies only rewrites proven safe, and leaves join order to your database. A few query shapes stay costly on large tables by nature; [Make queries fast](https://gitlab.com/briceg/prograph/-/blob/main/docs/guides/make-queries-fast.md#write-queries-that-scale) lists them.
- **Young.** 1.0 shipped in November 2026.

## More

- [Documentation](https://gitlab.com/briceg/prograph/-/blob/main/docs/README.md) and [How ProGraph works](https://gitlab.com/briceg/prograph/-/blob/main/docs/explanation/how-prograph-works.md)
- [llms.txt](https://gitlab.com/briceg/prograph/-/blob/main/llms.txt), a reference for LLMs and agents
- [Changelog](https://gitlab.com/briceg/prograph/-/blob/main/docs/changelog.md)
- [Licence](https://gitlab.com/briceg/prograph/-/blob/main/LICENSE): Apache-2.0
