Metadata-Version: 2.1
Name: localtunnel-py
Version: 0.1.1
Summary: Python port of the localtunnel.me Client | Expose localhost to the world!
Home-page: https://github.com/gweidart/localtunnel-py
Author: gweidart
Author-email: gweidart <btnewcomer@pm.me>
License: MIT License
        
        Copyright (c) 2024 GweiDart
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/gweidart/localtunnel-py.git
Project-URL: Documentation, https://github.com/gweidart/localtunnel-py/README.md
Project-URL: Repository, https://github.com/gweidart/localtunnel-py.git
Project-URL: Issues, https://github.com/gweidart/localtunnel-py/issues
Project-URL: Changelog, https://github.com/gweidart/localtunnel-py/blob/master/CHANGELOG.md
Keywords: localtunnel,tunnel,proxy,local server,port forwarding,subdomain,networking,http proxy,python client,cli tool,remote access,webhooks,cloud proxy,dynamic DNS,ngrok alternative,localhost,secure tunnel,public URL,developer tools,devops,system administration,network utilities,web server,firewalls,python library,python proxy,port tunneling
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
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: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Internet
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: Proxy Servers
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Build Tools
Classifier: Topic :: System :: Networking
Classifier: Topic :: System :: Networking :: Firewalls
Classifier: Topic :: Utilities
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: aiohttp>=3.11.2
Requires-Dist: asyncio>=3.4.3
Requires-Dist: nest-asyncio>=1.5.6
Requires-Dist: rich>=13.9.4

# LocalTunnel Python Client

[![PyPI version](https://badge.fury.io/py/localtunnel-py.svg)](https://pypi.org/project/localtunnel-py/)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![Python Versions](https://img.shields.io/pypi/pyversions/localtunnel-py.svg)](https://pypi.org/project/localtunnel-py/)

Python port of the Localtunnel Client with _enhancements_

Expose your localhost to the 🌎 for easy testing and sharing:

- 👷🏻‍♂️ Actively maintained

A Python client for [LocalTunnel](https://localtunnel.github.io/www/), enabling developers to expose their local servers to the internet with minimal setup. Designed for ease of use, flexibility, and lightweight integration, this library supports both CLI and programmatic APIs.

---

## Overview

LocalTunnel provides a simple way to make a local development server accessible to anyone on the internet. Unlike similar tools like Ngrok, this library is lightweight, open-source, and Python-native, making it perfect for developers who prefer seamless integration into their Python projects.

---

## Installation

Install using a package manager 📦:

### via `pip`

```bash
pip install localtunnel-py
```

### via `uv`

```bash
uv add localtunnel-py
```

### via `poetry`

```bash
poetry add Localtunnel-py
```

For contributors or advanced users, clone the repository and install in editable mode:

```bash
git clone https://github.com/gweidart/localtunnel-py.git
cd localtunnel-py
pip install -e .
```

---

## Features

- **Expose Local Servers Effortlessly**:

  - Quickly share your local development server with a public URL.
  - Perfect for testing webhooks, sharing progress with team members, or debugging remotely.

- **Custom Subdomains**:

  - Use a custom subdomain to make your server URL more predictable and user-friendly.
  - Example: `https://my-custom-subdomain.loca.lt`

- **Robust Retry Mechanisms**:

  - Ensure tunnel connections are resilient with customizable retry strategies, including exponential backoff.

- **Monitoring and Lifecycle Management**:

  - Built-in support for monitoring tunnels to handle unexpected disruptions.
  - Automatically recover or notify when a tunnel goes offline.

- **Flexible Header Transformations**:

  - Modify request headers dynamically using `HeaderTransformer`.

- **Lightweight CLI Tool**:

  - A simple command-line interface for quick setup and deployment.

- **Seamless Integration**:

  - Import the library directly into your Python project and manage tunnels programmatically.

- **Extensive Logging**:
  - Pretty printed logging with rich tracebacks.

---

## Quick Start

### Programmatic API

Here’s how to expose a local server programmatically:

```python
import asyncio
from localtunnel.tunnel_manager import TunnelManager

async def main():
    manager = TunnelManager()
    manager.add_tunnel(port=8000, subdomain="my-subdomain")

    try:
        await manager.open_all()
        for tunnel in manager.tunnels:
            print(f"Tunnel open at URL: {tunnel.get_tunnel_url()}")

        # Keep running
        await asyncio.Event().wait()
    finally:
        await manager.close_all()

asyncio.run(main())
```

---

### CLI Usage

Expose a local server directly from the command line:

```bash
lt --port 3002 -s my-subdomain
```

Available arguments:

| Argument          | Description                                                 |
| ----------------- | ----------------------------------------------------------- |
| `-p, --port`      | Local port to expose via the tunnel (required).             |
| `-s, --subdomain` | Optional subdomain for the tunnel.                          |
| `-t, --host`      | LocalTunnel server URL (default: `https://localtunnel.me`). |
| `-m, --monitor`   | Enable monitoring of the tunnel.                            |

---

## Advanced Usage

### Create a new localtunnel

```python
import asyncio
from localtunnel.tunnel_manager import TunnelManager

async def main():
    manager = TunnelManager()
    manager.add_tunnel(port=8000, subdomain="my-subdomain")

    try:
        await manager.open_all()
        for tunnel in manager.tunnels:
            print(f"Tunnel open at URL: {tunnel.get_tunnel_url()}")

        # Keep running
        await asyncio.Event().wait()
    finally:
        await manager.close_all()

asyncio.run(main())

```

```

```

### Custom Header Transformations

Modify headers dynamically using `HeaderTransformer`:

```python
from localtunnel.header_transformer import HeaderTransformerFactory

transformer = HeaderTransformerFactory.create_transformer(
    transformer_type="host", host="my-custom-host"
)
headers = {"Authorization": "Bearer token"}
transformed_headers = transformer.transform(headers)
print(transformed_headers)
```

---

### Retry Strategies

Implement robust retry mechanisms for tunnel connections:

```python
from localtunnel.utils import ExponentialBackoffRetryTemplate

retry_strategy = ExponentialBackoffRetryTemplate(base_delay=1.0, max_delay=10.0)
retry_strategy.retry(some_function, retries=5)
```

---

### Managing Multiple Tunnels

Use `TunnelManager` to handle multiple tunnels seamlessly:

```python
from localtunnel.tunnel_manager import TunnelManager

manager = TunnelManager()
manager.add_tunnel(port=8000, subdomain="app1")
manager.add_tunnel(port=8001, subdomain="app2")
await manager.open_all()
```

---

## Troubleshooting

- **Issue**: Tunnel connection drops frequently.

  - **Solution**: Enable monitoring with `TunnelManager`.

- **Issue**: Custom subdomain not working.

  - **Solution**: Ensure the subdomain is available and correctly passed to `add_tunnel()`.

---

## Contributing

We welcome contributions! Here's how you can get involved:

1. Fork the repository.
2. Create a new branch for your feature or bugfix.
3. Submit a pull request with a detailed description.

---

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

---

## Links and Acknowledgments

- [Source Code](https://github.com/gweidart/localtunnel-py)
- [Issue Tracker](https://github.com/gweidart/localtunnel-py/issues)
- [Documentation](https://github.com/gweidart/localtunnel-py#readme)
