How to Install your Python application on Cloud?

How to Install Python Application on Cloud?

The platform offers a ready-to-use integration of the scalable Apache application server, designed explicitly for hosting Python-based applications. It comes pre-optimized and ready for immediate management, enabling developers to dive straight into development without being burdened by various orchestration tasks. It ensures the hosting process is as convenient as possible for developers.

This article will introduce the key tools and features available on the platform, essential for offering the desired level of Python cloud hosting. Use the table of contents below to find the information you need within the guide quickly:

Python Environment Hosting

To start hosting your Python application on the Platform, create a suitable environment using the robust topology wizard (You can access this wizard through the “New Environment” button on the top panel of the dashboard).

Navigate to the Python language tab and choose the desired engine version. The Apache Python application server will be automatically included along with the mod_wsgi module. You can then set resource limits and nodes’ count as needed and add extra software stacks or options (e.g., Public IPs) if necessary.

Note: This template utilizes a contemporary system initialization daemon.

Note:

  • Each instance operates as a fully independent and isolated container.
  • Instances belonging to the same layer are automatically distributed across accessible hosts, ensuring high availability.

Python Versioning

As of the present time (at the time of writing this), the following Python versions are supported:

  • 3.6.15
  • 3.7.16
  • 3.8.16
  • 3.9.16
  • 3.10.11
  • 3.11.3

When setting up a new environment, you can select the desired Python version directly from the topology wizard. Furthermore, you can modify the Python version for existing environments using container redeployment.

Python Application Deployment

The platform automates the deployment process to the managed application servers (Apache Python), which can be carried out through one of the following flows:

  • From a remote VCS repository (e.g., GitHub)
  • Via an application archive uploaded from an external URL or the local machine.

The Git flow offers the flexibility of sequential or simultaneous deployment, and it also supports automatic redeployment from the repository whenever new code changes detect.

Python Packages/Modules Management

To ensure the successful deployment and execution of a Python application, additional modules or packages may need to install. A common practice is to run Python web applications in isolated virtual environments, for example, using the virtual environment tool. That enables the management of projects independently and without the need for administrator privileges.

  1. To connect to the Python environment via SSH (use either a local SSH or the built-in Web SSH client), run the following commands to create and start a new virtual environment:
  • virtualenv {appName}
  • source {appName}/bin/activate

  1. The management of the necessary software packages is typically facilitated by pip, a widely used Python package management system for the PiPI repository. Below are some of the most common pip commands:
  • pip install {packageName} – installs a necessary module
  • pip uninstall {packageName} – removes previously installed module
  • pip install -upgrade {packageName} – updates the specified module to its latest version
  • pip install -r requirements.txt – installs all the modules that are available in the requirements.txt file
  • pip list – shows the list of modules that are already available.

Tip: For preconfigured application packages (archives), the requirements.txt file contains all the necessary dependencies. This file is read automatically during deployment to install the listing Python modules, ensuring a hassle-free setup. The requirements.txt file should include the wsgi.py file, with the entry point script for running the application inside a virtual environment using mod_wsgi for Apache.

Domains Management

If necessary, you can replace the default domain name of your Python application with a custom one by using the following method:

  • When using Shared Load Balancer, CNAME redirection recommend for dev and test environments.
  • When using a public IP, DNS A Record can handle high traffic loads and is suitable for production environments.

Moreover, the platform offers the capability to swiftly switch traffic between two environments without any downtime (e.g., seamless redirection of customers to the newer application version) using either the swap domains functionality or the SwapExtIps API/CLI method, ensuring smooth transitions and uninterrupted user experience during updates or changes.

Automatic Vertical Scaling

The platform’s automatic vertical scaling feature intelligently allocates the precise resources (RAM and CPU) your application needs at any time. It eliminates the need for constant manual adjustments based on the load. Moreover, when combined with the Pay-as-You-Use pricing model, it guarantees that you won’t be charged for unused resources, ensuring cost-effectiveness and efficiency in resource allocation.

Simply set the upper cloudlets limit for your Python application server (each cloudlet equals 128 MiB of RAM and 400 MHz of CPU), and the platform will take care of everything else automatically.

Manual Horizontal Scaling

Scaling the Python servers horizontally is as straightforward as scaling any other instance on the platform. Simply indicate the desired number of nodes using the +/- buttons in the topology wizard’s central part. If required, you can also select your preferred scaling mode:

There are two scaling modes available:

Stateless – This mode simultaneously creates all new nodes from the base image template.

Stateful – The file system of the master container is sequentially copy into the new nodes.

Tip: When scaling Python servers, the platform automatically includes a load balancer instance in the environment to ensure proper request distribution. For more detailed information and specifications, refer to the horizontal scaling documentation.

Automatic Horizontal Scaling

Go to the environment Settings > Auto Horizontal Scaling section to set up custom triggers to automatically increase or decrease the number of nodes due to the application load. Select a resource type to monitor (CPU, RAM, Network, Disk) and specify the scaling conditions. The platform handles the rest of the scaling process automatically.

Database Connection to Python Application

Within the platform, you can access a range of scalable database servers that can effortlessly install and use for your Python environment. To establish a connection, refer to the provided instructions tailored to the specific database you require:

  • MySQL Connection
  • MongoDB Connection

Conclusion

Discover top-tier Python hosting through our Platform as a Service (PaaS) solution. Experience the convenience of seamless integration, automated scaling, and exceptional performance for your Python-based applications. Start building and deploying quickly, and enjoy a hassle-free hosting experience with our high-quality PaaS platform.