Skip to main content

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

Project description

OCG — OpenCypher Graph

High-performance in-memory graph database with 100% OpenCypher compliance, 4 backends, and 175+ 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
  • 175+ graph algorithms: centrality, community, pathfinding, spanning trees, flow, coloring, matching, cliques, layout, generators
  • Bulk Loader API: 57x faster batch construction vs OpenCypher CREATE statements
  • Serialization: save/load graphs to JSON with full metadata
  • Python 3.11–3.14, macOS · Linux (glibc + musl) · Windows

Installation

pip install ocg

Rust:

[dependencies]
ocg = "0.4.1"

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, 175+ algorithms, and save/load.


Graph Algorithms (175+)

All algorithms are available on all 4 backends.

Category Algorithms
Centrality degree, betweenness, closeness, pagerank, eigenvector, katz, harmonic, voterank
Pathfinding bfs, dijkstra, astar, bellman_ford, floyd_warshall, all_pairs, all_simple_paths, all_pairs_all_simple_paths
Shortest Paths single_source, multi_source, k_shortest, average_shortest_path_length
Spanning Trees minimum, maximum, steiner_tree
DAG topological_sort, is_dag, find_cycles, dag_longest_path, transitive_closure, transitive_reduction, dag_to_tree
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, number_weakly_connected, is_connected, is_tree, is_forest
Cliques find_cliques, max_clique, clique_number, node_clique_number, cliques_containing_node
Traversal dfs, bfs_layers, descendants, ancestors
Transitivity triangles, transitivity, clustering, average_clustering, square_clustering
Graph Ops complement, line_graph, cartesian_product, tensor_product, strong_product, lexicographic_product, graph_power
Euler is_eulerian, eulerian_circuit, semieulerian
Planar is_planar
Contraction contract_nodes, quotient_graph
Token Swapper token_swapper
Generators erdos_renyi, barabasi_albert, complete_graph, path_graph, cycle_graph, star_graph, grid_graph, petersen_graph, watts_strogatz, configuration_model, expected_degree_graph
Layout spring, kamada_kawai, spectral, sfdp, hierarchical, bipartite, circular, shell, random
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.4.4.tar.gz (562.8 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.4.4-cp314-cp314-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

ocg-0.4.4-cp313-cp313-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

ocg-0.4.4-cp312-cp312-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

ocg-0.4.4-cp311-cp311-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for ocg-0.4.4.tar.gz
Algorithm Hash digest
SHA256 d6487ce8e265d3238f67a1b4291557ce0eb47a10cafa212b3e0731eb4fcfb6ae
MD5 dfa20735f371ff75c73a3ba092a79f8e
BLAKE2b-256 7c4f88021efc084b81b5a34be69d3d413579020330cdcdc2243e28e71b0e0115

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ocg-0.4.4-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ae4ab045b1a43e61b1bddf29bd43fe861bc249202169770246a963e26fd9272d
MD5 4d4d11cbad67c66dddd5ad9c49aa1b40
BLAKE2b-256 9b6ba2c178513f5d8df10c03f4c3152acaa9ce194d8187d65c69e3cc252cfad6

See more details on using hashes here.

File details

Details for the file ocg-0.4.4-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

  • Download URL: ocg-0.4.4-cp313-cp313-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.13, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for ocg-0.4.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 19f10b293c604f58ecf23eb964ef1ee3dae5709ec394a5a0df6e3a9cac084f57
MD5 6c72923fb94c9e1a078cc5e5277fe233
BLAKE2b-256 a5859fee3cc2c987d2338bb0d111089a8fc45d32ef82810ebc09c30dce4844cd

See more details on using hashes here.

File details

Details for the file ocg-0.4.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

  • Download URL: ocg-0.4.4-cp312-cp312-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.12, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for ocg-0.4.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aeb308087626b00287d0c00a65e72c161f718ae5f93f8c7b4f070d913386e1d4
MD5 3eaf526fb27a1e984416d594bbe2c1a7
BLAKE2b-256 ce237fd11ea90aab24e3c720d79798a4e97e7e77451530c2310e8ebcd95cf8d2

See more details on using hashes here.

File details

Details for the file ocg-0.4.4-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

  • Download URL: ocg-0.4.4-cp311-cp311-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.11, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for ocg-0.4.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 545f483e6b3774be707d0558204dec01ae1f572ba8efecdd7df193f7e1aaf5f9
MD5 bae8f7c377391e7fa656572510d0f190
BLAKE2b-256 210383acd50e3877ba224d587a75220d58f0e9bd76941bb0b29ffdc198d0bac0

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