Nexus Rust SDK
Official Rust SDK for Nexus graph database.
Compatibility: SDK 2.0.0 ↔
nexus-server2.0.0. SDK and server move in lockstep on the same X.Y.Z train; mismatches within the sameMAJOR.MINORare usually fine but only the exact-match build is in the test matrix. Seedocs/COMPATIBILITY_MATRIX.md.
The crate is published as nexus-graph-sdk (the generic
nexus-sdk name on crates.io is owned by the unrelated Nexus
Workflow project). The module name stays nexus_sdk, so every
use nexus_sdk::...; statement keeps working unchanged.
Installation
Add to your Cargo.toml:
[]
= "2.0.0"
Transports
The SDK is RPC-first starting in 1.0.0. The default endpoint is
nexus://127.0.0.1:15475 (native binary RPC, length-prefixed
MessagePack over TCP). URL scheme picks the transport:
| URL form | Transport | Default port |
|---|---|---|
nexus://host[:port] |
Binary RPC | 15475 |
http://host[:port] |
HTTP/JSON | 15474 |
https://host[:port] |
HTTPS/JSON | 443 |
host[:port] (no scheme) |
Binary RPC | 15475 |
Override per-client with ClientConfig.transport, per-process with
the NEXUS_SDK_TRANSPORT env var (values: nexus, http, https,
resp3, auto). URL scheme always wins over env/config.
See docs/specs/sdk-transport.md
for the canonical contract every Nexus SDK follows.
Usage
Basic Example
use NexusClient;
use HashMap;
async
With Authentication
use NexusClient;
// Using API key
let client = with_api_key?;
// Or using username/password
let client = with_credentials?;
// Force HTTP/JSON when you need a REST-only path
let legacy = new?;
Schema Management
// Create a label
let response = client.create_label.await?;
// List all labels. Each entry is a `LabelInfo { name, id }` —
// the second field is the catalog id allocated by the engine,
// not a count. (Renamed from `Vec<(String, u32)>` in 1.15.0.)
let labels = client.list_labels.await?;
for label in &labels.labels
// Create a relationship type
let response = client.create_rel_type.await?;
// List all relationship types. Each entry is a
// `RelTypeInfo { name, id }`.
let types = client.list_rel_types.await?;
for rel_type in &types.types
Multi-Database Support
// List all databases
let databases = client.list_databases.await?;
println!;
println!;
// Create a new database
let create_result = client.create_database.await?;
println!;
// Switch to the new database
let switch_result = client.switch_database.await?;
println!;
// Get current database
let current_db = client.get_current_database.await?;
println!;
// Create data in the current database
let result = client.execute_cypher.await?;
// Get database information
let db_info = client.get_database.await?;
println!;
// Drop database (must not be current database)
client.switch_database.await?; // Switch away first
let drop_result = client.drop_database.await?;
// Or connect directly to a specific database
let db_client = builder
.url
.database
.build?;
// All operations will use 'mydb'
let result = db_client.execute_cypher.await?;
High Availability with Replication
Nexus supports master-replica replication for high availability and read scaling. Use the master for all write operations and replicas for read operations.
use NexusClient;
use ;
use Arc;
/// Client for Nexus cluster with master-replica topology.
async
Replication Architecture
┌─────────────────────────────────────────────────────────────┐
│ Application │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ NexusCluster Client │ │
│ │ write() ──────────┐ read() ───────────────┐ │ │
│ └─────────────────────┼───────────────────────────┼───┘ │
└─────────────────────────┼───────────────────────────┼───────┘
│ │
▼ ▼
┌───────────────────┐ ┌─────────────────────┐
│ MASTER │ │ REPLICAS │
│ (writes only) │────▶│ (reads only) │
│ │ WAL │ ┌───────────────┐ │
│ • CREATE │────▶│ │ Replica 1 │ │
│ • UPDATE │ │ └───────────────┘ │
│ • DELETE │ │ ┌───────────────┐ │
│ • MERGE │────▶│ │ Replica 2 │ │
└───────────────────┘ │ └───────────────┘ │
└─────────────────────┘
Starting a Nexus Cluster
# Start master node
NEXUS_REPLICATION_ROLE=master \
NEXUS_REPLICATION_BIND_ADDR=0.0.0.0:15475 \
# Start replica 1
NEXUS_REPLICATION_ROLE=replica \
NEXUS_REPLICATION_MASTER_ADDR=master:15475 \
# Start replica 2
NEXUS_REPLICATION_ROLE=replica \
NEXUS_REPLICATION_MASTER_ADDR=master:15475 \
Monitoring Replication Status
use Client;
use Deserialize;
async
Features
- ✅ Native binary RPC transport (default on
nexus://URLs; ~3–10× lower latency vs HTTP/JSON) - ✅ Pluggable transport layer (
TransportMode::NexusRpc/Http/Https) - ✅ Cypher query execution
- ✅ Database statistics
- ✅ Health check
- ✅ Node CRUD operations (Create, Read, Update, Delete)
- ✅ Relationship CRUD operations (Create, Update, Delete)
- ✅ Batch operations (sequential implementation)
- ✅ Schema management (Labels, Relationship Types)
- ✅ Performance monitoring (Query statistics, slow queries, plan cache)
- ✅ Transaction support (BEGIN, COMMIT, ROLLBACK)
- ✅ Query builder for type-safe query construction
- ✅ Multi-database support (create, list, switch, drop databases)
- ✅ Retry logic with exponential backoff (basic implementation)
- ✅ API key authentication
- ✅ Username/password authentication
- ✅ Proper error handling
- ✅ Type-safe models
Dependencies Status
All dependencies are up-to-date:
reqwest0.12 - Latest stabletokio1.0 - Latest stableserde1.0 - Latest stableserde_json1.0 - Latest stablethiserror1.0 - Latest 1.x (2.0 available but breaking changes)anyhow1.0 - Latest stablefutures0.3 - Latest stableurl2.5 - Latest stablebase640.22 - Latest stabletracing0.1 - Latest stable
Examples
See the examples/ directory for complete examples:
basic_usage.rs- Basic operations with nodes, relationships, and schemawith_auth.rs- Authentication examplesperformance_monitoring.rs- Performance monitoring and statisticstransactions.rs- Transaction management examplesquery_builder.rs- Query builder usage examplesmulti_database.rs- Multi-database support examples
Run examples with:
Testing
Run tests with:
# Run unit tests
# Run integration tests (requires running Nexus server)
NEXUS_TEST_SERVER=http://localhost:15474
# Run specific test suites
Test Coverage
The SDK includes comprehensive tests for:
- ✅ Client initialization and configuration
- ✅ Cypher query execution
- ✅ Node CRUD operations
- ✅ Relationship CRUD operations (Create, Update, Delete)
- ✅ Schema management (Labels, Relationship Types)
- ✅ Transaction support (Begin, Commit, Rollback)
- ✅ Query builder functionality
- ✅ Performance monitoring
- ✅ Batch operations
- ✅ Multi-database support (Create, list, switch, drop databases)
Roadmap
- Native binary RPC transport (landed 1.0.0)
- Node CRUD operations
- Relationship CRUD operations (Create, Update, Delete)
- Schema management
- Integration tests
- Examples
- Transaction support
- Query builder
- Retry logic with exponential backoff (basic implementation)
- Neo4j compatibility comparison tests
- RESP3 transport (wire format parsed; implementation deferred)
- Connection pooling
License
Licensed under the Apache License, Version 2.0.
See LICENSE for details.