Skip to content
Dashboard

Python Quickstart

Deploy a Python HTTP application as a NexHost Web Service.

Python Quickstart#

Use a Web Service for a Python HTTP application. The runtime command must bind to the port supplied in PORT.

Create a Flask application#

Create app.py:

python
import os
from flask import Flask

app = Flask(__name__)

@app.get("/")
def home():
    return "Hello from NexHost"

@app.get("/health")
def health():
    return {"ok": True}

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=int(os.environ["PORT"]))

Create requirements.txt:

text
Flask
gunicorn

Configure the service#

  1. Select Web Service in New Project.
  2. Connect the repository or archive containing app.py and requirements.txt.
  3. Set Build command to pip install -r requirements.txt.
  4. Set Start command to gunicorn app:app --bind 0.0.0.0:$PORT.
  5. Set Health path to /health, then deploy.

For FastAPI, use a comparable uvicorn start command that sets --host 0.0.0.0 and --port $PORT.