3.1. Create a project
3.1.1. Basic structure
A Backendpy-based project does not have a mandatory, predetermined structure, and it is the programmer who decides how to structure his project according to his needs.
The programmer only needs to create a Python module with a custom name (for example “main.py”) and set the
Backendpy class (which is an ASGI application) inside it.
from backendpy import Backendpy bp = Backendpy()
Also for project settings, the
config.ini file must be created in the same path next to the module.
Check out the Configurations section for more information.
Backendpy projects are developed by components called Applications. It is also possible to connect third-party apps to the project.
To create an application, first create a package containing the
main.py module in the desired path within
the project (or any other path that can be imported).
Then inside the main.py module of an application we need to set an instance of the
All parts and settings of an application are assigned by the parameters of the App class.
For example, in the “/apps” path inside the project, we create a package called “hello” and main.py file as follows:
from backendpy.app import App from .handlers import routes app = App( routes=[routes])
from backendpy.router import Routes from backendpy.response import Text routes = Routes() @routes.get(r'^/hello-world$') async def hello_world(request): return Text('Hello World!')
As you can see, we have created another optional module called handlers.py and then introduced the routes defined in it to the App class instance. The complete list of App class parameters is described in section Applications structure.
Only the items that are introduced to the App class are important to the framework, and the internal structuring of the applications is completely optional.
Our application is now ready and you just need to enable it in the project config.ini file as follows:
[apps] active = project.apps.hello
To run the project, see the Run section.
Refer to the Application development section to learn how to develop applications.
3.1.3. Command line
backendpy command can also be used to create projects and apps.
To do this, first enter the desired path and then use the following commands:
18.104.22.168. Project creation
$ backendpy create_project --name myproject
To create a project with more complete sample components:
$ backendpy create_project --name myproject --full
22.214.171.124. App creation
$ backendpy create_app --name myapp
$ backendpy create_app --name myapp --full