Metadata-Version: 2.4
Name: prograph
Version: 1.3.4
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://gitlab.com/briceg/prograph/-/blob/stable/1.3/docs/README.md
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/stable/1.3/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==24.0.0; 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==4.2.6; 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"
Dynamic: license-file

# ProGraph

ProGraph answers SPARQL 1.1 queries over tables you already have. You give it
a mapping (R2RML or YAML) from tables to RDF terms; each query is translated
to one SQL statement that your database runs. Nothing is copied or loaded:
the data stays where it is, and ProGraph does not write to your tables.

## Install

Python 3.11 or later:

```bash
pip install "prograph[duckdb]"
```

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) |

MySQL and SQL Server have no extra: install `mysql-connector-python` or
`pyodbc` yourself (SQL Server also needs the ODBC Driver 18).

## Quickstart

A DuckDB table, a YAML mapping and one query:

```python
import duckdb
from prograph import ProGraph
from prograph.config import load_config

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)")

open("graph.yaml", "w").write("""
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}
""")
engine = ProGraph(schema=load_config("graph.yaml").to_schema(), connection=con)

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

`ProGraph.from_r2rml(path, connection=con)` reads an R2RML mapping instead.
More: [quickstart](https://gitlab.com/briceg/prograph/-/blob/stable/1.3/docs/sparql/quickstart.md), [map your tables](https://gitlab.com/briceg/prograph/-/blob/stable/1.3/docs/sparql/mapping.md),
[R2RML tutorial](https://gitlab.com/briceg/prograph/-/blob/stable/1.3/docs/start/r2rml-tutorial.md).

## Reasoning

Pass an ontology (`ontology=`) and reasoning is on. The RDFS core is always on
with an ontology. `profile="ql"`, the default, answers OWL 2 QL by rewriting the
query: nothing is stored. `profile="rl"` with an owned store (`store=`)
materializes OWL 2 RL facts into ProGraph's own tables, never yours; a query
reads them only where every mapped table is provably unchanged since the run
that made them. An ontology and data that contradict each other raise
`InconsistentOntologyError` unless `inconsistency="report"`. `owl:imports`
is read from local files only. See [OWL and ontology](https://gitlab.com/briceg/prograph/-/blob/stable/1.3/docs/guides/owl-and-ontology.md)
and [OWL 2 RL](https://gitlab.com/briceg/prograph/-/blob/stable/1.3/docs/reference/owl-rl.md).

## Backends

| Backend | Install | SPARQL | Owned store, `profile="rl"` |
|---|---|---|---|
| DuckDB, over pandas DataFrames or a DuckDB database | `duckdb` | yes | yes |
| PostgreSQL (also Lakebase, over ADBC) | `postgresql` | yes | yes |
| Spark (a SparkSession) | `spark` | yes | yes, with Delta Lake |
| Databricks SQL warehouse | `databricks` | yes | yes |
| Oracle | `oracle` | yes | no |
| MySQL 8.0+ | `mysql-connector-python` | yes | no |
| SQL Server | `pyodbc` | yes | no |

PostgreSQL, MySQL, SQL Server and Oracle are checked behind DuckDB,
Databricks and Spark: a fault found only on one of them waits for a later
pass. What differs per backend: [backends](https://gitlab.com/briceg/prograph/-/blob/stable/1.3/docs/guides/backends.md),
[what differs by backend](https://gitlab.com/briceg/prograph/-/blob/stable/1.3/docs/reference/backend-differences.md).

## Cypher

Cypher queries run on every engine, with no option: `engine.execute(query, language="cypher")`.

- **Mapping.** Cypher needs a YAML mapping: an R2RML mapping has no property-graph
  view and raises `PropertyGraphViewError`; query it with SPARQL.
- **Ontology.** Cypher applies the ontology's class and property hierarchies only
  (subclass, sub-property, equivalent class and property). The first Cypher query on an
  engine whose ontology states other axioms (domain and range, inverses, symmetric and
  transitive properties, `owl:sameAs`, RL facts, individuals) warns once
  (`CypherOntologyWarning`); SPARQL applies them.
- **Writes.** `CREATE`, `SET`, `REMOVE`, `DELETE` and `MERGE` write into the owned store
  (`store=`), never a mapped table; with no store they raise `CypherWriteRefusedError`. A
  label a table maps, or an inferred superclass of one, or a label the ontology makes a
  subclass of another, is refused.
- **Nodes.** A node is the map `{id, labels, properties}`; its `id` is its IRI, and so are
  `id(n)` and `elementId(n)`. A node mapping's key columns are properties under their column
  names (`n.id`). A property no mapping declares is null.
- **Speed.** A Cypher plan runs as translated, without the rewrites SPARQL plans get. A
  pattern that a second `MATCH` joins back to nodes the first bound (`MATCH (a)-[:KNOWS]->(b)
  MATCH (a)-[:LIKES]->(p)<-[:LIKES]-(b)`) can take minutes on large tables: its joins run
  in the order written, over every type a relationship's table gives. On LDBC SF1, 3 of 200
  Cypher queries ran past 2 minutes on DuckDB; one of them, written in SPARQL, took half a
  second. Write such a query in SPARQL until this is fixed.
- **Checked.** The openCypher TCK gave 0 wrong answers across the scenarios run for 1.3.0:
  2,880 on DuckDB and on Spark; 2,658 on PostgreSQL, where 222 more are refused by name
  (values of several types in one column, lists of lists, paths held as values); 2,849 of the
  2,880 on a Databricks SQL warehouse, where the other 31 hold values it has no type for (TIME,
  TIME WITH TIME ZONE, nanoseconds). Of the TCK's 3,897 scenarios,
  314 are not built (refused by name) and the rest expect an error or a setup the test
  harness cannot load. MySQL, SQL Server and Oracle run Cypher unchecked.
- Natural-language `ask` writes SPARQL by default, or Cypher (`language="cypher"`); it never writes data.

See [Choosing a language](https://gitlab.com/briceg/prograph/-/blob/stable/1.3/docs/start/choosing-a-language.md) and the
[conformance choices](https://gitlab.com/briceg/prograph/-/blob/stable/1.3/docs/conformance/choices.md).

## Endpoint, MCP and ask

`prograph serve --config graph.yaml` serves the SPARQL 1.1 Protocol; with
`--mcp` it also serves MCP tools at `/mcp`, including `ask`, which turns a
question into SPARQL (or Cypher) with a model, runs it, and retries with the error if it
fails. See [the endpoint](https://gitlab.com/briceg/prograph/-/blob/stable/1.3/docs/guides/sparql-endpoint.md) and
[agents](https://gitlab.com/briceg/prograph/-/blob/stable/1.3/docs/guides/agents.md).

## More

- [Documentation](https://gitlab.com/briceg/prograph/-/blob/stable/1.3/docs/README.md), and the [primer](https://gitlab.com/briceg/prograph/-/blob/stable/1.3/docs/primer.md)
- [llms.txt](https://gitlab.com/briceg/prograph/-/blob/stable/1.3/llms.txt), a reference for LLMs and agents
- [Changelog](https://gitlab.com/briceg/prograph/-/blob/stable/1.3/docs/changelog.md)
- [Licence](https://gitlab.com/briceg/prograph/-/blob/stable/1.3/LICENSE): Apache-2.0
