Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
71 changes: 64 additions & 7 deletions docs/000-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,29 @@ 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`.
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 the projects available to this identity.

```sh
rstream project list
```

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
```

Expand All @@ -45,8 +61,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 application 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())
```

Run it from the directory containing `main.py`.

```sh
python main.py
Expand All @@ -61,15 +113,20 @@ 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
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
```

Expand Down
14 changes: 6 additions & 8 deletions docs/004-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 2 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Loading