GraphSense Library

A comprehensive Python library for the GraphSense crypto-analytics platform. It provides database access, data ingestion, maintenance tools, and analysis capabilities for cryptocurrency transactions and networks.
Note: This library uses optional dependencies. Use graphsense-lib[all] to install all features.
Quick Start
Installation
# Install with all features
uv add graphsense-lib[all]
# Install from source
git clone https://github.com/graphsense/graphsense-lib.git
cd graphsense-lib
make install
Serving the REST API locally
The web API requires two backend connections: a Cassandra cluster (blockchain data) and a TagStore (PostgreSQL). You can configure them via environment variables or a YAML config file.
Option A: Environment variables only
GS_CASSANDRA_ASYNC_NODES='["<cassandra-host>"]' \
GRAPHSENSE_TAGSTORE_READ_URL='postgresql+asyncpg://<user>:<password>@<host>:<port>/tagstore' \
GS_CASSANDRA_ASYNC_CURRENCIES='{"btc":{"raw": "btc_raw", "transformed": "btc_transformed"},"eth":{}}' \
uv run --extra web uvicorn graphsenselib.web.app:create_app --factory --host localhost --port 9000 --reload
Option B: YAML config file
Point CONFIG_FILE to a REST-specific config (see instance/config.yaml for a full example):
CONFIG_FILE=./instance/config.yaml make serve-web
Or without Make:
CONFIG_FILE=./instance/config.yaml \
uv run --extra web uvicorn graphsenselib.web.app:create_app --factory --host localhost --port 9000 --reload
Option C: .graphsense.yaml with a web key
If you already have a .graphsense.yaml (or ~/.graphsense.yaml) for the CLI, you can add a web key containing the REST config. The app will pick it up automatically without setting CONFIG_FILE:
# .graphsense.yaml
environments:
# ... your existing CLI config ...
web:
database:
nodes: ["<cassandra-host>"]
currencies:
btc:
eth:
gs-tagstore:
url: "postgresql+asyncpg://<user>:<password>@<host>:<port>/tagstore"
make serve-web
Config resolution order: explicit config_file param > CONFIG_FILE env var > ./instance/config.yaml > .graphsense.yaml web key > env vars only.
Environment variable substitution in YAML
Any string value in a config file may reference environment variables with ${VAR}. This works in both the CLI config (.graphsense.yaml) and the REST config, and applies to nested values (lists, maps) too. Useful for keeping secrets out of the file:
gs-tagstore:
url: ${TAGSTORE_URL}
database:
nodes:
- ${CASSANDRA_HOST}
- Defaults:
${VAR:-fallback} uses fallback when VAR is unset or empty. Use ${VAR:-} to allow an empty value.
- Errors: a
${VAR} referencing an unset variable with no default fails loudly at load time.
- Escaping: write
$${VAR} to emit a literal ${VAR} without substitution. A bare $VAR (no braces) is never substituted.
Optional REST settings (env vars)
| Variable | Default | Description |
|---|
GSREST_DISABLE_AUTH | false | Disable API key authentication |
GSREST_ENSURE_TAGSTORE_SCHEMA_ON_STARTUP | false | Auto-initialize TagStore tables/views at startup when missing |
GRAPHSENSE_TAGSTORE_READ_URL | — | TagStore database URL (e.g., postgresql://user:password@host:5432/tagstore) |
GSREST_ALLOWED_ORIGINS | * | CORS allowed origins |
GSREST_LOGGING_LEVEL | — | Logging level (DEBUG, INFO, …) |
GS_CASSANDRA_ASYNC_PORT | 9042 | Cassandra port |
GS_CASSANDRA_ASYNC_USERNAME | — | Cassandra username |
GS_CASSANDRA_ASYNC_PASSWORD | — | Cassandra password |