Quick Start
Use the SessionManager to project data from your data lake into a Neptune Analytics graph, run algorithms, and export results.
-
Install nx-neptune
Terminal window pip install nx_neptune -
Set environment variables
Terminal window export AWS_REGION=us-west-2export NETWORKX_S3_IMPORT_BUCKET_PATH=s3://my-bucket/import/export NETWORKX_S3_EXPORT_BUCKET_PATH=s3://my-bucket/export/export NETWORKX_STAGING_BUCKET=s3://my-bucket/staging -
Project data and run algorithms
from nx_neptune.session_manager import SessionManagersession = SessionManager.session("my-session")graph = await session.get_or_create_graph(config={"provisionedMemory": 32})NODES = """SELECT DISTINCT "~id", 'customer' AS "~label"FROM (SELECT "nameOrig" as "~id" FROM transactionsUNION ALLSELECT "nameDest" as "~id" FROM transactions);"""EDGES = """SELECT "nameOrig" as "~from", "nameDest" as "~to", "type" AS "~label","amount" AS "amount:Float"FROM transactions;"""await session.import_from_table(graph, s3_import_path, [NODES, EDGES],catalog=catalog, database=database)# Run Louvain community detectionresult = graph.execute_query('CALL neptune.algo.louvain.mutate({writeProperty:"community"}) ''YIELD success RETURN success')
Use nx-neptune as a drop-in NetworkX backend to run algorithms on Neptune Analytics.
-
Install nx-neptune
Terminal window pip install nx_neptune -
Set your Neptune Analytics graph ID
Terminal window export NETWORKX_GRAPH_ID=your-neptune-analytics-graph-id -
Run a graph algorithm
import networkx as nxG = nx.Graph()G.add_node("Bill")G.add_node("John")G.add_edge("Bill", "John")r = nx.pagerank(G, backend="neptune")print(r) -
Execute
Terminal window python nx_example.py
Running tests
Section titled “Running tests”Unit tests:
make testIntegration tests (requires a live Neptune Analytics instance):
export NETWORKX_GRAPH_ID=g-test12345make integ-testNext steps
Section titled “Next steps”- Session Manager — project data lake sources into a graph
- NetworkX Backend — offload algorithms to Neptune Analytics
- Deployment — deploy with CloudFormation