Build Apps with Python
This guide will help you get started with building apps with Autonomi starting from scratch. This guide has 4 parts:
This has guide has been tested on MacOS, it should work on Linux or other unixes as well, but the commands might be slightly different for Windows (unless you are using WSL).
Prerequisites
First let's install the required tools to get started:
Python 3.9+
The uv Python package manager: to manage the python environment and install the dependencies, although you can use any other package manager you want.
The Rust toolchain installed, for running the testnet
Anvil: to run a local Ethereum testnet
Once all the above is ready, let's proceed to create a local testnet. For this testnet we will use the following Ethereum wallet which is the default address for our testnet.
The default private key and address (public key) for the testnet is:
It owns all the money on the testnet, you can use it to play around with the testnet! Which we will do in the next steps. Don't send real money to this address!!
Create a local testnet
An app is currently in development to make this process a one click thing, but for now we need to run the testnet manually.
First let's clone the Autonomi repository:
Then to run the testnet, run the following command:
Keep the terminal open and running.
In a separate terminal, in the same directory (autonomi), run the following command:
You now have a local Autonomi testnet running! Congrats! 🎉
Connect to the testnet with Python
Let's create a python project that interacts with the testnet. First let's setup a working environment and install the autonomi-client package.
Then create a new Python file in which we will write our app:
Open up the file in your favorite editor and add the following code:
In your terminal, run the following command to execute the script:
You should see the following output:
Congrats! You've just connected to the testnet! 🎉
Upload and retrieve data with Python
Next up let's upload some data to the testnet and retrieve it. We will be using the Autonomi data API for this. Expanding upon our previous work, change the main.py
file to the following:
For private data, use the
data_put
anddata_get
methods instead!
Congrats! If you got this far, you are ready to start building apps that can store data on Autonomi! 🎉
Going further
The API offers many other tools to interact with the Network which you can find here: Autonomi API Docs.
Cleanup and Troubleshooting
To stop and cleanup after a testnet, run the following commands to kill all the nodes, the evm testnet and delete all Autonomi related files.
Warning: If you are running local live nodes or apps/clients on Autonomi DO NOT DELETE THE WHOLE Autonomi data FOLDER asyou risk losing all your data. It is recommended to run testnets on a separate user or machine.
If you are on Windows, the Autonomi data folder is:
C:\Users\<username>\AppData\Roaming\autonomi
.
Note that the 3 programs above might end with .exe
For hackers
A ONE LINER I like to use to start a testnet (and the evm testnet too), and stop everything on CTRL+C
:
Note: this has to be run in the autonomi directory (the one we cloned in part 1)
Last updated