Basic Program

We will write a basic Python program to send over an Aleph Program Message.

1 - Requirements

We will use Uvicorn for local testing and FastAPI to build our program.

  • Linux/ macOs :

pip3 install "uvicorn[standard]" fastapi

2 - Writing the program

To create the first program, open your favorite code editor and create a directory named my-program, containing a file named main.py.

.
└── my-program/
    └── main.py

Then write the following code in the file:

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
async def root():
    return {"message": "Hello World"}

That's it for your first program.

This code comes from the FastAPI tutorial. Have a look at it for a better understanding of what it does and how it works.

3 - Testing locally

Before uploading your program on Aleph, it is best to first test it locally.

Aleph uses the standard ASGI interface to interface with programs written in Python. ASGI interfaces with many Python frameworks, including FastAPI but also Django or Quart.

Test your program locally using uvicorn, an ASGI server:

go to your working repository and launch:

python3 -m uvicorn main:app --reload --host=0.0.0.0

Then open http://127.0.0.1:8000 . The --reload option will automatically reload your app when the code changes.

4 - Deploy

See the publish method.

Last updated