Create your first graph
Once you have the Kùzu CLI or your preferred client library installed, you can define a graph schema and
begin inserting data to the database using Cypher. The example below uses a
graph schema with two node types, User
and City
, and two relationship types, Follows
and LivesIn
.
The dataset in CSV format can be found here.
Quick start
Because Kùzu is an embedded database, there are no servers to set up — you can simply import
the kuzu
module in your preferred client library and begin interacting with the database. Cypher queries
can be passed as string literals to the execute
(or equivalent) method in the respective client,
or run directly in the Kùzu CLI shell.
Result:
The approach shown above returned a list of lists containing query results. See below for more output options for Python.
Pandas
You can also pass the results of a Cypher query to a Pandas DataFrame
for downstream tasks. This assumes that pandas
is installed in your environment.
Polars
Polars is another popular DataFrames library for Python users, and you
can process the results of a Cypher query in much the same way you did with Pandas. This assumes
that polars
is installed in your environment.
Arrow Table
You can also use the PyArrow library to work with
Arrow Tables in Python. This assumes that pyarrow
is installed in your environment. This
approach is useful when you need to interoperate with other systems that use Arrow as a backend.
In fact, the get_as_pl()
method shown above for Polars materializes a pyarrow.Table
under the hood.
Result:
Kùzu’s Java client library is available as a JAR file that you can include in your project. You can
download the latest version here. The JAR file is referenced in the classpath
with the -cp
flag.
Below is the project structure for a simple Java application that creates a graph schema and inserts data into the database for the given example.
The Main.java
contains the following code:
To execute the example, navigate to the project root directory and run the following command:
Result:
For users who prefer Maven, our jar file can also be manually referenced from your Maven configuration:
Please note that we will soon provide a more convenient Maven-based solution for installing our API directly from Maven Central.
When installing the kuzu
crate via Cargo, it will by default build and statically link Kùzu’s C++
library from source. You can also link against the dynamic release libraries (see the Rust
crate docs for details).
The main.rs
file contains the following code:
Result:
The Kùzu C++ client is distributed as so
/dylib
/dll+lib
library files along with a header file (kuzu.hpp
).
Once you’ve downloaded and extracted the C++ files into a directory, it’s ready to use without
any additional installation. You just need to specify the library search path for the linker.
In the following example, we assume that the so
/dylib
/dll+lib
, the header file, the CSV files, and
the cpp code file are all under the same directory as follows:
The main.cpp
file contains the following code:
Compile and run main.cpp
. Since we did not install the libkuzu
as a system library, we need to
override the linker search path to correctly compile the C++ code and run the compiled program.
On Linux:
On macOS:
On Windows, the library file is passed to the compiler directly and the current directory is used
automatically when searching for kuzu_shared.dll
at runtime:
Result:
The Kùzu C API shares the same so
/dylib
library files with the C++ API and can be used by
including the C header file (kuzu.h
).
In this example, we assume that the so
/dylib
, the header file, the CSV files, and the C code file
are all under the same directory:
The file main.c
contains the following code:
Compile and run main.c
: Since we did not install the libkuzu as a system library, we need to
override the linker search path to correctly compile the C code and run the compiled program.
On Linux:
On macOS:
On Windows, the library file is passed to the compiler directly and the current directory is used
automatically when searching for kuzu_shared.dll
at runtime:
Result:
When using the Kùzu CLI’s shell, you need to first initialize an empty database.
Then, proceed to enter the following Cypher statements separated by semicolons. Note that you must indicate the end of each query statement with a semicolon in the shell, otherwise it will not be parsed correctly and fail to execute.
The following result is obtained: