python.sh 1.0 KB

12345678910111213141516171819
  1. #!/usr/bin/env bash
  2. # ZCode Sites start.sh for a Python web server. Runs in the foreground on 0.0.0.0:3000.
  3. # Dependencies must already be in ./vendor (linux x86-64 wheels for Python 3.12); never install here.
  4. set -euo pipefail
  5. cd "$(dirname "${BASH_SOURCE[0]}")"
  6. export PYTHONPATH="$PWD/vendor${PYTHONPATH:+:$PYTHONPATH}"
  7. export PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1
  8. export PORT="${PORT:-3000}"
  9. # Writable but temporary storage (lost when the instance is recycled).
  10. export DATA_DIR="${DATA_DIR:-$PWD/data}"
  11. mkdir -p "$DATA_DIR"
  12. # ADJUST: the server command. Always use `python3 -m <tool>`: console scripts in vendor/bin
  13. # carry the build machine's interpreter path and do not run in the cloud.
  14. # FastAPI / Starlette (ASGI): exec python3 -m uvicorn main:app --host 0.0.0.0 --port "$PORT"
  15. # Flask (WSGI): exec python3 -m gunicorn --bind "0.0.0.0:$PORT" --workers 2 app:app
  16. # Django (WSGI): exec python3 -m gunicorn --bind "0.0.0.0:$PORT" --workers 2 mysite.wsgi
  17. exec python3 -m uvicorn main:app --host 0.0.0.0 --port "$PORT"