Bottle Framework
Bottle is a fast and simple microframework of Python for building APIs, small-scale personal applications without the requirement of any dependencies. Bottle comes with a host of features like a built-in development server, plugins for various databases, request-dispatching routing, and several utilities.
This example illustrates the steps to build a simple Python app with the Bottle framework. This application will then be bundled and associated with an AppSail service, and deployed to the console.
-
Create a new folder in your local system for the Bottle app.
-
Navigate to the directory from your terminal and execute the following command to install Bottle:
copypython3 -m pip install bottle -t.
- You can now create your python index file and name it app.py or anything of your choice. Add the logic you require in the application’s code. Given below is a sample code for a basic “Hello World” program.
copyimport os import bottle app = bottle.Bottle() @app.route('/') def hello(): return "Hello, World!" if __name__ == '__main__': listen_port = int(os.getenv('X_ZOHO_CATALYST_LISTEN_PORT', 9000)) bottle.run(app, host='0.0.0.0', port=listen_port)
-
You can now initialize an AppSail service in the same directory from the CLI or add it in an existing project directory. The app’s source must be your application’s directory. Provide the following value while initializing the app service:
Stack: Python_3_9
-
Ensure all the Python application files along with the bottle modules are present in the build directory you specify during initialization. Catalyst will automatically ZIP your app files during deployment to the remote console.
-
Deploy the app service to the console.
-
You can then configure the startup command given below from the console:
copypython3 -u app.py
You can also configure this in the app-config.json file before deploying.
Access the deployed app service from its endpoint URL.
Last Updated 2023-12-14 16:25:23 +0530 +0530
Yes
No
Send your feedback to us