Skip to main content

graphnight

Python bindings for GraphNight — an embeddable semantic layer for AI agents and humans.

Status: 1.0.0. Rust-backed local YAML client (GraphNightClient). Server features (OIDC, HA metadata, Docker) live in the main repo binaries.

Install

From PyPI (wheels):

pip install graphnight==1.0.0

From a source checkout (develop / contribute):

cd crates/graphnight-python
python3.11 -m venv .venv && source .venv/bin/activate
pip install maturin pytest
# Reuse an existing Cargo target to save disk:
#   export CARGO_TARGET_DIR=../../target
maturin develop
pip install -e '.[dev]'   # optional: pytest, ruff, mypy

Quick start

from graphnight import GraphNightClient

client = GraphNightClient(storage_path="./graphnight_data")

# Datasource + model
client.create_datasource({
    "name": "demo",
    "driver": "postgres",
    "connection_string": "postgresql://localhost/demo",
})
client.create_model({
    "name": "orders",
    "datasource": "demo",
    "description": "Order facts",
    "measures": [
        {"formula": {"expression": "amount_usd", "label": "Revenue"}, "aggregation": "sum"},
        {"formula": "*", "aggregation": "count"},
    ],
    "dimensions": ["status", {"name": "customer_id", "label": "Customer"}],
    "time_dimensions": [{"dimension": "created_at", "granularity": "day"}],
})

print(client.list_models())
print(client.list_datasources())
print(client.get_model("orders"))

Scaffold data with the CLI instead:

cargo install --path crates/graphnight-cli
graphnight init ./my-project

Query helpers

All client methods are synchronous (they drive an internal Tokio runtime).

query = {
    "name": "orders",
    "measures": [
        {"formula": {"expression": "amount_usd"}, "aggregation": "sum"},
    ],
    "dimensions": [{"name": "status"}],
    "filters": [{"field": "status", "operator": "eq", "value": "completed"}],
    "limit": 100,
}

# SQL only — no database connection needed
sql = client.generate_sql(query)
dry = client.dry_run_query(query)  # {"sql": "...", "name": "orders"}

# Execute against the datasource connection_string (needs a live DB)
# result = client.query(query)  # {"data", "columns", "sql", "execution_time_ms"}

API surface

Method Purpose
GraphNightClient(url=None, storage_path=None) Local YAML client (url reserved / ignored)
list_models(datasource=None) List model summaries
get_model(name, datasource=None) Fetch one model or None
create_model(dict) Persist a model
list_datasources() List datasources
create_datasource(dict) Persist a datasource
generate_sql(query) Return SQL string
dry_run_query(query) Return {"sql", "name?"} without executing
query(query) / query_df(query) Execute SQL via sqlx (DataFrame TBD)
search(q, limit=None) Search models
save_memory(...) / list_memories(...) / forget_memory(id) Agent learnings

Formula fields accept a string ("amount_usd") or a dict {"expression", "label?", "format?"}. Dimensions accept a string or {"name", "label?"}.

Tests

cd crates/graphnight-python
maturin develop
pytest

Tests use tempfile storage and do not need a warehouse. See also examples/python/ for runnable scripts.

CI note

Main CI excludes this crate (cargo test --workspace --exclude graphnight-python) because PyO3 needs a Python interpreter and maturin. Run the commands above locally or in a dedicated job when changing bindings. Multi-platform wheels are built by .github/workflows/wheels.yml.

License

Apache-2.0

Release files for graphnight 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for graphnight 1.0.1
File Size Uploaded
graphnight-1.0.1.tar.gz 85.2 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for graphnight 1.0.1
File
graphnight-1.0.1-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details
graphnight-1.0.1-cp38-abi3-musllinux_1_2_x86_64.whl CPython 3.8 abi3 Linux musl 1.2+ x86-64 Details
graphnight-1.0.1-cp38-abi3-musllinux_1_2_aarch64.whl CPython 3.8 abi3 Linux musl 1.2+ ARM64 Details
graphnight-1.0.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 abi3 Linux glibc 2.17+ x86-64 Details
graphnight-1.0.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.8 abi3 Linux glibc 2.17+ ARM64 Details
graphnight-1.0.1-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details
graphnight-1.0.1-cp38-abi3-macosx_10_12_x86_64.whl CPython 3.8 abi3 macOS 10.12+ x86-64 Details

Total release size: 20.0 MB

Release files / graphnight-1.0.1.tar.gz

Download URL graphnight-1.0.1.tar.gz
Size 85.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b79a26f3928bd75953a7bfba5811f0f3ca2e81d017c48235839637f481ae0654
BLAKE2b-256 checksum
How to use checksums
ff073e5823c936ce7494232bf0eb60521f7555e110d00848608eed9121355d3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / graphnight-1.0.1-cp38-abi3-win_amd64.whl

Download URL graphnight-1.0.1-cp38-abi3-win_amd64.whl
Size 2.7 MB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
192dd36fa7b862a5d6f344342dd55e1260d02cc9abcb3a11c2434062f1ce709f
BLAKE2b-256 checksum
How to use checksums
d772eca2d0841ff7b7a25cbbbc3e53e25e00c1517d6723b3fac4f83e562ad4ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / graphnight-1.0.1-cp38-abi3-musllinux_1_2_x86_64.whl

Download URL graphnight-1.0.1-cp38-abi3-musllinux_1_2_x86_64.whl
Size 3.2 MB
Tags CPython 3.8 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
11f83bcc3e822c46751f90b5648da0296ac4f612b8f00d74d9cb07d34afea98a
BLAKE2b-256 checksum
How to use checksums
d84c7b09ee1e16b25dcdf41abd231d77c6840e5537fb699d842e9a462f8eba20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / graphnight-1.0.1-cp38-abi3-musllinux_1_2_aarch64.whl

Download URL graphnight-1.0.1-cp38-abi3-musllinux_1_2_aarch64.whl
Size 3.0 MB
Tags CPython 3.8 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
bef30d57755214c8f95adc3c6c816eb102b3ec74e4dcf4ffa0e156480f8987c6
BLAKE2b-256 checksum
How to use checksums
7303bf9a362a84310e0f23b022f538abf2436076ec11d517cd76a5dde9a6d55c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / graphnight-1.0.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL graphnight-1.0.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.9 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
55ac356973414b3a72310abf53a41ffb272762197a66dc4f733cf01a177120bb
BLAKE2b-256 checksum
How to use checksums
fb95feb55c16d73b71d44f02e649d99402b83b11324a712d843a3cdf9b124d66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / graphnight-1.0.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL graphnight-1.0.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 2.7 MB
Tags CPython 3.8 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
bdb2f61ed249243b571880c6b6d80618ddd0bb86822105c9bf7de6d49d23a2cb
BLAKE2b-256 checksum
How to use checksums
144dffc8fefcc26733cb8e787ebd624e3acaa2c48d6a1830072dc9d1ecc5e92b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / graphnight-1.0.1-cp38-abi3-macosx_11_0_arm64.whl

Download URL graphnight-1.0.1-cp38-abi3-macosx_11_0_arm64.whl
Size 2.6 MB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9958f9ec6957952ffd3eb65d070f96fa453f74f858c74600cb1b19a2f2182aac
BLAKE2b-256 checksum
How to use checksums
07da4069e7508df0c392de35f22a0bd266a974ecf4938cbcffec666764484c9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / graphnight-1.0.1-cp38-abi3-macosx_10_12_x86_64.whl

Download URL graphnight-1.0.1-cp38-abi3-macosx_10_12_x86_64.whl
Size 2.8 MB
Tags CPython 3.8 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
dcad9abca85687a015c911d9e52f83192294be191a2b26de37ea0ad43234bf1a
BLAKE2b-256 checksum
How to use checksums
bcc656fe15f7f5dfab58163f7d6f0d06be1fda65d499a2eec3df25a83cb65287
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release history Release notifications | RSS feed

This release

1.0.1 This release

8 release files

1.0.0

8 release files

0.4.0

8 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page