Run the example
This page guides you through running the Python transaction graph example.
Clone the repository
-
Clone the Aerospike Graph repository.
Open a terminal and clone the repository:
Terminal window git clone https://github.com/aerospike/aerospike-graph.gitcd aerospike-graphCloning 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
-
Start the Docker containers.
From the
aerospike-graphrepository 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 StartedExample response -
Wait for services to be ready.
AGS waits for the database to complete startup before accepting connections. This typically takes 10 to 20 seconds.
-
Check the AGS logs.
Terminal window docker logs aerospike-graph-serviceFound 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
-
Navigate to the Python basic example directory.
Terminal window cd python/basic -
Create a virtual environment.
Terminal window python3 -m venv .venvsource .venv/bin/activate -
Install the Gremlin Python driver.
Terminal window python3 -m pip install gremlinpython -
Run the Python application.
Execute the example script:
Terminal window python example.pyConnecting to Aerospike Graph Service...Connected to Aerospike Graph Service; Adding Data...Adding some users, accounts and transactionsData written successfully...QUERY 1: Transactions initiated by Alice:Transaction Amount: 200, Receiver Account ID: A2Transaction Amount: 892, Receiver Account ID: A3Transaction Amount: 472, Receiver Account ID: A5Transaction Amount: 825, Receiver Account ID: A2Transaction Amount: 887, Receiver Account ID: A5Transaction Amount: 149, Receiver Account ID: A5Transaction Amount: 613, Receiver Account ID: A2Transaction Amount: 244, Receiver Account ID: A5Transaction Amount: 132, Receiver Account ID: A3QUERY 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: 35name: BobuserId: U2Dropping 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.