yyds-mdns: Zero-Config mDNS Service Broadcaster & Discovery for Python
yyds-mdns is a lightweight, zero-configuration mDNS (Multicast DNS / Zeroconf) service registration and discovery library tailored for Python Web frameworks (FastAPI, Flask, Starlette, etc.) and standalone services.
Solve the annoyance of constantly changing DHCP IP addresses during local development, IoT, Raspberry Pi, or private server deployments.
Map http://192.168.x.x:8000 to http://my-service.local:8000 with just one line of code!
✨ Features
- ⚡ One-Line Integration: Seamless lifespan hook for FastAPI / Starlette and Flask extensions.
- 🌐 Real Hostname Resolution: Assembles both DNS-SD and IPv4
Ahost records so LAN browsers can directly navigate to.localdomains. - 🧠 Smart Interface & IP Detection: Automatically probes the OS outbound routing table and filters out loopback, unconfigured link-local, and Docker virtual bridges.
- 🛡️ Graceful Shutdown (Goodbye Packet): Automatically broadcasts TTL=0 goodbye packets upon SIGINT/SIGTERM or normal exit to avoid stale DNS caching on clients.
- 🔒 Multi-Worker Process Lock: Safe under
uvicorn --workers 4or Gunicorn deployments by ensuring only one process holds the broadcast. - 🔍 Lightweight Resolver & Scanner: Built-in
MDNSResolverto scan LAN services or resolve other.localdevices. - 💻 Standalone CLI Tool: Provides
yyds-mdns runfor non-Python applications (e.g. Ollama, MinIO, Docker containers).
📦 Installation
pip install yyds-mdns
No framework-specific plugins needed. It natively works out-of-the-box with any installed ASGI or WSGI framework.
🚀 Quick Start: Universal Experience
Whether you use FastAPI, Flask, Django, Sanic, or standalone Python scripts, you only ever need to import a single entrypoint:
from yyds_mdns import MDNS
1. FastAPI (One-Liner)
import uvicorn
from fastapi import FastAPI
from yyds_mdns import MDNS
app = FastAPI()
# One line to register: Accessible at http://my-api.local:8000
MDNS(app, name="my-api", port=8000)
@app.get("/")
def read_root():
return {"message": "Hello from mDNS!"}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
2. Flask
from flask import Flask
from yyds_mdns import MDNS
app = Flask(__name__)
# Register Flask service: Accessible at http://flask-app.local:5000
MDNS(app, name="flask-app", port=5000)
@app.route("/")
def index():
return "Hello Flask from mDNS!"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
3. Django (In wsgi.py or asgi.py)
from django.core.wsgi import get_wsgi_application
from yyds_mdns import MDNS
application = get_wsgi_application()
# Accessible at http://my-django.local:8000
MDNS(application, name="my-django", port=8000)
4. Universal Python Mode (Context Manager & Decorator)
Works with any TCP server, Sanic, Tornado, or standard library http.server:
from yyds_mdns import MDNS
# Synchronous context manager
with MDNS(name="custom-node", port=9090) as server:
print(f"Service live on {server.url} (IP: {server.ip})")
run_server()
# Asynchronous context manager
async with MDNS(name="async-service", port=8080):
await run_async_server()
# Function decorator
@MDNS(name="my-job", port=8888)
def serve():
run_server()
5. Service Discovery & Resolution Client
from yyds_mdns import MDNSResolver
# 1. Discover all active HTTP services in LAN (async_discover also available)
services = MDNSResolver.discover(service_type="_http._tcp.local.", timeout=2.0)
for s in services:
print(s["name"], "->", s["url"], s["ip"])
# 2. Resolve a specific .local service or host (async_resolve also available)
res = MDNSResolver.resolve("my-api")
if res:
print(f"IP: {res['ip']}, Port: {res['port']}")
6. Command-Line Interface (CLI)
Map any running port to a local domain without modifying code:
# Broadcast a local port (e.g. Ollama or Docker container)
yyds-mdns run --name my-ollama --port 11434
# Multi-node / LAN collision prevention (appends MAC hardware suffix, e.g. my-ollama-e6d3.local)
yyds-mdns run --name my-ollama --port 11434 --unique
# Discover services in LAN
yyds-mdns scan
# Resolve a specific service
yyds-mdns resolve my-api
# Resolve and open directly in default browser
yyds-mdns open my-api
# Show detected LAN IP
yyds-mdns ip
⚙️ Configuration Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
name |
str |
None (auto-inferred) |
Domain/service prefix, inferred from app.title, app.name, or filename. Supports {mac} placeholder (e.g. "node-{mac}") |
port |
int |
None (auto-inferred) |
Service port, resolved from PORT env or framework defaults (Flask 5000, ASGI 8000) |
unique |
bool |
False |
Multi-node conflict prevention. Automatically appends 4-char MAC suffix (e.g. my-app-e6d3.local) and injects device_id into TXT record |
ip |
str |
None (auto-detect) |
Explicit IPv4 address override |
interface |
str |
None (smart choice) |
Explicit network interface binding (e.g. "eno1", "eth0") |
protocol |
str |
"_http._tcp.local." |
DNS-SD service type, e.g. "_https._tcp.local." |
properties |
dict |
None |
Key-value pairs stored in DNS TXT record |
use_worker_lock |
bool |
True |
Prevents multi-worker broadcast collision |
allow_name_change |
bool |
False |
Automatically renames service (e.g. my-api-2) upon LAN collision |
strict |
bool |
True |
When False, logs a warning and degrades gracefully on registration failure |
watch_interval |
float |
0.0 |
Optional background interval (seconds) for DHCP IP refresh & worker failover |
verbose |
bool |
True |
Whether to print startup banner and shutdown notice to terminal |
🛠️ Testing & Building
Aligned with the yyds-fast repository standard:
# Run unit tests
python -m unittest discover -s tests -v
# Run build & package verification
./build.sh
📄 License
Licensed under the MIT License. Copyright (c) 2026 yyds-fast.
Metadata
Release files for yyds-mdns 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| yyds_mdns-0.1.6.tar.gz | 54.5 kB | Without provenance | Details for yyds_mdns-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| yyds_mdns-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for yyds_mdns-0.1.6-py3-none-any.whl |
Total release size: 98.8 kB
Release files / yyds_mdns-0.1.6.tar.gz
| Download URL | yyds_mdns-0.1.6.tar.gz |
|---|---|
| Size | 54.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5209505bec907727f9bbccc4e6588d42d975dbf2b547a6dbc5b823ec217a4975
|
|
BLAKE2b-256 checksum How to use checksums |
80d2c941c8212930f54c528c8f34ef68a6f47fa63969d0400fb7dee64fddbd95
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.11
|
Release files / yyds_mdns-0.1.6-py3-none-any.whl
| Download URL | yyds_mdns-0.1.6-py3-none-any.whl |
|---|---|
| Size | 44.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
40fad988c44f0cdf66f35c4156b91a6b7e207ddce2ddbd57c82170912d0ba699
|
|
BLAKE2b-256 checksum How to use checksums |
f7208be0ff8500ebd3b6c4147c3f0f0d09e98bb036fa059e349c75680d5010ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.11
|
Security for yyds-mdns 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.