Skip to main content

100% openCypher-compliant in-memory graph database — 4 backends, 31 algorithms, pure Rust

Project description

OCG — OpenCypher Graph

High-performance in-memory graph database with 100% OpenCypher compliance, 4 backends, and 31 algorithms — pure Rust.

PyPI Python License OpenCypher TCK Rust

Overview

OCG executes OpenCypher queries against in-memory property graphs. It is built in pure Rust and exposed to Python via PyO3 bindings.

  • 100% OpenCypher TCK: 3,897 / 3,897 scenarios passing (0 skipped, 0 failed)
  • 4 graph backends: PropertyGraph, NetworKitRust, RustworkxCore, Graphrs
  • 31 graph algorithms: centrality, community detection, pathfinding, spanning trees, flow, coloring, matching
  • Bulk Loader API: 57x faster batch construction vs OpenCypher CREATE statements
  • Serialization: save/load graphs to JSON with full metadata
  • Python 3.8–3.13, macOS · Linux · Windows

Installation

pip install ocg

Rust:

[dependencies]
ocg = "0.3.0"

Quick Start

Python

from ocg import Graph

graph = Graph()

# OpenCypher queries
graph.execute("CREATE (a:Person {name: 'Alice', age: 30})")
graph.execute("CREATE (b:Person {name: 'Bob', age: 25})")
graph.execute("MATCH (a:Person), (b:Person) WHERE a.name='Alice' AND b.name='Bob' CREATE (a)-[:KNOWS]->(b)")

result = graph.execute("MATCH (a:Person)-[:KNOWS]->(b:Person) RETURN a.name AS from, b.name AS to")
print(result)  # [{'from': 'Alice', 'to': 'Bob'}]

Bulk Loader (10–57x faster)

Bypasses the OpenCypher parser for large batch operations:

from ocg import Graph

graph = Graph()

node_ids = graph.bulk_create_nodes([
    (["Person"], {"name": "Alice", "age": 30}),
    (["Person"], {"name": "Bob",   "age": 25}),
])

graph.bulk_create_relationships([
    (node_ids[0], node_ids[1], "KNOWS", {"since": 2020}),
])

result = graph.execute("MATCH (a)-[:KNOWS]->(b) RETURN a.name, b.name")

Serialization

graph.save("my_graph.json")
loaded = Graph.load("my_graph.json")

Rust

use ocg::{PropertyGraph, execute};

let mut graph = PropertyGraph::new();
execute(&mut graph, "CREATE (a:Person {name: 'Alice'})").unwrap();
let result = execute(&mut graph, "MATCH (n:Person) RETURN n.name").unwrap();

Graph Backends

Backend Class Description
PropertyGraph Graph Native petgraph-based property graph
NetworKitRust NetworKitGraph Port of NetworKit algorithms to pure Rust
RustworkxCore RustworkxGraph IBM Qiskit rustworkx-core algorithms
Graphrs GraphrsGraph graphrs-based community detection

All four backends expose identical APIs: OpenCypher execution, bulk loader, 31 algorithms, and save/load.


Graph Algorithms (31)

All algorithms are available on all 4 backends.

Category Algorithms
Centrality degree, betweenness, closeness, pagerank
Pathfinding bfs, dijkstra, astar, bellman_ford, floyd_warshall, all_pairs
Spanning Trees minimum, maximum
DAG topological_sort, is_dag, find_cycles, dag_longest_path, dag_longest_path_weighted, transitive_closure
Flow max_flow, min_cut_capacity
Coloring node_coloring, edge_coloring, chromatic_number
Matching max_weight_matching, max_cardinality_matching
Community louvain, label_propagation, girvan_newman
Components connected_components, strongly_connected_components
from ocg import Graph

graph = Graph()
# ... populate graph ...

scores = graph.pagerank(damping=0.85, max_iter=100)
communities = graph.louvain()
path = graph.dijkstra(source_id, target_id)

Supported OpenCypher Features

Clauses

  • MATCH, OPTIONAL MATCH, variable-length paths [*1..3]
  • CREATE, MERGE, SET, DELETE, DETACH DELETE, REMOVE
  • WITH, UNWIND, RETURN, WHERE
  • ORDER BY, SKIP, LIMIT, DISTINCT
  • UNION, UNION ALL

Expressions

  • Property access, list indexing, string slicing
  • Arithmetic: +, -, *, /, %, ^
  • Comparison: =, <>, <, >, <=, >=
  • Logical: AND, OR, NOT, XOR
  • String: STARTS WITH, ENDS WITH, CONTAINS, =~
  • Null: IS NULL, IS NOT NULL
  • List: IN, comprehensions, quantifiers

Functions (60+)

  • String: substring, trim, toLower, toUpper, split, replace
  • Math: abs, ceil, floor, round, sqrt, sin, cos, log
  • List: size, head, tail, range, reverse, keys
  • Aggregation: count, sum, avg, min, max, collect
  • Temporal: date, datetime, localDatetime, duration
  • Predicates: exists, all, any, none, single

Procedures

  • db.labels(), db.relationshipTypes(), db.propertyKeys()
  • dbms.components()

TCK Compliance

3,897 / 3,897 scenarios passing — 100% (0 skipped, 0 failed)

Validated against the openCypher Technology Compatibility Kit.


Development

# Build
cargo build --release

# Unit tests
cargo test --no-default-features

# OpenCypher TCK
cargo test --test tck_property_graph --no-default-features

# Python wheel (requires maturin)
maturin develop --features python

Credits

Algorithm implementations (PageRank, Betweenness Centrality, Dijkstra, etc.) are based on published academic work. See NOTICE file for complete citations.


License

Apache-2.0 — see LICENSE and NOTICE files.

OpenCypher® and Cypher® are registered trademarks of Neo4j, Inc. This project implements the open OpenCypher specification and is not affiliated with Neo4j.


Contributing

Issues and proposals may be submitted via GitHub. Contributions are evaluated on a controlled schedule — pull requests are reviewed at the maintainer's discretion and timeline.

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

ocg-0.3.2.tar.gz (410.0 kB view details)

Uploaded Source

Built Distributions

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

ocg-0.3.2-cp314-cp314-macosx_11_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

ocg-0.3.2-cp314-cp314-macosx_10_12_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

ocg-0.3.2-cp311-cp311-musllinux_1_2_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

ocg-0.3.2-cp311-cp311-musllinux_1_2_aarch64.whl (2.3 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ ARM64

ocg-0.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

ocg-0.3.2-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ s390x

ocg-0.3.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

File details

Details for the file ocg-0.3.2.tar.gz.

File metadata

  • Download URL: ocg-0.3.2.tar.gz
  • Upload date:
  • Size: 410.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.12.1

File hashes

Hashes for ocg-0.3.2.tar.gz
Algorithm Hash digest
SHA256 6ecc7287e3ac08951acceedbeba500636652f54ea28afe5e3833884d0af0524a
MD5 e71f3b54ac217a15942aea7ca4e9a879
BLAKE2b-256 96db0bdaadcd255f29c6c7340fd05b9536b0e156c554661c43510a668bb1bfc8

See more details on using hashes here.

File details

Details for the file ocg-0.3.2-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ocg-0.3.2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aef115cf53298d8a5e21c641f0052bcb8e0bad5d10245e8b052ece6140d842b6
MD5 5f38d5872ed31122637501a11448ae05
BLAKE2b-256 d325f5356f73ed0af01c4abe8cf4ba728abb6dcfe903287f20ca07e7c01098dd

See more details on using hashes here.

File details

Details for the file ocg-0.3.2-cp314-cp314-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ocg-0.3.2-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a8f0272bc90b08892dce76f96b76d7b609d6024d1e2780d543b51fbfdcdad298
MD5 7347396ce75fdb84a945b591589c622a
BLAKE2b-256 a92b8ffd940aad30f29ac256f32eeb9e9160c197af4bbb3bb7b9f9c4631449d7

See more details on using hashes here.

File details

Details for the file ocg-0.3.2-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ocg-0.3.2-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 cbfc3fb666d9ae4c1f3d4d3c4dc66813b0e4dca2d8c92c2792324321a4a2f278
MD5 d639277f32c14839ac86a55a16b909c7
BLAKE2b-256 87f34a642154a58a1a942af4ae4c364762242edc73001314ee033dbaf9658188

See more details on using hashes here.

File details

Details for the file ocg-0.3.2-cp311-cp311-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for ocg-0.3.2-cp311-cp311-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f043366928d4a5af19cd09b63a01906842610231d3e91db7f9c165230416f12d
MD5 8c7c0cf9abfa6b0b42a46131f22fc380
BLAKE2b-256 0f79e2d3fa7cb38315564100d3f3169c0fb93cde9758c58529277f29f6a2f82c

See more details on using hashes here.

File details

Details for the file ocg-0.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ocg-0.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 460cc620cfbdc9435c3af7f5417e7d4ecc61843a09828af19dc8a9812f3e0325
MD5 b563566c4d2b2c3e052d3f5535354e59
BLAKE2b-256 7df06e10f14779373f22f4eebb08bc5304e1c7746a4d8700840f267cd9769640

See more details on using hashes here.

File details

Details for the file ocg-0.3.2-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for ocg-0.3.2-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 a03555c52f5c22363ceb2b0729f5d71a5e86eaf96a1381fbb8a0067026db61d2
MD5 bdf388b464d418a109b788e31c49e483
BLAKE2b-256 4126c1b10ea427187f79ff25a34a3f1320f1dda22a6801a03fb48c4bf4cd615e

See more details on using hashes here.

File details

Details for the file ocg-0.3.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ocg-0.3.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 29bb3eb95013eb06e502f720d7b2f115a858bc54c33492392e02a2af3eb155d4
MD5 474001ab8582045ef4f977db9005f3e4
BLAKE2b-256 8531e684557d3661c03f3815444d2ceef27393e0568d7c74e1d413c6a1dda2fc

See more details on using hashes here.

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