From 5ec18817e872bcd9ca43f27e0650989680dd316a Mon Sep 17 00:00:00 2001 From: uartnet <140632163+uartnet@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:52:19 +0100 Subject: [PATCH 1/2] docs: run the FastAPI example directly from the first guide --- docs/000-getting-started.md | 55 +++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/docs/000-getting-started.md b/docs/000-getting-started.md index e22d763..e5f5ac9 100644 --- a/docs/000-getting-started.md +++ b/docs/000-getting-started.md @@ -24,13 +24,22 @@ the `asgi` extra alone. ## Run and verify the FastAPI application -[Install the CLI](https://rstream.io/docs/getting-started/installation) and -select a hosted project that allows HTTP publication. Replace the example -endpoint with the one shown by `rstream project list`. +For hosted rstream, [install the CLI](https://rstream.io/docs/getting-started/installation) +and use a project that permits HTTP publication. Sign in with the CLI. ```sh rstream login +``` + +List your projects. + +```sh rstream project list +``` + +Replace `my-project-endpoint` with the value from the `ENDPOINT` column. + +```sh rstream project use my-project-endpoint ``` @@ -45,8 +54,44 @@ export SSL_CERT_FILE=/path/to/ca-bundle.pem In PowerShell, set `$env:SSL_CERT_FILE = 'C:\path\to\ca-bundle.pem'`. Unattended services can use a provisioned identity. -Save the [README program](../README.md#publish-a-fastapi-application) as -`main.py` and run: +Save the following program as `main.py`. + +```python +import asyncio +from contextlib import suppress + +from fastapi import FastAPI + +import rstream + +app = FastAPI() + + +@app.get("/") +async def root() -> dict[str, str]: + return {"status": "ok"} + + +async def main() -> None: + async with ( + app.router.lifespan_context(app), + rstream.Client.from_env() as client, + await client.connect() as control, + ): + tunnel = await control.create_tunnel( + protocol="http", + http_version="http/1.1", + publish=True, + ) + print("Forwarding address:", tunnel.forwarding_address, flush=True) + await rstream.asgi.serve(app, tunnel) + + +with suppress(KeyboardInterrupt): + asyncio.run(main()) +``` + +Start the application from that directory. ```sh python main.py From b6ac656e575dd28ec1cf30661dda692a9cac7949 Mon Sep 17 00:00:00 2001 From: uartnet <140632163+uartnet@users.noreply.github.com> Date: Mon, 23 Nov 2026 21:39:41 +0100 Subject: [PATCH 2/2] Make the first FastAPI tunnel guide self-contained --- README.md | 14 ++++++++++---- docs/000-getting-started.md | 28 ++++++++++++++++++++-------- docs/004-testing.md | 14 ++++++-------- examples/README.md | 4 ++-- 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 949f77e..9a877bc 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,15 @@ The runtime connects to the engine over TLS. Datagram tunnels, QUIC runtime tran ## Publish a FastAPI application -[Install the package and select a project](https://github.com/rstreamlabs/rstream-python/blob/main/docs/000-getting-started.md). -This application owns FastAPI startup and shutdown and serves requests -directly over the tunnel. +Install FastAPI and the SDK's ASGI and API extras in the application's virtual environment. + +```sh +python -m pip install "rstreamlabs-rstream[asgi,api]" fastapi +``` + +Select a [project or Engine context](https://github.com/rstreamlabs/rstream-python/blob/main/docs/000-getting-started.md#run-and-verify-the-fastapi-application) +that permits published HTTP. Save the following as `main.py`. FastAPI handles +requests on the tunnel and owns the route at `/`. ```python import asyncio @@ -63,7 +69,7 @@ with suppress(KeyboardInterrupt): Run `python main.py` and open the forwarding address to receive `{"status":"ok"}`. The [first-application guide](https://github.com/rstreamlabs/rstream-python/blob/main/docs/000-getting-started.md) -explains how to verify the endpoint and build the checkout. +includes environment setup, access requirements and the checkout example. ## Documentation diff --git a/docs/000-getting-started.md b/docs/000-getting-started.md index e5f5ac9..7347d1d 100644 --- a/docs/000-getting-started.md +++ b/docs/000-getting-started.md @@ -24,20 +24,27 @@ the `asgi` extra alone. ## Run and verify the FastAPI application -For hosted rstream, [install the CLI](https://rstream.io/docs/getting-started/installation) -and use a project that permits HTTP publication. Sign in with the CLI. +With the [rstream CLI](https://rstream.io/docs/getting-started/installation) installed, sign in and approve the request in the browser. ```sh rstream login ``` -List your projects. +List the projects available to this identity. ```sh rstream project list ``` -Replace `my-project-endpoint` with the value from the `ENDPOINT` column. +If the list is empty, open the workspace in the [Dashboard](https://rstream.io/dashboard). +Workspace owners and admins can select **Create new project**. A Basic project +supports this HTTP example. Other members can ask an owner or admin for access +to an existing project. If the CLI login was limited to specific projects, run +`rstream login` again to include the intended project. Run `rstream project list` +again after gaining access. + +Choose a project that allows HTTP publication. Replace `my-project-endpoint` +with its `ENDPOINT` value. ```sh rstream project use my-project-endpoint @@ -54,7 +61,7 @@ export SSL_CERT_FILE=/path/to/ca-bundle.pem In PowerShell, set `$env:SSL_CERT_FILE = 'C:\path\to\ca-bundle.pem'`. Unattended services can use a provisioned identity. -Save the following program as `main.py`. +Save the application as `main.py`. ```python import asyncio @@ -91,7 +98,7 @@ with suppress(KeyboardInterrupt): asyncio.run(main()) ``` -Start the application from that directory. +Run it from the directory containing `main.py`. ```sh python main.py @@ -106,8 +113,8 @@ Stop the program with Ctrl+C. ## Build and test the checkout -Clone the repository. Create and activate an environment as above. From -the repository root, install the editable SDK and example dependencies. +Clone the repository and install the checkout in its own environment. +On macOS or Linux, run the following commands. ```sh git clone https://github.com/rstreamlabs/rstream-python.git @@ -115,6 +122,11 @@ cd rstream-python python3 -m venv .venv . .venv/bin/activate python -m pip install -e ".[examples,asgi,wsgi,api]" +``` + +On Windows, use the PowerShell environment commands under [Install the package](#install-the-package), then run the same editable install. To try the checkout's FastAPI example, select a context as above and run this from the repository root. + +```sh python examples/fastapi-tunnel/main.py ``` diff --git a/docs/004-testing.md b/docs/004-testing.md index eafb08d..2746636 100644 --- a/docs/004-testing.md +++ b/docs/004-testing.md @@ -90,15 +90,13 @@ not enable TLS 1.3 early data. ## Local self-hosted engine Follow the [self-hosted engine guide](https://rstream.io/docs/tunnels/self-hosted) -to configure a local engine, select its CLI context and run: +to configure a local Engine. Replace `tests` with its selected CLI context +and run the private-tunnel checks. ```bash -RSTREAM_CONTEXT=tests \ -RSTREAM_PYTHON_E2E=1 \ -RSTREAM_PYTHON_E2E_PUBLISHED=1 \ -RSTREAM_PYTHON_E2E_PUBLISHED_TCP=1 \ -pytest tests/e2e +RSTREAM_CONTEXT=tests RSTREAM_PYTHON_E2E=1 pytest tests/e2e ``` -Enable published checks only when the local engine supports them and its -forwarding addresses are reachable from the test process. +Add `RSTREAM_PYTHON_E2E_PUBLISHED=1` for published HTTP. Add +`RSTREAM_PYTHON_E2E_PUBLISHED_TCP=1` for published TCP when a port range +is configured. Each forwarding address must be reachable from the test process. diff --git a/examples/README.md b/examples/README.md index ecd8d29..50668f3 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,7 +1,7 @@ # Python application examples -[Install the checkout and start the FastAPI application](../docs/000-getting-started.md#build-and-test-the-checkout) -to verify your Python environment and Engine context. Run commands from the +[Install the checkout and its example dependencies](../docs/000-getting-started.md#build-and-test-the-checkout). +Tunnel examples also require a configured project or Engine. Run commands from the repository root unless an example gives a different directory. Framework samples use the SDK in this checkout. Webhook receivers can be tested locally with signed deliveries and need no Engine.