package neo4j_bolt
All checked builds passInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha512=77bbf2a38cb070ffe6633c569e7ed5ba6bfed3cf7cee5f0dffb6914fedd660d0e205f61b7b094b6e145fb64c330d26d3139ac23678500a38b5b6f8e9826a13ae
Description
A pure OCaml implementation of the Neo4j Bolt protocol with TLS/SSL support. Supports bolt://, bolt+s://, bolts://, and bolt+ssc:// connection schemes.
Added to opam-repository:
README
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
Dependencies (7)
Dev Dependencies (1)
-
alcotest
with-test
Optional Dependencies
None
Used by
None
Conflicts
None
Build status
Results of building neo4j_bolt with each compiler on check.ci.ocaml.org, run of against opam-repository 78c202b. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
| Version | OCaml 4.11 | OCaml 4.14 | OCaml 5.2 | OCaml 5.4 | OCaml 5.5 |
|---|---|---|---|---|---|
| 0.3.0 (this version) | n/a | good | good | good | good |
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure