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.37.tar.gz (2.1 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.37-cp312-abi3-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.12+Windows x86-64

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

Uploaded CPython 3.12+Windows x86

grafeo-0.5.37-cp312-abi3-musllinux_1_2_x86_64.whl (5.1 MB view details)

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

grafeo-0.5.37-cp312-abi3-musllinux_1_2_aarch64.whl (4.8 MB view details)

Uploaded CPython 3.12+musllinux: musl 1.2+ ARM64

grafeo-0.5.37-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.37-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.37-cp312-abi3-macosx_11_0_arm64.whl (4.4 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

grafeo-0.5.37-cp312-abi3-macosx_10_12_x86_64.whl (4.7 MB view details)

Uploaded CPython 3.12+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: grafeo-0.5.37.tar.gz
  • Upload date:
  • Size: 2.1 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.37.tar.gz
Algorithm Hash digest
SHA256 563c57b0d902cf7629e378fb3448873c88aa4d4a341c74fa7122a8df4ffbd9a3
MD5 40c92ca33cf62b0ad2101f57564b3d01
BLAKE2b-256 af826f9111454a493f673af10cb21f3b3cf8406b35620349ca5ad24dbe81f206

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: grafeo-0.5.37-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.37-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c66a71dc75878f56971158b6b9ee52b15b6388c2724b76da4ea94430fcf2ffd5
MD5 4de3e6ba875ebdab0de12c84ed214900
BLAKE2b-256 8fb4274fe9cfebd6220e47fdc10ee5acd65e2bf9de8d0141b3b76d3f4f49d78e

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: grafeo-0.5.37-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.37-cp312-abi3-win32.whl
Algorithm Hash digest
SHA256 5ab4b8220d805da9233e66c4e60f7964f821622b204fc76c2d76b518b7e6d0d3
MD5 4f4a3d1b4caaf46d4cda82f6d19765aa
BLAKE2b-256 8cdae0f3778920f66130884f70b007cd7a87297cb24c178b5df5c6f5e9c3e37f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for grafeo-0.5.37-cp312-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 91f3ebd5c4be39cdb495ce81ef35dbed93e05851d61360d07d1882af68d5dbed
MD5 948fb2cbd175fcb5e02f5f0e04ecfa38
BLAKE2b-256 d6d355c3ef3c0df8eca1f3fb32a37006205a0942bcc42a11e1926c4aa4c77e13

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for grafeo-0.5.37-cp312-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 2d467c802ef409bcb74e41b7f4617bfb64e005af1d211b961bbee554cee71385
MD5 63f174459b52d020e98d2c1fac7d48ec
BLAKE2b-256 18a4bb0121ac474e2dd3ef81631627b95883df587df889f9a34e46c2f26585e1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for grafeo-0.5.37-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2c2cda8f0a72c3e8bf232669a0270cf6c9e890f06366e7706f1a0291aa87d585
MD5 e134f393d16527e03506bc55bab10935
BLAKE2b-256 8cfbb2503f5f96a322c819f5500531628011ba98bea5cc3fa7a07ab49054220e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for grafeo-0.5.37-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4a7603d4dcc3412e4ea78341fdbdc57515faf10b7357f8f65dbd7388982e89d7
MD5 f3ab984260bf089cbb38319f61fae79f
BLAKE2b-256 e58a584a12d5158cf88c989137d5d15f6663b2d2602a55abc700f9b0f91e80c7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for grafeo-0.5.37-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3f7a659e5f242f11d3c1f921b8f82c1e2ef210916ba2af8027d494c133b2cb4a
MD5 ec54da4c7b9c398cfbaf224db97b6b46
BLAKE2b-256 d5cb95add20121db57085a22f61b2594c513f0ee0fe62272611697dec958720f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for grafeo-0.5.37-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d4c23da954068e9e3b099af9dbd1bcd5e07cb7b2285c026acd710b7c0f03bbc2
MD5 fc2f053dc871ce797932ff2a18411796
BLAKE2b-256 3d4c442d0ce78b6e95076e0ff946dadd2c5fbc2d2295f62919ea7bafa9267a43

See more details on using hashes here.

Provenance

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