Metadata-Version: 2.4
Name: checkconnectnet
Version: 1.4
Summary: A tiny dependency-free Python library for checking internet connectivity.
License-Expression: MIT
Project-URL: Documentation, https://pypi.org/project/checkconnectnet/
Keywords: internet,connectivity,network,online
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Internet
Classifier: Topic :: System :: Networking
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# checkconnectnet

A tiny, dependency-free Python library for checking whether an HTTP or HTTPS endpoint is reachable.

## Installation

```bash
pip install checkconnectnet
```

## Usage

```python
from checkconnectnet import is_connected

if is_connected():
    print("Online")
else:
    print("Offline")
```

Without a URL, the library checks its primary endpoint first and automatically uses the public fallback if the first connection fails. You can also choose a custom URL and timeout:

```python
from checkconnectnet import check_connection

result = check_connection("https://example.com", timeout=3)
print(result.connected, result.status_code, result.elapsed_seconds, result.error)
```

Any HTTP response proves that the network request reached the server, including responses such as 403 or 404.

Flexible GET or POST requests are supported:

```python
from checkconnectnet import is_connected, send_request

online = is_connected(method="GET", params={"source": "desktop"})
result = send_request(
    method="POST",
    params={"source": "server"},
    json={"status": "checking"},
    headers={"X-App": "example"},
)
print(online, result.body)
```

Get the validated public IPv4 or IPv6 address:

```python
from checkconnectnet import get_public_ip

public_ip = get_public_ip()
print(public_ip)
```

## Command line

```bash
checkconnectnet
checkconnectnet --url https://example.com --timeout 3
```

The command exits with code `0` when connected and `1` when the request fails.

## Publishing to PyPI

Create an API token in your PyPI account, then run these commands from this directory:

```powershell
python -m pip install --upgrade build twine
python -m build
python -m twine check dist/*
$env:TWINE_USERNAME = "__token__"
$env:TWINE_PASSWORD = "pypi-your-api-token"
python -m twine upload dist/*
```

Do not save the PyPI token in this project or commit it to source control.
