Pure OCaml Neo4j Bolt protocol client with TLS support.
bolt+s://, bolt+ssc://)opam install neo4j_boltlet () = Lwt_main.run begin
let open Lwt.Syntax in
let open Neo4j_bolt.Bolt in
(* Connect using environment variables *)
let* conn = connect () in
match conn with
| Error e -> print_endline (error_to_string e); Lwt.return ()
| Ok c ->
Printf.printf "Connected: %s\n" (connection_info c);
(* Run query *)
let* res = query c ~cypher:"MATCH (n) RETURN count(n) as total" () in
let* () = close c in
(match res with
| Ok j -> print_endline (Yojson.Safe.to_string j)
| Error e -> print_endline (error_to_string e));
Lwt.return ()
endScheme | Description | Use Case |
|---|---|---|
| Plain TCP | Local development |
| TLS with cert verification | Production (Neo4j Aura, etc.) |
| Alias for | Same as above |
| TLS without cert verification | Self-signed certificates |
let* conn = Neo4j_bolt.Bolt.connect_uri
~uri:"bolt+s://neo4j.example.com:7687"
~username:"neo4j"
~password:"secret"
() in# Option 1: URI (recommended)
export NEO4J_URI="bolt+s://neo4j.example.com:7687"
export NEO4J_USERNAME="neo4j"
export NEO4J_PASSWORD="your-password"
# Option 2: Individual settings
export NEO4J_HOST="localhost"
export NEO4J_PORT="7687"
export NEO4J_USERNAME="neo4j"
export NEO4J_PASSWORD="your-password"let config = Neo4j_bolt.Bolt.{
host = "localhost";
port = 7687;
username = "neo4j";
password = "secret";
timeout_s = 30.0;
tls_mode = NoTLS; (* or TLS, TLSSelfSigned *)
}connect - Connect using default/environment configconnect_uri - Connect using URI stringclose - Close connectionis_tls_connection - Check if TLS is enabledconnection_info - Get connection info stringrun - Execute Cypher query (returns PackStream)query - Execute Cypher query (returns JSON)test_connection - Verify connection with simple querycount_nodes - Count nodes with a labeltls_mode - NoTLS | TLS | TLSSelfSignederror - ConnectionError | HandshakeError | AuthError | ProtocolError | Timeoutlet* result = Neo4j_bolt.Bolt.count_nodes conn ~label:"Person" in
match result with
| Ok count -> Printf.printf "Found %d Person nodes\n" count
| Error e -> print_endline (Neo4j_bolt.Bolt.error_to_string e)let params = `Assoc [("name", `String "Alice")] in
let* result = Neo4j_bolt.Bolt.query conn
~cypher:"MATCH (p:Person {name: $name}) RETURN p"
~params
() inMIT