Skip to content

Quick Start

Use the SessionManager to project data from your data lake into a Neptune Analytics graph, run algorithms, and export results.

  1. Install nx-neptune

    Terminal window
    pip install nx_neptune
  2. Set environment variables

    Terminal window
    export AWS_REGION=us-west-2
    export 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
  3. Project data and run algorithms

    from nx_neptune.session_manager import SessionManager
    session = 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 transactions
    UNION ALL
    SELECT "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 detection
    result = graph.execute_query(
    'CALL neptune.algo.louvain.mutate({writeProperty:"community"}) '
    'YIELD success RETURN success'
    )

Unit tests:

Terminal window
make test

Integration tests (requires a live Neptune Analytics instance):

Terminal window
export NETWORKX_GRAPH_ID=g-test12345
make integ-test