Abstraction and Serialization of the backend module
Setting up a backend module within the DASF Framework can be done by every newbie who just started with python. The basic API is very simple and a lot happens under the hood. So this here is already a backend module
1from demessaging import main
2
3
4__all__ = ["hello_world"]
5
6
7def hello_world(name: str) -> str:
8 return 'Hello World, ' + name
9
10
11if __name__ == "__main__":
12 main()
You are probably familiar with these things (unless you are completely new to python), but let’s go through it and explain a bit, what happens here in the background:
from demessaging import main
:This and the call of the
main()
function is the only DASF specific part in this framework. We will come to this function below__all__ = ["hello_world"]
This variable specifies, what should be available for the remote procedure call (see Specifying module members).
def hello_world(name: str) -> str:
This is the definition of a procedure that we want to make available as RPC through our framework. It’s just a python function with type annotations (see Abstracting procedures for more details.)
return 'Hello World, ' + name
This is the computing part that happens in the server stub. In our case we just combine two strings, but you could do anything here that python let’s you do.
main()
Now the magic happens. The
main()
function that takes control now. It interprets yourhello_world
function and transforms it into something, that can be used to execute remote procedure calls (a subclass of pydanticsBaseModel
, we’ll come to that later). It also generates a command-line interface that you can use to configure several aspects in DASF, see the backend config.
More in-depth details that describe what is happening behind the scenes are provided in the following sections.