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.42.tar.gz (2.5 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.42-cp312-abi3-win_amd64.whl (5.1 MB view details)

Uploaded CPython 3.12+Windows x86-64

grafeo-0.5.42-cp312-abi3-win32.whl (4.7 MB view details)

Uploaded CPython 3.12+Windows x86

grafeo-0.5.42-cp312-abi3-musllinux_1_2_x86_64.whl (5.6 MB view details)

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

grafeo-0.5.42-cp312-abi3-musllinux_1_2_aarch64.whl (5.2 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ ARM64

grafeo-0.5.42-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.3 MB view details)

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

grafeo-0.5.42-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ ARM64

grafeo-0.5.42-cp312-abi3-macosx_11_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

grafeo-0.5.42-cp312-abi3-macosx_10_12_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.12+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: grafeo-0.5.42.tar.gz
  • Upload date:
  • Size: 2.5 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.42.tar.gz
Algorithm Hash digest
SHA256 f2af6bc4d243437744c84c01d1f0c99880098fd11b18205deaf2c774f987d443
MD5 03d37dcdbd0c8ea2efa958d3fc5cb071
BLAKE2b-256 ecd929bdc76d59285ba036cbce359e7c0407913155a24dcdad3455a8450a2bed

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: grafeo-0.5.42-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 5.1 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.42-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f219b86c01a0e7bd7d5c287bef7f12656a9885b79f57048a79743e73ab87a0af
MD5 47d417fb5c4041a39945f98f587eb570
BLAKE2b-256 f62fdcbf471d8f18d678d5775bd3c876dfa42afb6b00251aa89c61d915b7d8be

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: grafeo-0.5.42-cp312-abi3-win32.whl
  • Upload date:
  • Size: 4.7 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.42-cp312-abi3-win32.whl
Algorithm Hash digest
SHA256 fc28e539c70e393964212f92922686c333df08dfe2ddd6a26866aa1175a00994
MD5 d36e3b9ec008922c0314a58fc3cc8b97
BLAKE2b-256 c2d69ae14d674d2756160cc3bea180e7b095b8923341795f0b3659d168f708b0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for grafeo-0.5.42-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7fc3270307a475b7977045228ddb5660b4221d4a036461bafb08f0391f159a51
MD5 7ec8145a97e23180809eec4ab817d6fc
BLAKE2b-256 90237d7f7f7eb50a73177d9b43dad006eac5494d7f17bab494e0dd1e68507023

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for grafeo-0.5.42-cp312-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 16d15725ea6b1d69c045bc73d8ec130e3329259d7f93184df6818296e8ecfa7b
MD5 47992ec44a146ad1878f5c3d13d436f7
BLAKE2b-256 a518bb6d104f38583e4769833d8169d7d1e3a4b2962580c747efb90fa0250414

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for grafeo-0.5.42-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 376b39ae8c57f63f173ea328b24a43f1c843bc7a8159728b140cb3bf4a6c391c
MD5 4df6ce3797c54156d54bad049857dc05
BLAKE2b-256 2e73f64ec3acaa3b08b57c7ec1ad340ae821ff70b8b248fe32430c32ea9710b3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for grafeo-0.5.42-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 dcbf75da90bd93cbda0cbc4d0325e51f80b66fdf3bad0501830981f7bb61b036
MD5 9b2a7007e6c4cfc7e4c1d97e879aab39
BLAKE2b-256 639ab27f0345fa4329f9e8412bd852df93f16216b9db788df711b13f4e2c5ce3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for grafeo-0.5.42-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 24883ce0ab202f7f079ab145e62404f242ab44cd1b406195ce5b6873a7f3f3a7
MD5 494ba771652a4582c2a45a52133fd3e1
BLAKE2b-256 cc473fdd36f97a8b83cbeebe4923eb5a5dfef394cdd439bbf34e73ad56f2beb3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for grafeo-0.5.42-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 98fc9724e0e49291afd923a5ccd5fd099bc718c9896f4fbd5d1b3338f27dc922
MD5 63463db979eec61bea4a2a1627ba0d7b
BLAKE2b-256 21b02a6a8f128165e826a06c687d4b6e41eb556dee459e02483646682bce3d89

See more details on using hashes here.

Provenance

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