Metadata-Version: 2.5
Name: rstreamlabs-rstream
Version: 0.8.2
Summary: Python SDK for rstream tunnels.
Project-URL: Homepage, https://rstream.io
Project-URL: Documentation, https://rstream.io/docs
Project-URL: Repository, https://github.com/rstreamlabs/rstream-python
Author: rstream
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: networking,rstream,tunnels,webhooks
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: protobuf<8,>=7.35.1
Requires-Dist: pyyaml<7,>=6.0.3
Provides-Extra: api
Requires-Dist: httpx<1,>=0.28.1; extra == 'api'
Provides-Extra: asgi
Requires-Dist: h11<1,>=0.16; extra == 'asgi'
Provides-Extra: dev
Requires-Dist: aiohttp<4,>=3.14.3; extra == 'dev'
Requires-Dist: build<2,>=1.5; extra == 'dev'
Requires-Dist: django<6,>=5.2.15; (python_version < '3.12') and extra == 'dev'
Requires-Dist: django<7,>=6.0.7; (python_version >= '3.12') and extra == 'dev'
Requires-Dist: fastapi<1,>=0.139.2; extra == 'dev'
Requires-Dist: flask<4,>=3.1.3; extra == 'dev'
Requires-Dist: httpx<1,>=0.28.1; extra == 'dev'
Requires-Dist: mypy<3,>=2.3; extra == 'dev'
Requires-Dist: pytest-asyncio<2,>=1.4; extra == 'dev'
Requires-Dist: pytest<10,>=9.1.1; extra == 'dev'
Requires-Dist: ruff<1,>=0.16; extra == 'dev'
Requires-Dist: trustme<2,>=1.2; extra == 'dev'
Requires-Dist: websockets<18,>=16.1.1; extra == 'dev'
Provides-Extra: examples
Requires-Dist: aiohttp<4,>=3.14.3; extra == 'examples'
Requires-Dist: django<6,>=5.2.15; (python_version < '3.12') and extra == 'examples'
Requires-Dist: django<7,>=6.0.7; (python_version >= '3.12') and extra == 'examples'
Requires-Dist: fastapi<1,>=0.139.2; extra == 'examples'
Requires-Dist: flask<4,>=3.1.3; extra == 'examples'
Requires-Dist: h11<1,>=0.16; extra == 'examples'
Provides-Extra: realtime
Requires-Dist: httpx<1,>=0.28.1; extra == 'realtime'
Requires-Dist: websockets<18,>=16.1.1; extra == 'realtime'
Provides-Extra: wsgi
Requires-Dist: h11<1,>=0.16; extra == 'wsgi'
Description-Content-Type: text/markdown

# rstream Python SDK

rstream connects services and devices through outbound connections, so they can be reached without opening inbound ports on their hosts. This SDK embeds that connection in a Python application, without a separate agent process.

Its async API fits `asyncio` services and workers. ASGI and WSGI adapters serve an existing web application directly over accepted tunnel streams; the same SDK can dial private services and verify webhook deliveries.

The package is named `rstreamlabs-rstream`; import it as `rstream`. Python 3.10 or newer is required.

## Where this SDK fits

An rstream agent connects outbound to the edge, which routes traffic to the application and applies project and tunnel policy. Published tunnels provide a forwarding address; private tunnels are reached by name or ID through an authenticated rstream client.

| Integration | Python support |
| --- | --- |
| Application servers | Serve HTTP/1.1 through ASGI, WSGI or accepted bytestreams. |
| Existing services | Forward tunnel connections to a local TCP port. |
| Private connectivity | Dial bytestream tunnels by name or ID. |
| Service discovery | Query inventory and watch lifecycle events with optional HTTP dependencies. |
| Webhooks | Verify signatures and parse deliveries in your framework. |

The runtime connects to the engine over TLS. Datagram tunnels, QUIC runtime transport and HTTP/3 tunnel creation are outside this SDK’s current scope. The [SDK guide](https://rstream.io/sdks) compares the available language and protocol choices.

## 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.

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

## Documentation

| Task | Guide |
| --- | --- |
| Install the SDK or build the checkout | [Getting started](https://github.com/rstreamlabs/rstream-python/blob/main/docs/000-getting-started.md) |
| Serve an application or forward an existing port | [Choose a tunnel integration](https://github.com/rstreamlabs/rstream-python/blob/main/docs/002-tunnels.md) |
| Find an equivalent Flask, Django or asyncio example | [Example catalog](https://github.com/rstreamlabs/rstream-python/blob/main/examples/README.md) |
| Configure credentials or verify a webhook | [Documentation index](https://github.com/rstreamlabs/rstream-python/blob/main/docs/README.md) |
| Develop the SDK | [Contributing](https://github.com/rstreamlabs/rstream-python/blob/main/CONTRIBUTING.md) |

## Security and support

Use [Security](SECURITY.md) to report vulnerabilities privately. Usage questions and reproducible bugs belong in [GitHub issues](https://github.com/rstreamlabs/rstream-python/issues); remove credentials and customer identifiers before sharing a reproduction. Licensed under [Apache-2.0](LICENSE).
