Skip to content
Shell

Get started

Ursa is a SQL engine for graph analytics, used through a command-line tool called ursa. It works like DuckDB: point it at Parquet, CSV or JSON files, on your disk or in object storage, and query them with SQL. Graph algorithms are part of that SQL. An edge table is a graph, and there is nothing to convert or load first.

The newest release is ursa-cli 0.15.0. The SQL may still change between minor versions; the changelog records every change.

Ursa Shell is the ursa shell in a web page. It runs the same engine, compiled to WebAssembly, in your browser. Pick an example from the Examples menu, or Upload a file of your own, which stays on your machine.

New to Ursa? Take the tour: four steps on Zachary’s karate club, from PageRank and Louvain to shortest paths.

On Linux or macOS:

curl -fsSL https://ursagraph.dev/install.sh | sh

On Windows, in PowerShell:

irm https://ursagraph.dev/install.ps1 | iex

The script downloads the newest ursa for your machine from the releases page, checks it against its SHA-256 checksum, and puts it in ~/.local/bin (on Windows, %LOCALAPPDATA%\ursa\bin, added to your user PATH). It needs no sudo. If ~/.local/bin is not on your PATH, it prints the line to add. To choose the directory, set URSA_INSTALL_DIR after the pipe (and URSA_VERSION, e.g. URSA_VERSION=0.13.0, for an older release):

curl -fsSL https://ursagraph.dev/install.sh | URSA_INSTALL_DIR=/opt/bin sh

Ursa is one binary, with no server and no dependencies. The prebuilt binaries cover Linux (x86_64 and aarch64, glibc 2.35 or later), macOS (Intel and Apple silicon) and Windows (x64), and you can also download them from the releases page yourself, each with a .sha256 file next to it. On anything else, install with Cargo. You need Rust 1.94 or later:

cargo install ursa-cli

Check it runs:

ursa --version

Nightly builds. The newest build of main, rebuilt on every merge, has features before they are released. They may still change or break.

curl -fsSL https://ursagraph.dev/install.sh | URSA_CHANNEL=nightly sh

On Windows, set $env:URSA_CHANNEL = 'nightly' before running the installer. To go back to stable, run the installer again without the nightly option. When you report a bug, include the output of ursa --version: it says which channel and commit you have.

This guide uses Zachary’s karate club: 34 members of a club, and 78 friendships between them. Download the two files:

curl -LO https://raw.githubusercontent.com/cldixon/ursa/main/python/ursa/datasets/data/karate_edges.csv
curl -LO https://raw.githubusercontent.com/cldixon/ursa/main/python/ursa/datasets/data/karate_nodes.csv

Any file is a table. Name it in FROM, in quotes:

ursa -c "SELECT * FROM 'karate_edges.csv' LIMIT 3"
┌───────┬───────┐
│ src │ dst │
│ Int64 │ Int64 │
├───────┼───────┤
│ 0 │ 1 │
│ 0 │ 2 │
│ 0 │ 3 │
└───────┴───────┘

The format comes from the extension: .parquet, .csv, .json (or .jsonl, .ndjson) and .arrow. Files and storage has the details.

Start the shell with a database file:

ursa club.ursa

The file is created if it does not exist. It keeps the views and graphs you define, and the graph indexes Ursa builds, so the next session starts where you left off. Without a file name, ursa runs in memory and forgets everything when it exits. The rest of this guide runs in that shell.

Name the files as views. A view reads its file each time it is queried, so nothing is copied into the database:

CREATE VIEW members AS SELECT * FROM 'karate_nodes.csv';
CREATE VIEW ties AS SELECT * FROM 'karate_edges.csv';

Then define the graph, with the CREATE PROPERTY GRAPH statement from the SQL standard (SQL/PGQ):

CREATE PROPERTY GRAPH karate
VERTEX TABLES (members KEY (id))
EDGE TABLES (
ties SOURCE KEY (src) REFERENCES members (id)
DESTINATION KEY (dst) REFERENCES members (id)
);

Every row of ties is an edge from src to dst. Every row of members is a node, keyed by id, with its other columns as attributes. The vertex table is optional: without it, the nodes are the endpoints of the edges. SQL and graphs covers the whole statement.

An algorithm is a table function. Its first argument is the graph. It returns one row per node: the node’s id, and a column named after the algorithm. Parameters are named, with =>:

SELECT id, round(pagerank, 4) AS pagerank
FROM pagerank(karate, direction => 'both')
ORDER BY pagerank DESC
LIMIT 5;
┌───────┬──────────┐
│ id │ pagerank │
│ Int64 │ Float64 │
├───────┼──────────┤
│ 33 │ 0.1009 │
│ 0 │ 0.097 │
│ 32 │ 0.0717 │
│ 2 │ 0.0571 │
│ 1 │ 0.0529 │
└───────┴──────────┘

The result is a table like any other. Join it to the graph’s node table, karate.nodes, on id for the members’ attributes:

SELECT id, club, round(pagerank, 4) AS pagerank
FROM pagerank(karate, direction => 'both') JOIN karate.nodes USING (id)
ORDER BY pagerank DESC
LIMIT 3;
┌───────┬─────────┬──────────┐
│ id │ club │ pagerank │
│ Int64 │ Utf8 │ Float64 │
├───────┼─────────┼──────────┤
│ 33 │ Officer │ 0.1009 │
│ 0 │ Mr. Hi │ 0.097 │
│ 32 │ Officer │ 0.0717 │
└───────┴─────────┴──────────┘

Ursa builds an index of the graph the first time a query needs it, and stores it in club.ursa. The next query, in this session or a later one, uses the stored index. If karate_edges.csv changes, Ursa notices and builds a new one. Algorithms covers direction, weights and running several algorithms at once.

The shell starts when there is no SQL to run. A statement ends with ; and may span lines. These run SQL and exit, as duckdb -c does:

ursa club.ursa -c "SELECT * FROM degree(karate)" # one or more statements
ursa club.ursa -f query.sql # a file of SQL
echo "SHOW GRAPHS;" | ursa club.ursa # SQL on stdin

If a statement fails, ursa prints the error, marking the part of the query to fix, and exits with status 1. --format chooses the output: table (the default), csv, json and more (see output formats).

A line that starts with . is a shell command, not SQL. The commands follow DuckDB’s shell where it has the same one:

Command Does
.help Lists the commands; .help graph is a page on the graph SQL
.tables, .graphs List the tables and views, and the graphs
.describe karate Describes a graph, table or view
.functions pagerank Shows a graph function’s parameters and output
.mode csv Sets the output format
.timer on Times each statement
.read FILE Runs the SQL and dot-commands in FILE
.quit Exits (also Ctrl-D)

ursa serve opens the Ursa Console in a browser tab, on this machine’s engine: a SQL editor, the catalog, result tabs and history. It listens on this machine only, with a one-time token in the link it opens. ursa serve club.ursa opens a database, and ursa serve data/ a directory.

For coding agents. ursa --skill prints a guide to writing Ursa SQL, built into the binary so it matches the version you run. Save it where your agent loads skills, for example ursa --skill > ~/.claude/skills/ursa-sql/SKILL.md, and have the agent read results as --format json or ndjson.

Looking for the Python library, ursa-graph? It is on hold: Ursa is developed as a SQL engine now. See its README.