Metadata-Version: 2.5
Name: tnldotdev-tnl
Version: 0.1.0rc42
Summary: take a shortcut through the internet.
License-Expression: BSD-3-Clause
License-File: LICENSE
License-File: NOTICE
License-File: THIRD_PARTY_LICENSES.txt
Requires-Python: >=3.12
Requires-Dist: httpx<0.29,>=0.28
Requires-Dist: starlette<2,>=0.45
Requires-Dist: uvicorn<1,>=0.40
Requires-Dist: websockets<17,>=14
Description-Content-Type: text/markdown

# tnldotdev-tnl

Give your Python ASGI app an HTTPS URL through tnl. Requires Python 3.12+
on macOS or Linux, arm64 or x64.

## publish an asgi app

Install the [tnl CLI](https://tnl.dev/docs/releases) for setup, then add the SDK and
prepare a namespace publisher:

```console
uv add tnldotdev-tnl
tnl auth login
tnl publisher setup --namespace
```

If your ASGI app lives in `myapp.py`, save this as `preview.py`:

```python
import asyncio

import tnl
from myapp import app


async def main():
    async with tnl.open(app) as tunnel:
        print(tunnel.url)
        await tunnel.wait()


asyncio.run(main())
```

Run `uv run python preview.py`. tnl starts the app and waits until its temporary
public URL can receive visitors. Press Ctrl+C to remove the URL and stop the
app. By default, visitors need a current sign-in, share link, or token.

To use a provisioned publisher credential instead of local setup, pass
`publisher_credential_file="/absolute/private/publisher.json"` to `tnl.open`, or
set `TNL_PUBLISHER_CREDENTIAL_FILE`.

## use a configured app

Declare an app service in `tnl.yml`:

```yaml
version: 1
tnl:
  services:
    api:
      public_url: {}
      target:
        type: app
```

Then start it with Uvicorn through tnl:

```python
import tnl

if __name__ == "__main__":
    tnl.run("myapp:app", service="api", port=0, reload=True)
```

Run from the project directory. `service="api"` selects the service above.
`port=0` picks a free port, and
`tnl wait` checks public readiness. Restart the project's apps together after
changing configuration.

## connect to a service

Use `await tnl.connect("database")` to get settings for a declared service.
The platform wheel includes the native tnl binary required for every protocol.
See [Python connection examples](https://github.com/tnldotdev/tnl/blob/main/packages/py/connections.md) for PostgreSQL, TCP, Kubernetes,
and the current MySQL and HTTP adapter limits.
