Skip to main content

netdiag-client

Official Python client for NetDiag API - network diagnostics (HTTP, DNS, TLS, ping) as a service. Run distributed health checks from multiple regions worldwide.

Installation

pip install netdiag-client

Quick Start

from netdiag_client import NetDiagClient

client = NetDiagClient()

# Run a full diagnostic check
result = client.check("example.com")

print(f"Status: {result.status}")           # Status.HEALTHY, Status.WARNING, or Status.UNHEALTHY
print(f"Quorum: {result.quorum.required}/{result.quorum.total} (met: {result.quorum.met})")
print(f"Duration: {result.duration_ms}ms")

# Check for cross-region observations
for obs in result.observations:
    print(f"  [{obs.severity}] {obs.code}: {obs.message}")

# Inspect per-region results
for region in result.regions:
    print(f"{region.region}: {region.status}")
    if region.ping:
        print(f"  Ping: {region.ping.avg_rtt_ms}ms ({region.ping.received}/{region.ping.sent})")
    if region.dns:
        print(f"  DNS: {region.dns.query_time_ms}ms")
    if region.http:
        print(f"  HTTP: {region.http.status_code} in {region.http.total_time_ms}ms")

API Reference

Constructor

# Default configuration
client = NetDiagClient()

# With API key (increases rate limits)
client = NetDiagClient(api_key="your-api-key")

# Full options
client = NetDiagClient(
    base_url="https://api.netdiag.dev",  # API base URL
    api_key="your-api-key",              # API key for authentication
    timeout=30.0,                         # Request timeout in seconds
)

Context Manager

with NetDiagClient() as client:
    result = client.check("example.com")
    print(result.status)
# Client is automatically closed

Methods

check(host) -> CheckResponse

Run network diagnostics against a host.

# Simple usage
result = client.check("example.com")

# URLs are accepted (host is extracted automatically)
result = client.check("https://example.com/path")

# With options
from netdiag_client import CheckRequest

result = client.check(CheckRequest(
    host="example.com",
    port=443,
    regions="us-west,eu-central",
    ping_count=10,
    ping_timeout=5,
    dns="8.8.8.8",
))

check_prometheus(host) -> str

Run diagnostics and get results in Prometheus exposition format.

metrics = client.check_prometheus("example.com")
# Returns:
# netdiag_check_success{host="example.com",region="us-west"} 1
# netdiag_ping_rtt_ms{host="example.com",region="us-west"} 15.2
# netdiag_http_time_ms{host="example.com",region="us-west"} 120.0
# ...

is_healthy(host) -> bool

Quick check if a host is healthy.

if client.is_healthy("example.com"):
    print("All systems operational")

get_status(host) -> Status

Get the health status of a host.

from netdiag_client import Status

status = client.get_status("example.com")
if status == Status.HEALTHY:
    print("Host is healthy")

Error Handling

from netdiag_client import (
    NetDiagClient,
    NetDiagApiError,
    NetDiagRateLimitError,
)

client = NetDiagClient()

try:
    result = client.check("example.com")
except NetDiagRateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after_seconds}s")
except NetDiagApiError as e:
    print(f"API error: {e.status_code} - {e}")

Type Hints

Full type hints included for IDE support:

from netdiag_client import (
    CheckRequest,
    CheckResponse,
    LocationResult,
    QuorumInfo,
    Observation,
    PingResult,
    DnsResult,
    TlsResult,
    HttpResult,
    Status,
)

Response Types

CheckResponse

Property Type Description
host str Target hostname
status Status Overall health status
quorum QuorumInfo Quorum details (required, total, met)
duration_ms int Total check duration
observations list[Observation] Cross-region analysis findings
regions list[LocationResult] Per-region results

Observation Codes

Code Severity Description
DNS_ANSWERS_MISMATCH warning DNS differs across regions
CERT_EXPIRING_SOON warning Certificate expires < 30 days
CERT_WEAK_PROTOCOL warning TLS 1.0 or 1.1 detected
REGIONAL_FAILURE error Probe failed in some regions

Requirements

  • Python 3.10+
  • httpx

Documentation

Full documentation available at netdiag.dev/docs/python

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

netdiag_client-1.1.0.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

netdiag_client-1.1.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file netdiag_client-1.1.0.tar.gz.

File metadata

  • Download URL: netdiag_client-1.1.0.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for netdiag_client-1.1.0.tar.gz
Algorithm Hash digest
SHA256 ac1619702f3404c2b4c53e0129c615d121af7aba8669d262e92232cfc3b3f42c
MD5 45422ab2028ea1d3e45841a93ab8e45c
BLAKE2b-256 39b7a13a05d2a90018e80d48e4101ea44d655710850bf5caaf5deb9e8e8458c2

See more details on using hashes here.

File details

Details for the file netdiag_client-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: netdiag_client-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for netdiag_client-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 56881d05886faae41863496c053c5f5df3fa6c93a56edee7f31e3ed183851ad0
MD5 eb2273c45f2f13a320365ee768e65f9f
BLAKE2b-256 4da95041839afb52bffc00537ac3e12a09814bc2b7e1bf5b3ebd9a4a968b742c

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 files

1.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page