neo4j-client

Neo4j Client
(CLI and library)

View the Project on GitHub cleishm/libneo4j-client

Fork me on GitHub

About

neo4j-client is a command shell (CLI) for Neo4j. It supports secure connections to Neo4j server, sending of statements (including multiline statements), persistent command history, and rendering of results to tables or CSV.

neo4j-client utilizes the Bolt Network Protocol, and will work with any server that supports Bolt.

For more details, see the FAQ.

Requirements

neo4j-client is known to work on GNU/Linux, Mac OS X and FreeBSD. It requires neo4j 3.0.0 or later.

Getting Started

If you're using Mac OS X, neo4j-client can be installed using homebrew:

$ brew install cleishm/neo4j/neo4j-client

If you're using Ubuntu, neo4j-client can be installed using APT:

$ sudo add-apt-repository ppa:cleishm/neo4j
$ sudo apt-get update
$ sudo apt-get install neo4j-client libneo4j-client-dev

For other platforms, please see Building below.

neo4j-client Usage

Example interactive usage:

Example non-interactive usage:

$ echo "MATCH (n:Person) RETURN n.name AS name, n.born AS born LIMIT 3" | \
     neo4j-client -u neo4j -P localhost > result.csv
Password: *****
$
$ cat result.csv
"name","born"
"Keanu Reeves",1964
"Carrie-Anne Moss",1967
"Laurence Fishburne",1961
$

Evaluating source files:

$ cat query.cyp
:set echo
:export name='Emil'

// Create a person node if it doesn't exist
begin;
MERGE (:Person {name: {name}});
commit;

// return the total number of people
MATCH (n:Person)
RETURN count(n);
$
$ neo4j-client -u neo4j -p pass -o result.out -i query.cyp localhost
$ cat result.out
+:export name='Emil'
+begin;
+MERGE (:Person {name: {name}});
Created 1 node, set 1 property, added 1 label
+commit;
+MATCH (n:Person)
 RETURN count(n);
"count(n)"
137
$

libneo4j-client

libneo4j-client is a client library for Neo4j, written in C, and intended as a foundation on which basic tools and drivers for various languages may be built. libneo4j-client takes care of all the detail of establishing a session with a Neo4j server, sending statements for evaluation, and retrieving results.

libneo4j-client provides a single C header file, neo4j-client.h, for inclusion in source code using the libneo4j-client API. The API is described in the API Documentation.

libneo4j-client can be included in your project by linking the library at compile time, typically using the linking flags -lneo4j-client -lssl -lcrypto. Alternatively, libneo4j-client ships with a pkg-config description file, enabling you to obtain the required flags using pkg-config --libs libneo4j-client.

API Documentation

API documentation for the latest release is available at https://cleishm.github.io/libneo4j-client/doc/latest/neo4j-client_8h.html.

Example

#include <neo4j-client.h>
#include <errno.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    neo4j_client_init();

    /* use NEO4J_INSECURE when connecting to disable TLS */
    neo4j_connection_t *connection =
            neo4j_connect("neo4j://user:pass@localhost:7687", NULL, NEO4J_INSECURE);
    if (connection == NULL)
    {
        neo4j_perror(stderr, errno, "Connection failed");
        return EXIT_FAILURE;
    }

    neo4j_result_stream_t *results =
            neo4j_run(connection, "RETURN 'hello world'", neo4j_null);
    if (results == NULL)
    {
        neo4j_perror(stderr, errno, "Failed to run statement");
        return EXIT_FAILURE;
    }

    neo4j_result_t *result = neo4j_fetch_next(results);
    if (result == NULL)
    {
        neo4j_perror(stderr, errno, "Failed to fetch result");
        return EXIT_FAILURE;
    }

    neo4j_value_t value = neo4j_result_field(result, 0);
    char buf[128];
    printf("%s\n", neo4j_tostring(value, buf, sizeof(buf)));

    neo4j_close_results(results);
    neo4j_close(connection);
    neo4j_client_cleanup();
    return EXIT_SUCCESS;
}

Building

To build software using libneo4j-client, consider installing libneo4j-client using the package management system for your operating system (currently only Mac OS X). See Getting Started for detail.

NOTE: Recent versions of Mac OS X ship without the OpenSSL header files, and autoconf doesn't pick this up (yet). Please use the homebrew package to install on Mac OS X.

If libneo4j-client is not available via your package management system, please download the latest release and then:

$ ./configure
$ make clean check
$ sudo make install

libneo4j-client requires OpenSSL, although this can be disabled by invoking configure with --without-tls.

neo4j-client also requires some dependencies to build, including libedit and libcypher-parser. If these are not available, the library can be built without neo4j-client, by invoking configure with --disable-tools.

Support

Having trouble with libneo4j-client or neo4j-client? Please raise any issues with usage on StackOverflow. If you've found a bug in the code for libneo4j-client, please raise an issue on GitHub and include details of how to reproduce the bug.

Contributing

Contributions to libneo4j-client are welcome and encouraged! Please see the GitHub repository for more detail.

License

libneo4j-client is licensed under the Apache License, Version 2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.