package neo4j_bolt
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page
Pure OCaml Neo4j Bolt protocol client with TLS support
Install
dune-project
Dependency
Authors
Maintainers
Sources
v0.3.0.tar.gz
sha512=77bbf2a38cb070ffe6633c569e7ed5ba6bfed3cf7cee5f0dffb6914fedd660d0e205f61b7b094b6e145fb64c330d26d3139ac23678500a38b5b6f8e9826a13ae
doc/README.html
ocaml-neo4j-bolt
Pure OCaml Neo4j Bolt protocol client with TLS support.
Features
- Bolt 4.x/5.x protocol support
- TLS/SSL connections (
bolt+s://,bolt+ssc://) - PackStream binary serialization (spec)
- Async I/O with Lwt
- No Python subprocess required
Install
opam install neo4j_boltQuick Start
let () = 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 ()
endConnection Schemes
Scheme | 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 |
URI-based Connection
let* conn = Neo4j_bolt.Bolt.connect_uri
~uri:"bolt+s://neo4j.example.com:7687"
~username:"neo4j"
~password:"secret"
() inConfiguration
Environment Variables
# 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"Programmatic Config
let config = Neo4j_bolt.Bolt.{
host = "localhost";
port = 7687;
username = "neo4j";
password = "secret";
timeout_s = 30.0;
tls_mode = NoTLS; (* or TLS, TLSSelfSigned *)
}API Reference
Connection
connect- Connect using default/environment configconnect_uri- Connect using URI stringclose- Close connectionis_tls_connection- Check if TLS is enabledconnection_info- Get connection info string
Queries
run- Execute Cypher query (returns PackStream)query- Execute Cypher query (returns JSON)test_connection- Verify connection with simple querycount_nodes- Count nodes with a label
Types
tls_mode-NoTLS | TLS | TLSSelfSignederror-ConnectionError | HandshakeError | AuthError | ProtocolError | Timeout
Examples
Count Nodes
let* 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)Parameterized Query
let params = `Assoc [("name", `String "Alice")] in
let* result = Neo4j_bolt.Bolt.query conn
~cypher:"MATCH (p:Person {name: $name}) RETURN p"
~params
() inRequirements
- OCaml >= 4.14
- lwt, lwt_ppx
- lwt_ssl, ssl (for TLS support)
- yojson
License
MIT
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page