Python and FastAPI
Two FastAPI apps run with uv. web renders Jinja2 pages under uvicorn and calls quotes over HTTPS with httpx, which trusts the devlanes CA through SSL_CERT_FILE.
Requirements
Section titled “Requirements”- devlanes, with
devlanes setuprun once - uv and Python 3.12
Run it
Section titled “Run it”cd languages-python-fastapidevlanes startdevlanes start --no-ui prints the start as text:
example-python-fastapi@0 (main): 2/2 readyready web http://127.0.0.1:20591 https://example-python-fastapi.localhostready quotes http://127.0.0.1:20590 https://quotes.example-python-fastapi.localhostOpen https://example-python-fastapi.localhost. The page shows lane 0 of example-python-fastapi, the request.url uvicorn saw, the answer of the lane’s quotes service, and whether your browser’s own call to quotes passed CORS.
During a start
Section titled “During a start”- On a lane’s first start the
synctask (when: lane.create) runsuv sync --frozen, which builds.venvfromuv.lock. Later starts skip it. webrunsuv run uvicorn acme.web.main:appwith--port ${{ self.port }}and serves https://example-python-fastapi.localhost.quotesrunsuv run quotes, the entry point in[project.scripts], which readsPORTandHOST, and serves https://quotes.example-python-fastapi.localhost.- Each service counts as ready once
/healthzanswers. The 3 minute timeout leaves room foruv runto sync again after auv.lockchange.
devlanes detects the python platform from pyproject.toml and gives both services SSL_CERT_FILE and REQUESTS_CA_BUNDLE (system roots plus the devlanes CA) and PYTHONUNBUFFERED=1. web gets QUOTES_URL from ${{ services.quotes.public_url }}, so its httpx call goes through the proxy over HTTPS. The proxy sends X-Forwarded-Proto: https and --proxy-headers makes uvicorn use it, so request.url and the page’s url_for links start with https://.
Try next
Section titled “Try next”Start a second lane:
git worktree add ../examples-checkout -b feat/checkout, thencd ../examples-checkout/languages-python-fastapi && devlanes start. https://example-python-fastapi1.localhost says lane 1, and itsquotesanswer comes from lane 1 too.Without a worktree,
devlanes lane new --name example-python-fastapi-review --startgives this folder a second lane, anddevlanes lane clean example-python-fastapi-review --yesremoves it.devlanes env show web --explainlistsSSL_CERT_FILE,REQUESTS_CA_BUNDLEandPYTHONUNBUFFEREDin thecontributorlayer. Your own shell does not have them, so the same httpx call from there fails withhttpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED]:Terminal window uv run python -c "import httpx; print(httpx.get('https://quotes.example-python-fastapi.localhost/healthz').text)"Change the footer in
src/acme/web/templates/base.htmland reload the page: Jinja reads the template again without a restart.Change
src/acme/web/main.pyand--reloadrestarts the server;devlanes logs web --tail 10showsStatReload detected changes in 'src\acme\web\main.py'. Reloading...(on Windows).quotessends CORS headers only to this lane’s origins. This printsaccess-control-allow-origin: https://example-python-fastapi.localhost, and prints nothing with lane 1’s origin,https://example-python-fastapi1.localhost(on Windows add--ssl-revoke-best-effort):Terminal window curl -sS -o /dev/null -D - -H "Origin: https://example-python-fastapi.localhost" https://quotes.example-python-fastapi.localhost/api/quotes | grep -i access-control
devlanes.yaml: thesynctask,webas arunstring,quotesas arun_script, each withhostsand anhttpready check.pyproject.toml: the pinned dependencies and thequotesentry point.src/acme/settings.py: every variable the apps read, parsed once.src/acme/web/: the page, the httpx call inquotes_client.pyand the Jinja templates.src/acme/quotes/: the API, with CORS fromDEVLANES_ORIGINSand themain()thatuv run quotescalls.