Metadata-Version: 2.4
Name: neruton
Version: 0.2.0
Summary: Native pure-Python tunnel client & SDK for Neruton (WSS + Yamux HTTP/WebSocket intranet proxy)
Author: neruton contributors
License-Expression: MIT
Project-URL: Homepage, https://github.com/kaecho/neruton
Project-URL: Repository, https://github.com/kaecho/neruton
Project-URL: Issues, https://github.com/kaecho/neruton/issues
Keywords: neruton,tunnel,proxy,yamux,websocket,intranet,reverse-proxy,cloudflared
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: System Administrators
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
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: Programming Language :: Python :: 3.14
Classifier: Topic :: Internet :: Proxy Servers
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: websockets>=12.0
Requires-Dist: tomli>=2.0.1; python_version < "3.11"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Dynamic: license-file

# neruton (Python SDK & CLI)

Native pure-Python tunnel client & SDK for [Neruton](https://github.com/kaecho/neruton) — self-hosted intranet penetration, wildcard subdomain reverse proxy, and WebSocket tunneling over port 443 (`WSS + Yamux`).

- **100% pure Python** (no Rust binary wrapper, no C extensions) implementing the exact Neruton control protocol and **Yamux v0** multiplexer byte-for-byte compatible with `neruton-server` (`yamux 0.13`).
- **Async & Sync Python APIs** with full PEP 561 type annotations (`py.typed`).
- **Drop-in CLI** (`neruton` and `python -m neruton`) sharing `~/.config/neruton/config.toml` (`0600`) and `NERUTON_SERVER` / `NERUTON_TOKEN` environment variables with the Rust CLI.
- **Full HTTP/1.1 & WebSocket forwarding** with Host rewriting, chunked streaming, local HTTPS (`--no-tls-verify`), automatic reconnect with sticky prefix, and fail-fast on HTTP 401 auth errors.

## Installation

```bash
pip install neruton
```

Requires Python 3.9+.

## Quick Start — Python SDK

### Async API (`asyncio` / FastAPI / Starlette / aiohttp)

```python
import asyncio
import neruton

async def main() -> None:
    async with neruton.connect(
        url="http://127.0.0.1:3000",
        server="https://neruton.moer.eu.org",
        token="ntk_your_token_here",
        subdomain="my-app",  # optional; auto-assigns UUID v4 if omitted
    ) as tunnel:
        print("Public URL :", tunnel.public_url)
        print("Preview URL:", tunnel.preview_url)
        print("Path URL   :", tunnel.path_url)
        print("Prefix     :", tunnel.prefix)
        await tunnel.wait()

asyncio.run(main())
```

Shorthand helpers for local ports:

```python
async with neruton.forward(3000, subdomain="my-app") as tunnel:
    print(tunnel.public_url)

# Alias matching `neruton http 8080`:
tunnel = await neruton.http(8080)
try:
    print(tunnel.public_url)
finally:
    await tunnel.close()
```

### Sync API (Flask / Django / Scripts / Notebooks)

`neruton.open(...)` runs the tunnel's `asyncio` event loop on a dedicated daemon thread and shuts down cleanly when exiting the `with` block:

```python
import neruton

with neruton.open(5000, server="https://neruton.moer.eu.org", token="ntk_your_token_here") as tunnel:
    print("Tunnel live at:", tunnel.public_url)
    app.run(port=5000)
```

### Config Helpers

```python
import neruton

print(neruton.config_path())  # ~/.config/neruton/config.toml
neruton.save_config(server="https://neruton.moer.eu.org", token="ntk_your_token_here")
cfg = neruton.load_config()
```

## Quick Start — CLI

```bash
# Save default server and tunnel token (writes mode 0600 config.toml)
neruton config set --server https://neruton.moer.eu.org --token ntk_your_token_here
neruton config show
neruton config path

# Forward a local port with an auto-generated UUID v4 subdomain
neruton http 3000

# Forward with a custom subdomain prefix
neruton http 8080 -s my-app
neruton tunnel --url http://127.0.0.1:3000 --subdomain my-app

# Or invoke as a Python module
python -m neruton http 3000
python -m neruton version
```

## License

MIT
