The GraphAr Python SDK provides Python bindings for the GraphAr C++ library.
It lets Python applications read GraphAr metadata, use the high-level graph APIs,
and run the bundled graphar command-line tool.
This package is separate from the PySpark package in ../pyspark.
- Python >= 3.9
- pip
- CMake >= 3.15, Apache Arrow >= 12.0, and a C++ toolchain when building from source
pip install -U grapharVerify the installation:
python -c "import graphar; print(graphar.GraphInfo)"
graphar --helpClone the repository, then from its root:
pip install ./python
# for local development
pip install -e ./pythonThe project also publishes a development image:
docker run -it ghcr.io/apache/graphar-devLoad graph metadata from a GraphAr YAML file:
import graphar
graph_info = graphar.GraphInfo.load("path/to/graph.graph.yml")
print(graph_info.get_name())
print(graph_info.get_vertex_info("person").get_type())
print(graph_info.get_edge_info("person", "knows", "person").get_edge_type())Replace path/to/graph.graph.yml with the path to a GraphAr graph metadata file.
The Python SDK exposes the core GraphAr functionality through these modules:
graphar.graph_info: graph, vertex, edge, property, and metadata APIs.graphar.high_level: high-level vertex and edge collection APIs.graphar.types: GraphAr enum types used by metadata and high-level APIs.
Example scripts are available in python/example:
graph_info_example.pyshows how to load graph metadata and inspect vertex and edge information.high_level_example.pyshows how to use the high-level vertex and edge collection APIs.
The examples expect GAR_TEST_DATA to point to a directory that contains the
ldbc_sample/parquet/ldbc_sample.graph.yml test graph:
bash dev/download_test_data.sh
export GAR_TEST_DATA=/tmp/graphar-testing
python python/example/graph_info_example.py
python python/example/high_level_example.pyThe package installs a graphar command-line tool:
graphar --help
graphar show --path path/to/graph.graph.yml
graphar check --path path/to/graph.graph.ymlSee python/src/cli/README.md for more CLI examples.
Build the Python API documentation from the python directory:
make install_docs
make docsThe generated documentation is written to python/docs.
Install test dependencies from the repository root:
pip install -e "./python[test]"Run the Python tests from the python directory:
pytestSome tests require GAR_TEST_DATA; use dev/download_test_data.sh
if the test data is not available locally.
For general contribution guidelines, see ../CONTRIBUTING.md.
GraphAr is distributed under the Apache License 2.0. See ../LICENSE
and ../NOTICE for details.