Python on ISPmanager hosting

In the examples example.com is your domain. Use your own values.

A Python site runs as a separate application. The panel creates a virtual environment and starts the server.

1. Create the site

  1. "Sites" → "Create a site" → manual setup.
  2. Enter the domain in "Name", for example py.example.com.
  3. Untick "PHP" and tick "Python".
Python settings for a new site
Python settings for a new site
  1. Choose the "Python version".
  2. "Application mode": "Python web server" — your script runs as the server.
  3. "Path to server" is the file to run, server.py by default.
  4. Click "Create".
Python versions
Python versions
Site with the Python handler
Site with the Python handler

2. Site files

The panel creates server.py (a sample), an empty requirements.txt and the .venv virtual environment.

Python site files
Python site files

The app must listen on the socket in SOCKET, or on the port in PORT if "Use port" is enabled. Flask example with Waitress:

import os
from flask import Flask
from waitress import serve

app = Flask(__name__)

@app.get("/")
def index():
    return "Hello from Python!"

if __name__ == "__main__":
    sock = os.environ.get("SOCKET")
    if sock:
        if os.path.exists(sock):
            os.unlink(sock)
        serve(app, unix_socket=sock, unix_socket_perms="660")
    else:
        serve(app, host=os.environ.get("INSTANCE_HOST"), port=int(os.environ["PORT"]))

3. Packages

  1. Site menu → configuration files. List packages in requirements.txt, one per line.
Python items in the site menu
Python items in the site menu
requirements.txt in the panel editor
requirements.txt in the panel editor
  1. Site menu → "Pip install" → "Install". Packages go to the site .venv.
pip install
pip install
Installed Python packages
Installed Python packages

4. Restart

After changes: site menu → "Restart (Python)" → "Restart".

Restarting the application
Restarting the application
The application answers on the domain
The application answers on the domain

The site settings ("Edit" → the Python handler block) show the interpreter and pip paths. The Python version and server arguments are changed there too.

Python in the site settings
Python in the site settings

Python in the terminal

In the Shell client activate the site environment and use pip and manage.py as usual:

cd ~/www/py.example.com
source .venv/bin/activate
pip install -r requirements.txt
python manage.py migrate

For Django set "Path to server" to your own start file that runs a WSGI server (Waitress or Gunicorn) on the socket from SOCKET.

Questions and answers
Any: Flask, Django, FastAPI and others. The app must listen on the socket in SOCKET.
To the .venv virtual environment in the site folder.
List them in requirements.txt and choose "Pip install" in the site menu.
In the site settings, in the Python handler block.