outray is a Python library for creating HTTP, TCP, and UDP tunnels using https://outray.dev/. It allows you to forward local services to a remote endpoint easily.
Install via pip:
pip install outray- HTTP tunnel proxy (
HttpListener) - TCP tunnel proxy (
TCPListener) - UDP tunnel proxy (
UDPListener) - Forward a tunnel asynchronously or synchronously
- Built-in error handling and logging
- Asynchronous
import asyncio
from outray import forward, http
async def main():
listener = http("http://localhost:8080")
await forward(listener)
asyncio.run(main())- Synchronous
import asyncio
from outray import forward, http
listener = http("http://localhost:8080")
forward_sync(listener)- Multiple tunnels
import asyncio
from outray import forward, tcp, udp, http
async def main():
listners = [
http("http://localhost:8080", "small-arm"),
http("http://localhost:8080", "small-leg"),
udp("localhost", 8001, remote_port=30711),
udp("localhost", 8001, remote_port=30710),
tcp("localhost", 2002, remote_port=20711),
tcp("localhost", 2002, remote_port=20710),
]
await asyncio.gather(*[forward(l) for l in listners])
asyncio.run(main())Outray supports configuration via environment variables. These are optional but recommended.
Your API key used to authenticate tunnel connections.
export OUTRAY_API_KEY=your_api_key_hereIf not provided explicitly, forward and forward_sync will automatically read this value from the environment.
Equivalent code usage:
await forward(l1)
await forward(l1, api_key="API_KEY")The WebSocket endpoint used to establish tunnels.
export OUTRAY_API_URI=wss://api.outray.appIf not provided explicitly, this value is also read from the environment.
Equivalent code usage:
await forward(l1, api_key="API_KEY", ws_url="API_URL")from outray import tcp
listener = tcp(local_host="localhost", local_port=8090, remote_port=20710)from outray import udp
listener = udp(local_host="localhost", local_port=9000, remote_port=30710)from outray import http
listener = http(url="http://localhost:8080", subdomain="my-subdomain")from outray import forward
import asyncio
asyncio.run(forward(listener))forward(listener, ws_url=None, force_takeover=None, ping_interval=20, ping_timeout=20, api_key=None)- Forwards the listener to the remote WebSocket tunnel.
- Handles reconnects automatically.
from outray import forward_sync
forward_sync(listener)- Same as
forwardbut runs in a blocking synchronous context. - Useful for scripts that do not use
asyncionatively.
outray uses the standard Python logging module. To see detailed tunnel events:
import logging
logger = logging.getLogger("outray")
logger.setLevel(logging.DEBUG)