Graph analytics in SQL, in a single binary.
Ursa is a SQL engine for graphs, in the spirit of DuckDB. Point the ursa command-line tool at an edge list in Parquet, CSV or JSON. Name the edge list as a graph, then run PageRank, Louvain, shortest paths and SQL/PGQ pattern matching as ordinary SQL. There is no server and no load step.
Website · Docs · Try it in your browser · Releases
On Linux or macOS:
curl -fsSL https://ursagraph.dev/install.sh | shOn Windows, in PowerShell:
irm https://ursagraph.dev/install.ps1 | iexOr build it with Cargo (cargo install ursa-cli), or download a binary from the releases page. The installers verify each download's SHA-256 checksum. They can also pin a version (URSA_VERSION), choose the install directory (URSA_INSTALL_DIR), or install the nightly build of main. See Installation for details.
This example uses Zachary's karate club: 34 members and the 78 friendships between them. Download the edge list and start the shell with a database file:
curl -LO https://raw.githubusercontent.com/cldixon/ursa/main/python/ursa/datasets/data/karate_edges.csv
ursa club.ursaThe edge list is a plain table. Name it as a graph:
CREATE VIEW ties AS SELECT * FROM 'karate_edges.csv';
CREATE PROPERTY GRAPH club
EDGE TABLES (ties SOURCE KEY (src) DESTINATION KEY (dst));Algorithms are table functions. algorithms runs several of them over one graph in a single pass:
SELECT id, degree, round(pagerank, 4) AS pagerank, community
FROM algorithms(club,
degree(direction => 'both'),
pagerank(direction => 'both'),
community => louvain(seed => 1))
ORDER BY pagerank DESC
LIMIT 5;┌───────┬────────┬──────────┬───────────┐
│ id │ degree │ pagerank │ community │
│ Int64 │ UInt32 │ Float64 │ UInt32 │
├───────┼────────┼──────────┼───────────┤
│ 33 │ 17 │ 0.1009 │ 2 │
│ 0 │ 16 │ 0.097 │ 0 │
│ 32 │ 12 │ 0.0717 │ 2 │
│ 2 │ 10 │ 0.0571 │ 0 │
│ 1 │ 9 │ 0.0529 │ 0 │
└───────┴────────┴──────────┴───────────┘
Patterns use SQL/PGQ's GRAPH_TABLE. This query finds the shortest chain of friends from member 16 to member 33:
SELECT * FROM GRAPH_TABLE (club
MATCH p = ANY SHORTEST (a)-[e]-{1,4}(b)
WHERE a.id = 16 AND b.id = 33
COLUMNS (path_length(p) AS hops, vertices(p) AS path));┌───────┬──────────────────────┐
│ hops │ path │
│ Int64 │ List(non-null Int64) │
├───────┼──────────────────────┤
│ 4 │ [16, 5, 0, 8, 33] │
└───────┴──────────────────────┘
club.ursa stores the view, the graph and the graph index Ursa built, so the next session starts where this one left off. Run the algorithms query in your browser in Ursa Shell, with nothing to install. The Quickstart continues from here.
- Files are tables. Ursa reads Parquet, CSV, JSON/NDJSON and Arrow where they are: on disk, behind globs, or at
s3://,gs://,az://andhttps://URLs. It also has DuckDB'sread_parquet,read_csvandread_json.COPY … TOwrites results back out. - A graph is an edge table. SQL/PGQ's
CREATE PROPERTY GRAPHnames an edge table and its endpoints. Vertex tables, labels and several tables per graph are optional. - The standard algorithms. PageRank, degree, connected components, triangles and clustering, closeness and betweenness, Louvain and label propagation, neighbour aggregation, hops, random walks, shortest paths and force-directed layouts. Each is a table function with named parameters that you can join to anything on
id.SELECT * FROM ursa_functions()lists them all. - Pattern matching.
GRAPH_TABLEmatches nodes, edges and paths of any length, withANY SHORTEST,SHORTEST kand the path modes. DuckPGQ graph definitions and queries run as written. - Feels like DuckDB. One binary, a shell with dot-commands, and
ursa -candursa -ffor scripts.--format jsonproduces output for programs. A.ursadatabase file keeps your views, graphs and the indexes Ursa builds. - In a browser. Ursa Shell runs the same engine, compiled to WebAssembly, in a web page.
ursa serveopens the shell in a browser tab on your own machine, with the graph view beside it. - Results you can check. The kernels are parallel and deterministic on any thread count. Each one is pinned to the NetworkX function it matches.
- For coding agents.
ursa --skillprints a guide to writing Ursa SQL, built into the binary.
- Installation and the Quickstart
- Algorithms, traversals and pattern matching
- Differences from DuckDB, and coming from SQL/PGQ or DuckPGQ
- The function reference
Ursa is pre-1.0. The newest release is ursa-cli 0.15.0. The SQL surface may still change between minor versions. The changelog records every change.
The Python library is on hold. Ursa started as a Python package, ursa-graph, with a Polars-shaped API over the same engine. It still builds and its tests still run, but it gets no new features and may not be maintained. See python/README.md.
Ursa is written in Rust and built on Apache DataFusion and Apache Arrow.
| Crate | Role |
|---|---|
ursa-cli |
The ursa command-line tool, its shell, and ursa serve. |
ursa-sql |
Ursa's SQL statements (CREATE PROPERTY GRAPH, GRAPH_TABLE, ATTACH, …) on top of DataFusion's parser. |
ursa-engine |
The SQL engine: a DataFusion session with graph plan nodes, the graph catalog, the index cache and the .ursa database file. |
ursa-core |
The CSR graph index and the kernels. Parallel with rayon; compiles for wasm32 without it. |
ursa-io |
Reading Parquet, CSV and JSON, locally or from object storage. |
ursa-shell, ursa-server, ursa-viz |
The shell session shared by the CLI and the browser, ursa serve's server, and the graph view. |
ursa-wasm, web/ |
The engine compiled to WebAssembly, and Ursa Shell. |
ursa-plan, ursa-py, python/ |
The Python library (on hold). |
The design document is design/SPEC.md.
cargo build --release -p ursa-cli # target/release/ursa
cargo test --workspace # the Rust suites
cargo test -p ursa-cli --test docs # every SQL example in the docs runs as shownThe website and docs are in site/ (Astro and Starlight; see site/README.md). The web shell is in web/, and the benchmark harness is in benchmarks/.
MIT OR Apache-2.0.