Examples

The snippets below mirror how the packages are meant to be used together. Adjust hostnames, ports, and settings for your environment.

Plain Python service locator

import logging
from discovery_client import discover, load_config

logging.basicConfig(level=logging.INFO)

cfg = load_config(timeout=3.0, discovery_port=9999)
for hit in discover(config=cfg):
    print(hit.ip, hit.port, hit.raw_response)

First server only

from discovery_client import discover_one

node = discover_one()
if node:
    base = f"http://{node.ip}:{node.port}"
    print("Try:", base)

Interface-scoped discovery

from discovery_client import ClientConfig, discover

cfg = ClientConfig(
    timeout=5.0,
    interfaces_whitelist=["Ethernet", "Wi-Fi"],  # exact OS names
)
print(discover(config=cfg))

Note

Names differ by OS (e.g. en0 on macOS, eth0 on Linux). Use scripts/sanity_check.py in the client package while developing to print candidates.

Django server + auto listener

settings.py:

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "django_udp_discovery",
]

Run:

python manage.py runserver 0.0.0.0:8000

Separate Django “probe” project

settings.py:

INSTALLED_APPS = [
    "django.contrib.contenttypes",
    "discovery_client_django",
]
python manage.py discover_servers --timeout 10 --verbose

Operator restart with diagnostics

On the Django server:

python manage.py start_discovery --duration 300

Shows effective DISCOVERY_PORT, message strings, logging state, then tears down cleanly after five minutes unless interrupted.