Skip to main content

A high-performance, embeddable graph database with Python bindings

Project description

grafeo

Python bindings for Grafeo, a high-performance, embeddable graph database with a Rust core.

Installation

uv add grafeo
# or: pip install grafeo

Quick Start

from grafeo import GrafeoDB

# In-memory database
db = GrafeoDB()

# Or persistent
# db = GrafeoDB("./my-graph")

# Create nodes
db.execute("INSERT (:Person {name: 'Alix', age: 30})")
db.execute("INSERT (:Person {name: 'Gus', age: 25})")
db.execute("INSERT (:Person {name: 'Alix'})-[:KNOWS]->(:Person {name: 'Gus'})")

# Query the graph
result = db.execute("MATCH (p:Person) WHERE p.age > 20 RETURN p.name, p.age")
for row in result:
    print(row)

API Overview

Database

db = GrafeoDB()              # in-memory
db = GrafeoDB("./path")      # persistent
db = GrafeoDB.open("./path") # open existing

db.node_count   # number of nodes
db.edge_count   # number of edges

Query Languages

result = db.execute(gql)                        # GQL (ISO standard)
result = db.execute(gql, {"name": "Alix"})     # GQL with parameters
result = db.execute_cypher(query)               # Cypher
result = db.execute_sparql(query)               # SPARQL
result = db.execute_gremlin(query)              # Gremlin
result = db.execute_graphql(query)              # GraphQL

Node & Edge CRUD

node = db.create_node(["Person"], {"name": "Alix", "age": 30})
edge = db.create_edge(source_id, target_id, "KNOWS", {"since": 2024})

n = db.get_node(node_id)   # Node or None
e = db.get_edge(edge_id)   # Edge or None

db.set_node_property(node_id, "key", "value")
db.set_edge_property(edge_id, "key", "value")

db.delete_node(node_id)
db.delete_edge(edge_id)

Transactions

# Context manager (auto-rollback on exception)
with db.begin_transaction() as tx:
    tx.execute("INSERT (:Person {name: 'Harm'})")
    tx.commit()

# With isolation levels
from grafeo import IsolationLevel
with db.begin_transaction(IsolationLevel.SERIALIZABLE) as tx:
    tx.execute("MATCH (n:Person) SET n.verified = true")
    tx.commit()

# Per-transaction CDC override
with db.begin_transaction_with_cdc(True) as tx:
    tx.execute("INSERT (:AuditedEvent {action: 'login'})")
    tx.commit()

Named Graphs and Schemas

db.create_graph("social")
db.set_graph("social")
print(db.list_graphs())       # ['social']
print(db.current_graph())     # 'social'
db.reset_graph()
db.drop_graph("social")

db.set_schema("v1")
print(db.current_schema())    # 'v1'
db.reset_schema()

Graph Projections

db.create_projection("people", {
    "node_labels": ["Person"],
    "edge_types": ["KNOWS"]
})
print(db.list_projections())  # ['people']
db.drop_projection("people")

Data Import

count = db.import_csv("users.csv", "Person", headers=True)
count = db.import_jsonl("events.jsonl", "Event")

Backup and Restore

db.backup_full("/backups/full")
db.backup_incremental("/backups/incr")
GrafeoDB.restore_to_epoch("/backups/full", epoch=100, output_path="./restored")

QueryResult

result = db.execute("MATCH (n:Person) RETURN n.name, n.age")

result.columns          # column names
len(result)             # row count
result.execution_time   # execution time (seconds)

for row in result:      # iterate rows
    print(row)

result[0]               # access by index
result.scalar()         # first column of first row

Vector Search

# Create an HNSW index
db.create_vector_index("Document", "embedding", dimensions=384)

# Insert vectors
node = db.create_node(["Document"], {"embedding": [0.1, 0.2, ...]})

# Search
results = db.vector_search("Document", "embedding", query_vector, k=10)

Features

  • GQL, Cypher, SPARQL, Gremlin and GraphQL query languages
  • Full node/edge CRUD with native Python types
  • ACID transactions with configurable isolation levels
  • HNSW vector similarity search
  • Property indexes for fast lookups
  • Named graph and schema management
  • Graph projections (filtered virtual views)
  • CSV and JSON Lines import
  • Incremental backup and restore
  • Per-transaction CDC control
  • Async support via asyncio
  • Type stubs included

Links

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grafeo-0.5.36.tar.gz (2.0 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

grafeo-0.5.36-cp312-abi3-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.12+Windows x86-64

grafeo-0.5.36-cp312-abi3-win32.whl (4.2 MB view details)

Uploaded CPython 3.12+Windows x86

grafeo-0.5.36-cp312-abi3-musllinux_1_2_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ x86-64

grafeo-0.5.36-cp312-abi3-musllinux_1_2_aarch64.whl (4.7 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ ARM64

grafeo-0.5.36-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ x86-64

grafeo-0.5.36-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.6 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ ARM64

grafeo-0.5.36-cp312-abi3-macosx_11_0_arm64.whl (4.3 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

grafeo-0.5.36-cp312-abi3-macosx_10_12_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.12+macOS 10.12+ x86-64

File details

Details for the file grafeo-0.5.36.tar.gz.

File metadata

  • Download URL: grafeo-0.5.36.tar.gz
  • Upload date:
  • Size: 2.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for grafeo-0.5.36.tar.gz
Algorithm Hash digest
SHA256 428ca3c22d4155d1169ea47b270f6f69335093a65990fe819f375904a9aee5ed
MD5 762ff0e0edd06ea6468abf7679e05469
BLAKE2b-256 5c417dbd3d5966775f327fd84d3efb035864374853ec1df28c8b3b673cda18bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafeo-0.5.36.tar.gz:

Publisher: pypi.yml on GrafeoDB/grafeo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file grafeo-0.5.36-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: grafeo-0.5.36-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 4.6 MB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for grafeo-0.5.36-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7b005ddefa601e338dfd0bff0fc50eb5eb19fcb6dbad21077da041f5126b3919
MD5 e2c7d66c7dad473cffc576c8595944bd
BLAKE2b-256 8dc5bfa80bd281be9ada7bff9424dae664357ef49464c124f56e771ece17811a

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafeo-0.5.36-cp312-abi3-win_amd64.whl:

Publisher: pypi.yml on GrafeoDB/grafeo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file grafeo-0.5.36-cp312-abi3-win32.whl.

File metadata

  • Download URL: grafeo-0.5.36-cp312-abi3-win32.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: CPython 3.12+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for grafeo-0.5.36-cp312-abi3-win32.whl
Algorithm Hash digest
SHA256 f12b0f442dfa0deb40bb90013413310141979898748a9798cb5dfe960c81e0dd
MD5 a73317e89247aff38a14a10a3ade0186
BLAKE2b-256 8f4cefc1a5c714294bfe7b346f312e62af15d1b15e846ea7357ffaa02e348bd0

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafeo-0.5.36-cp312-abi3-win32.whl:

Publisher: pypi.yml on GrafeoDB/grafeo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file grafeo-0.5.36-cp312-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for grafeo-0.5.36-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4dccf55a4ebc4eb2b490102e19ce32de94a4ef3ee46375cd04c94018de3d85bc
MD5 8509b3d09e09b864e90ca7a28be643a9
BLAKE2b-256 0fea91d41c5c889b5abf490519138efb513562333853db4aa4163ddfcccb15d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafeo-0.5.36-cp312-abi3-musllinux_1_2_x86_64.whl:

Publisher: pypi.yml on GrafeoDB/grafeo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file grafeo-0.5.36-cp312-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for grafeo-0.5.36-cp312-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 cc4401fc2863ae3f7c7a9dfaf55664763a0c7e87102d2271e549ce3216c4d6cf
MD5 5f72e0b67f1326735386c913d7d660ca
BLAKE2b-256 012eaac3275cd5fcbb32cd59969f5a217956a36810d2be2ef1297d1488b0b368

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafeo-0.5.36-cp312-abi3-musllinux_1_2_aarch64.whl:

Publisher: pypi.yml on GrafeoDB/grafeo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file grafeo-0.5.36-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for grafeo-0.5.36-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 879587ea78ef8a872c190c5f4a1e96b8a3cdf310604d88de9561d15677006e43
MD5 1daa69baade9aaf3c5cbed3a8b6ae6e5
BLAKE2b-256 e280dc373662b7f9827193bae313447fdd27784643295f8c6310067a2769dca0

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafeo-0.5.36-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: pypi.yml on GrafeoDB/grafeo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file grafeo-0.5.36-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for grafeo-0.5.36-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 173921c0b58a7834517d72818e48389cf581c8ca25eadb3adcc47f57c5376474
MD5 0a6fe2610b9126e87aadcd111c2e0466
BLAKE2b-256 25053d768e552c47d24694939275b712e73005cb792fa75aad796e04762fdf56

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafeo-0.5.36-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: pypi.yml on GrafeoDB/grafeo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file grafeo-0.5.36-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for grafeo-0.5.36-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fe6530e7e9ce838cf86bbd5f56acd4731f42a078031f2f5e006dd05427aa1b2d
MD5 fba31578028ea7b6f04f286f5087586f
BLAKE2b-256 b6d11618f0c4c30d0ea347382450751ea380a95177b5b86e21d10d6cac4008a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafeo-0.5.36-cp312-abi3-macosx_11_0_arm64.whl:

Publisher: pypi.yml on GrafeoDB/grafeo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file grafeo-0.5.36-cp312-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for grafeo-0.5.36-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6c4d1fc854cbaaaa415d8846e0add46f20d5edab430eeaa807054a9ac2d8fc4c
MD5 63c0c63434799ad73166208354e4d70d
BLAKE2b-256 343cb043c8b0be24a9e9546051c48086b577e494a3f81a0431867231c999cb67

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafeo-0.5.36-cp312-abi3-macosx_10_12_x86_64.whl:

Publisher: pypi.yml on GrafeoDB/grafeo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page