Data Intelligence Suite with 4 line code to run Graph Algo on NebulaGraph
Documentation: https://github.com/wey-gu/nebulagraph-di#documentation
Source Code: https://github.com/wey-gu/nebulagraph-di
NebulaGraph Data Intelligence Suite for Python (ngdi) is a powerful Python library that offers APIs for data scientists to effectively read, write, analyze, and compute data in NebulaGraph.
With the support of single-machine engine(NetworkX), or distributed computing environment using Spark we could perform Graph Analysis and Algorithms on top of NebulaGraph in less than 10 lines of code, in unified and intuitive API.
Quick Start in 5 Minutes
- Setup env with Nebula-Up following this guide.
- Install ngdi with pip from the Jupyter Notebook with http://localhost:8888 (password:
nebula). - Open the demo notebook and run cells one by one.
- Check the API Reference
Installation
pip install ngdi
Usage
Call from nGQL
See more details in docs
RETURN ngdi("pagerank", ["follow"], ["degree"], "spark",
{space: "basketballplayer", max_iter: 10}, {write_mode: "insert"})
Spark Engine Examples
See also: examples/spark_engine.ipynb
Run Algorithm on top of NebulaGraph:
Note, there is also query mode, refer to examples or docs for more details.
from ngdi import NebulaReader
# read data with spark engine, scan mode
reader = NebulaReader(engine="spark")
reader.scan(edge="follow", props="degree")
df = reader.read()
# run pagerank algorithm
pr_result = df.algo.pagerank(reset_prob=0.15, max_iter=10)
Write back to NebulaGraph:
from ngdi import NebulaWriter
from ngdi.config import NebulaGraphConfig
config = NebulaGraphConfig()
properties = {"louvain": "cluster_id"}
writer = NebulaWriter(
data=df_result, sink="nebulagraph_vertex", config=config, engine="spark")
writer.set_options(
tag="louvain", vid_field="_id", properties=properties,
batch_size=256, write_mode="insert",)
writer.write()
Then we could query the result in NebulaGraph:
MATCH (v:louvain)
RETURN id(v), v.louvain.cluster_id LIMIT 10;
NebulaGraph Engine Examples(not yet implemented)
Basically the same as Spark Engine, but with engine="nebula".
- reader = NebulaReader(engine="spark")
+ reader = NebulaReader(engine="nebula")
Documentation
How it works
ngdi is an unified abstraction layer for different engines, the current implementation is based on Spark, NetworkX, DGL and NebulaGraph, but it's easy to extend to other engines like Flink, GraphScope, PyG etc.
┌───────────────────────────────────────────────────┐
│ Spark Cluster │
│ .─────. .─────. .─────. .─────. │
│ ; : ; : ; : ; : │
┌─▶│ : ; : ; : ; : ; │
│ │ ╲ ╱ ╲ ╱ ╲ ╱ ╲ ╱ │
│ │ `───' `───' `───' `───' │
Algo Spark │
Engine└───────────────────────────────────────────────────┘
│ ┌────────────────────────────────────────────────────┬──────────┐
└──┤ │ │
│ NebulaGraph Data Intelligence Suite(ngdi) │ ngdi-api │◀─┐
│ │ │ │
│ └──────────┤ │
│ ┌────────┐ ┌──────┐ ┌────────┐ ┌─────┐ │ │
│ │ Reader │ │ Algo │ │ Writer │ │ GNN │ │ │
┌───────▶│ └────────┘ └──────┘ └────────┘ └─────┘ │ │
│ │ │ │ │ │ │ │
│ │ ├────────────┴───┬────────┴─────┐ └──────┐ │ │
│ │ ▼ ▼ ▼ ▼ │ │
│ │ ┌─────────────┐ ┌──────────────┐ ┌──────────┐┌──────────┐ │ │
│ ┌──┤ │ SparkEngine │ │ NebulaEngine │ │ NetworkX ││ DGLEngine│ │ │
│ │ │ └─────────────┘ └──────────────┘ └──────────┘└──────────┘ │ │
│ │ └──────────┬────────────────────────────────────────────────────┘ │
│ │ │ Spark │
│ │ └────────Reader ────────────┐ │
│ Spark Query Mode │ │
│ Reader │ │
│Scan Mode ▼ ┌─────────┐
│ │ ┌───────────────────────────────────────────────────┬─────────┤ ngdi-udf│◀─────────────┐
│ │ │ │ └─────────┤ │
│ │ │ NebulaGraph Graph Engine Nebula-GraphD │ ngdi-GraphD │ │
│ │ ├──────────────────────────────┬────────────────────┼───────────────────┘ │
│ │ │ │ │ │
│ │ │ NebulaGraph Storage Engine │ │ │
│ │ │ │ │ │
│ └─▶│ Nebula-StorageD │ Nebula-Metad │ │
│ │ │ │ │
│ └──────────────────────────────┴────────────────────┘ │
│ │
│ ┌───────────────────────────────────────────────────────────────────────────────────────┐ │
│ │ RETURN ngdi("pagerank", ["follow"], ["degree"], "spark", {space: "basketballplayer"}) │──┘
│ └───────────────────────────────────────────────────────────────────────────────────────┘
│ ┌─────────────────────────────────────────────────────────────┐
│ │ from ngdi import NebulaReader │
│ │ │
│ │ # read data with spark engine, scan mode │
│ │ reader = NebulaReader(engine="spark") │
│ │ reader.scan(edge="follow", props="degree") │
└──│ df = reader.read() │
│ │
│ # run pagerank algorithm │
│ pr_result = df.algo.pagerank(reset_prob=0.15, max_iter=10) │
│ │
└─────────────────────────────────────────────────────────────┘
Spark Engine Prerequisites
- Spark 2.4, 3.0(not yet tested)
- NebulaGraph 3.4+
- NebulaGraph Spark Connector 3.4+
- NebulaGraph Algorithm 3.1+
NebulaGraph Engine Prerequisites
License
This project is licensed under the terms of the Apache License 2.0.
Metadata
Release files for ngdi 0.2.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| ngdi-0.2.6.tar.gz | 18.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ngdi-0.2.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 38.8 kB
Release files / ngdi-0.2.6.tar.gz
| Download URL | ngdi-0.2.6.tar.gz |
|---|---|
| Size | 18.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
19888c8488d37421196fd10aaa07accd75531dc0e416a7ed3ee86cff845e07b0
|
|
BLAKE2b-256 checksum How to use checksums |
167b73df577a25d2fa316418ce9dd9ea7ad9d82e48923f158a94dec888174b38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.4.6 CPython/3.8.10
|
Release files / ngdi-0.2.6-py3-none-any.whl
| Download URL | ngdi-0.2.6-py3-none-any.whl |
|---|---|
| Size | 20.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e9530d66cbd3516c0d252db74fc5f4df19ac87e4a218db173d25853532abc1da
|
|
BLAKE2b-256 checksum How to use checksums |
b44ad5651593e68ebccc1d6a55e9f641eb40b731293e07127aa3a0d65c8ef4fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.4.6 CPython/3.8.10
|
Security for ngdi 0.2.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.