Metadata-Version: 2.4
Name: neruton
Version: 0.3.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`).
- **Default DNS-over-HTTPS (RFC 8484) + Hidden SNI**: zero-dependency IP-based DoH (zero bootstrap DNS leak) paired with TLS ClientHello TCP fragmentation by default, plus custom/omitted SNI with strict RFC 6125 certificate verification.
- **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_*` 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)
        print("Transport  :", tunnel.transport_info)
        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)
```

### DNS-over-HTTPS (DoH) & Hidden SNI

By default (`doh="auto"`, `sni_mode="auto"`), non-local `wss://` connections resolve the gateway hostname via **RFC 8484 binary DoH** against IP-based endpoints (`1.0.0.1`, `223.5.5.5`, `1.1.1.1`, `8.8.4.4`, racing the first two with fallback — zero bootstrap DNS leak) and split the initial **TLS ClientHello across multiple TCP segments** while preserving full TLS 1.3 certificate validation. Local targets (`ws://`, `localhost`, `*.localhost`, `*.local`, and IP literals) automatically skip DoH and SNI hiding.

```python
# Strict DoH (fail instead of falling back to system DNS) + ClientHello fragmentation
async with neruton.connect(3000, doh="strict", sni_mode="fragment") as tunnel:
    print(tunnel.transport_info)

# Custom DoH endpoint(s) and custom/omitted SNI (cert is still verified against real server host)
async with neruton.connect(
    3000,
    doh=["https://1.0.0.1/dns-query", "https://223.5.5.5/dns-query"],
    sni_mode="none",  # or sni="example-front.example"
) as tunnel:
    ...

# Disable DoH and SNI hiding
async with neruton.connect(3000, doh=False, sni_mode="plain") as tunnel:
    ...
```

> **Note on TLS 1.3 ECH (`sni_mode="ech"`)**: Python's stdlib `ssl` module (3.9–3.14) does not yet expose native TLS 1.3 Encrypted Client Hello (ECH). Requesting `sni_mode="ech"` fails fast with `TunnelError`; use `sni_mode="auto"` / `"fragment"` in pure Python, or use the Rust `neruton` CLI when cryptographic TLS 1.3 ECH is required.

### 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",
    doh="auto",
    sni_mode="auto",
)
cfg = neruton.load_config()
```

## Quick Start — CLI

```bash
# Save default server, token, and stealth transport preferences (writes mode 0600 config.toml)
neruton config set --server https://neruton.moer.eu.org --token ntk_your_token_here --doh auto --sni-mode auto
neruton config show
neruton config path

# Forward a local port with default DoH + ClientHello TCP fragmentation
neruton http 3000

# Override DoH / SNI options per invocation (CLI flags > NERUTON_* env > config.toml > defaults)
neruton http 8080 -s my-app --doh strict --sni-mode fragment
neruton tunnel --url http://127.0.0.1:3000 --no-doh --sni-mode plain
neruton http 3000 --sni-mode none
neruton http 3000 --sni moer.eu.org

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

Environment variables: `NERUTON_SERVER`, `NERUTON_TOKEN`, `NERUTON_DOH`, `NERUTON_SNI_MODE`, `NERUTON_SNI`, `NERUTON_ECH_CONFIG`.

## License

MIT
