Skip to content

Run the example

This page guides you through running the Python transaction graph example.

Clone the repository

  1. Clone the Aerospike Graph repository.

    Open a terminal and clone the repository:

    Terminal window
    git clone https://github.com/aerospike/aerospike-graph.git
    cd aerospike-graph
    Cloning into 'aerospike-graph'...
    remote: Enumerating objects: 1234, done.
    remote: Counting objects: 100% (1234/1234), done.
    remote: Compressing objects: 100% (567/567), done.
    remote: Total 1234 (delta 456), reused 987 (delta 345)
    Receiving objects: 100% (1234/1234), 2.34 MiB | 5.67 MiB/s, done.
    Resolving deltas: 100% (456/456), done.
    Example response

Start Aerospike Graph Service

  1. Start the Docker containers.

    From the aerospike-graph repository root, start AGS and Aerospike Database:

    Terminal window
    docker compose up -d
    [+] Running 3/3
    ✔ Network asgraph_net Created
    ✔ Container aerospike-db Started
    ✔ Container aerospike-graph-service Started
    ✔ Container asgraph-zipkin Started
    Example response
  2. Wait for services to be ready.

    AGS waits for the database to complete startup before accepting connections. This typically takes 10 to 20 seconds.

  3. Check the AGS logs.

    Terminal window
    docker logs aerospike-graph-service
    Found named graphs: []
    Setting gremlinPool to 56 and threadPoolWorker to 7.
    ...
    Successfully configured Aerospike Graph Service.
    [INFO] c.a.f.r.FireflyServer - Warmup is complete.
    Example response

Install dependencies and run the Python example

  1. Navigate to the Python basic example directory.

    Terminal window
    cd python/basic
  2. Create a virtual environment.

    Terminal window
    python3 -m venv .venv
    source .venv/bin/activate
  3. Install the Gremlin Python driver.

    Terminal window
    python3 -m pip install gremlinpython
  4. Run the Python application.

    Execute the example script:

    Terminal window
    python example.py
    Connecting to Aerospike Graph Service...
    Connected to Aerospike Graph Service; Adding Data...
    Adding some users, accounts and transactions
    Data written successfully...
    QUERY 1: Transactions initiated by Alice:
    Transaction Amount: 200, Receiver Account ID: A2
    Transaction Amount: 892, Receiver Account ID: A3
    Transaction Amount: 472, Receiver Account ID: A5
    Transaction Amount: 825, Receiver Account ID: A2
    Transaction Amount: 887, Receiver Account ID: A5
    Transaction Amount: 149, Receiver Account ID: A5
    Transaction Amount: 613, Receiver Account ID: A2
    Transaction Amount: 244, Receiver Account ID: A5
    Transaction Amount: 132, Receiver Account ID: A3
    QUERY 2: Total transaction amounts initiated by users:
    {'A1': 4414, 'A2': 3998, 'A3': 3219, 'A4': 7351, 'A5': 6158}
    QUERY 3: Users who transferred greater than 100 to Alice:
    User: {'name': ['Bob']}
    User: {'name': ['Bob']}
    User: {'name': ['Diana']}
    User: {'name': ['Diana']}
    User: {'name': ['Diana']}
    User: {'name': ['Diana']}
    User: {'name': ['Diana']}
    User: {'name': ['Eve']}
    User: {'name': ['Eve']}
    User: {'name': ['Charlie']}
    QUERY 4: Properties of Bob:
    age: 35
    name: Bob
    userId: U2
    Dropping Dataset.
    Closing Connection...
    Example response

In the next pages you will walk through the example code in smaller sections identifying how the data model is constructed, what each query does, and how to extend the script with additional mutations.

Feedback

Was this page helpful?

What type of feedback are you giving?

What would you like us to know?

+Capture screenshot

Can we reach out to you?