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
result = db.execute_sql(query)                  # SQL/PGQ (SQL:2023)

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 (string or enum)
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_ms  # execution time (milliseconds)

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, GraphQL, and SQL/PGQ 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.41.tar.gz (2.3 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.41-cp312-abi3-win_amd64.whl (5.0 MB view details)

Uploaded CPython 3.12+Windows x86-64

grafeo-0.5.41-cp312-abi3-win32.whl (4.6 MB view details)

Uploaded CPython 3.12+Windows x86

grafeo-0.5.41-cp312-abi3-musllinux_1_2_x86_64.whl (5.4 MB view details)

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

grafeo-0.5.41-cp312-abi3-musllinux_1_2_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ ARM64

grafeo-0.5.41-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.2 MB view details)

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

grafeo-0.5.41-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ ARM64

grafeo-0.5.41-cp312-abi3-macosx_11_0_arm64.whl (4.7 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

grafeo-0.5.41-cp312-abi3-macosx_10_12_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.12+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: grafeo-0.5.41.tar.gz
  • Upload date:
  • Size: 2.3 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.41.tar.gz
Algorithm Hash digest
SHA256 5db5ddf67f7bf29da6a660431f0b397c444d7a4694f25c49440cc81f645f8ee1
MD5 c0abe58aabc8e180e9208b19e2972e05
BLAKE2b-256 5e04df723ff51a9eb046897a737dc688767271dd089b9b145a560d58b555d987

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafeo-0.5.41.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.41-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: grafeo-0.5.41-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 5.0 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.41-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e8585d5cf7382d09e3128af97b54732a6b67e859e34003db5079ffcfda670aec
MD5 ae1f3de780f29c514307cd748e737f63
BLAKE2b-256 de4136723c15c9eaf82d5919e76c026a0085546a5a83fc0f93b7c509cdfb3929

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafeo-0.5.41-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.41-cp312-abi3-win32.whl.

File metadata

  • Download URL: grafeo-0.5.41-cp312-abi3-win32.whl
  • Upload date:
  • Size: 4.6 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.41-cp312-abi3-win32.whl
Algorithm Hash digest
SHA256 48a96b7744576d4191664ed48d04c2a4b56c327b3849d214f8e7f3f3b1cddc5a
MD5 1c1e41913ed817c137c07e9021b93d7a
BLAKE2b-256 cf92710dc1d63c6f3748af8be78ab4f91a9b5675788a09088d2de4be76b9cfd9

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafeo-0.5.41-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.41-cp312-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for grafeo-0.5.41-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3a5a14c5a4e5c295b768d065d224082bd2b20617714405f0edbdcee9fbc93891
MD5 3cb54ecdf7614887cf31ab78275239b8
BLAKE2b-256 572df3cec9d70fb0634fa5aa5a623a58b51381b4843ee6735594aa0f8b85d61b

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafeo-0.5.41-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.41-cp312-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for grafeo-0.5.41-cp312-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 e0e33f49c7807187d9330e9bceac4a629d7fb5f03dc7162dea6855a156260451
MD5 80bd9087e1f1e958d25c3f78968e538e
BLAKE2b-256 12fe07db1b2a8b1e9f023071f811fa9f73841f05eb265d1b647164b00f640c2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafeo-0.5.41-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.41-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for grafeo-0.5.41-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8a96579c442b98066b045cddef7358405a0daacdd76d488456fd61eb81fdaf20
MD5 f848efc34e32dab9e00e495af4ae78e6
BLAKE2b-256 a0108a3ba80f10aba32628af6ac9527f6e958a2d156d87f2edc6daf64628016d

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafeo-0.5.41-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.41-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for grafeo-0.5.41-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c1eda200a629eb40ad5ae575a9cb4466308a817d0224d7d40c33816b6bc274b3
MD5 c40acb79ee95c49e617f70df609a9b7e
BLAKE2b-256 978fa773249d33a99e8dc3656e47f566dbc8dad37889fb8a2ad3669daa3e1217

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafeo-0.5.41-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.41-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for grafeo-0.5.41-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8cfce6de209076df341c5791e2cd7e5ea9932bd846093bee877b608b82cfd94b
MD5 3075a90c33cdb1f88c8465bdb70b5a72
BLAKE2b-256 88b635500c0b1ca34ec3b161297f76fe4a8065999174f3a044d87aa01607e918

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafeo-0.5.41-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.41-cp312-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for grafeo-0.5.41-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c929bac8049ae7d0d6125af320545df5a4e5479f027407f34ee8d07150fee3ce
MD5 b8b0195219b3848adbcb3195c03e9cda
BLAKE2b-256 709dbd2f6b5f2348adf60cebe1e8d7545edbc9559952bd3ce8cbdaa6a2802b74

See more details on using hashes here.

Provenance

The following attestation bundles were made for grafeo-0.5.41-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