Registry / http-networking / zeroconf

zeroconf

JSON →
library0.151.1pypypi✓ verified 22d ago

ZeroConf is a pure Python implementation of multicast DNS service discovery (mDNS/DNS-SD), commonly known as Bonjour or Apple's Zero Configuration Networking. It allows applications to discover services on a local network without manual configuration. The library is currently at version 0.148.0 and maintains an active release cadence with frequent bug fixes and feature updates.

pip install zeroconf
INSTALL
IMPORT
SIG · ZEROCONF
Z
zeroconf
http-networkingpythonv0.151.1
Install
2.4s avg
Import
274ms
Disk
21MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.151.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.276s · 22.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.4s · import 0.272s · 23MB
21MB installed
● package 21MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Zeroconf
from zeroconf import Zeroconf
ServiceInfo
from zeroconf import ServiceInfo
ServiceBrowser
from zeroconf import ServiceBrowser
ServiceStateChange
from zeroconf import ServiceStateChange
Useful for defining a listener for service discovery events.

This quickstart demonstrates how to register a local HTTP service and simultaneously browse for all HTTP services on the network. It registers 'MyTestService' on port 8080 and then listens for 30 seconds, printing any discovered or removed services. Remember to handle `KeyboardInterrupt` and ensure `Zeroconf` instances are properly closed to release network resources.

import socket import time from zeroconf import ServiceInfo, Zeroconf, ServiceBrowser # A simple listener for discovering services class MyListener: def add_service(self, zeroconf_instance, service_type, service_name): info = zeroconf_instance.get_service_info(service_type, service_name) if info: print(f"Service added: {service_name} at {info.server}, Port: {info.port}, Addr: {socket.inet_ntoa(info.addresses[0]) if info.addresses else 'N/A'}") def remove_service(self, zeroconf_instance, service_type, service_name): print(f"Service removed: {service_name}") # --- Example Usage --- zeroconf = None browser = None info = None try: # 1. Register a service desc = {'path': '/~example'} ip_address = socket.gethostbyname(socket.gethostname()) # Or specify an explicit IP like "127.0.0.1" info = ServiceInfo( "_http._tcp.local.", # Service type "MyTestService._http._tcp.local.", # Service name addresses=[socket.inet_aton(ip_address)], port=8080, properties=desc, server="example.local.", # The server's hostname ) zeroconf = Zeroconf() print(f"Registering service: {info.name} on {ip_address}:{info.port}") zeroconf.register_service(info) # 2. Browse for services (will also find our own registered service) print("Starting service browser for _http._tcp.local.") browser = ServiceBrowser(zeroconf, "_http._tcp.local.", listener=MyListener()) print("Running for 30 seconds to allow discovery and registration. Press Ctrl+C to stop.") time.sleep(30) # Keep running except KeyboardInterrupt: print("Keyboard interrupt received. Shutting down.") finally: if zeroconf: print("Unregistering service and closing Zeroconf...") if info: zeroconf.unregister_service(info) zeroconf.close() print("Cleanup complete.")
Debug
Known issues
breakingThe 1.0.0 release was unintentionally published due to an issue with `python-semantic-release` and was subsequently YANKED. It contained no breaking changes, but users should avoid attempting to install this specific version and instead rely on the latest 0.x.x releases.
fix
Ensure your `pip install` command does not explicitly target `zeroconf==1.0.0`. Stick to `zeroconf` or `zeroconf~=0.x.x`.
affects: 1.0.0
gotchaIt is crucial to explicitly call the `close()` method on your `Zeroconf` instance(s) when you are done with them. Failing to do so will leave sockets open and consume resources, potentially leading to 'address already in use' errors or resource leaks.
fix
Always wrap your `Zeroconf` usage in a `try...finally` block to ensure `zeroconf.close()` is called, as shown in the quickstart example. Consider using `asyncio` for long-running applications or running `Zeroconf` in a dedicated thread.
affects: All versions
gotchaOn systems with multiple network interfaces, `zeroconf` might not bind to the desired interface by default. If your service isn't discoverable or you're not seeing other services, explicitly specify the network interfaces to use during `Zeroconf` initialization.
fix
Pass a list of interface IPs (e.g., `interfaces=['192.168.1.2', '10.0.0.5']`) to the `Zeroconf` constructor: `zeroconf = Zeroconf(interfaces=my_interfaces)`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'zeroconf'
The 'zeroconf' package is not installed in the current Python environment.
fix
pip install zeroconf
OSError: [Errno 98] Address already in use
The multicast DNS port (5353) or another necessary socket is already in use by another process, or a previous Zeroconf instance was not properly closed.
fix
Ensure `zeroconf_instance.close()` is called when the Zeroconf instance is no longer needed, typically in a `try...finally` block, or by using it as a context manager (e.g., `with Zeroconf(...) as zc:`).
AttributeError: 'Zeroconf' object has no attribute 'get_service_info'
The `get_service_info` method requires a service type and name and is primarily intended to be called within a `ServiceBrowser` listener's `add_service` callback after a service has been discovered.
fix
class MyListener:
    def add_service(self, zeroconf_instance, service_type, service_name):
        info = zeroconf_instance.get_service_info(service_type, service_name)
        if info:
            print(f'Service found: {info.name}')

# Correct usage:
# zeroconf_instance = zeroconf.Zeroconf()
# browser = zeroconf.ServiceBrowser(zeroconf_instance, "_http._tcp.local.", MyListener())
# ...
# zeroconf_instance.close()
ValueError: Interface 'eth0' not found
The network interface specified using the `interfaces` parameter during `Zeroconf` initialization does not exist on the system or is misspelled.
fix
# Check available interfaces (e.g., using 'ip a' on Linux, 'ipconfig' on Windows, 'ifconfig' on macOS).
# Use a valid interface name, or omit the 'interfaces' argument to bind to all available interfaces.
import zeroconf

# Example with a valid interface (replace 'en0' with your actual interface):
# from ipaddress import ip_address
# zc = zeroconf.Zeroconf(interfaces=[ip_address("192.168.1.10")]) 

# Or, to bind to all interfaces (most common):
zc = zeroconf.Zeroconf()
Upgrade
Version history
0.151.1latest on PyPI · released Aug 28, 2026
Audit
Dependencies
ifaddrrequiredRequired for detecting network interfaces.
Agent activity
64 hits · last 30 days
node
54
OpenAI (training)
1
Resources
zeroconf — pip install zeroconf · libregistry