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:
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:
Flask
gunicornConfigure the service#
- Select Web Service in New Project.
- Connect the repository or archive containing
app.pyandrequirements.txt. - Set Build command to
pip install -r requirements.txt. - Set Start command to
gunicorn app:app --bind 0.0.0.0:$PORT. - 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.