checkconnectnet
A tiny, dependency-free Python library for checking whether an HTTP or HTTPS endpoint is reachable.
Installation
pip install checkconnectnet
Usage
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:
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:
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:
from checkconnectnet import get_public_ip
public_ip = get_public_ip()
print(public_ip)
Command line
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:
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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file checkconnectnet-1.4.tar.gz.
File metadata
- Download URL: checkconnectnet-1.4.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07c3eb69f3864b6bfb4ea794e94e4062c50fd090de90ec1b7fe07b643751812b
|
|
| MD5 |
7c8186161737cec26a090662c8501b05
|
|
| BLAKE2b-256 |
65576b8a575eec1692aaabfb14e2fa8c510f8f636ee69d7251c5e0ba3107fd22
|
File details
Details for the file checkconnectnet-1.4-py3-none-any.whl.
File metadata
- Download URL: checkconnectnet-1.4-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa264aa5ca867a6019295a40349f7de5b913cf43ea068fb3c0af9d796bbba3ab
|
|
| MD5 |
b135e312d994d835b3cd2eee62c2d425
|
|
| BLAKE2b-256 |
f5f09c71be613d0c678a072df771c0d0a280a3cef6abc81ca1358b1b569d628f
|