Installation and first application¤
Installation¤
ASAB is distributed via pypi. There are three installation options:
You can clone the repository from the master branch using pip:
Or clone the repository manually:
You can install asab using the EasyInstall package manager.
Creating your first application¤
-
Create a file called
main.py
with the following code:main.py -
All ASAB applications use Python 3.7+. This is specified by a hashbang line at the very beginning of the file.
-
ASAB is included from as
asab
module via an import statement. -
Every ASAB Application needs to have an application object. It is a singleton: the application must create and operate precisely one instance of the application. ASAB provides the base [asab.Application][#TODO] class that you need to inherit from to implement your custom application class.
-
The
Application.main()
method is one of the application lifecycle methods, that you can override to implement desired application functionality. Themain
method is a coroutine, so that you can await any tasks etc. in a fully asynchronous way. This method is called when the ASAB application is executed and initialized. The lifecycle stage is called "runtime". -
In this example, the app is printing a message to the screen.
-
This part of the code is executed when you launch the Python program. It creates the application object and executes the
run()
method which creates and runs an event loop. This is the standard way of starting any ASAB application.
-
-
Run the server:
If you see the following output, you have successfully created and run an ASAB application server.
-
Stop the application by pressing
Ctrl+C
.Info
ASAB is designed around an event loop. It is meant primarily for server architectures. For that reason, an ASAB application keeps running and serving requests unless or until you terminate the application. See run time.
You can continue with a step-by-step tutorial on how to build an ASAB-based web server.