python-zeroconf

This is fork of pyzeroconf, Multicast DNS Service Discovery for Python, originally by Paul Scott-Murphy (https://github.com/paulsm/pyzeroconf), modified by William McBrine (https://github.com/wmcbrine/pyzeroconf).

Compatible with:

  • Bonjour
  • Avahi

Compared to some other Zeroconf/Bonjour/Avahi Python packages, python-zeroconf:

  • isn't tied to Bonjour or Avahi
  • doesn't use D-Bus
  • doesn't force you to use particular event loop or Twisted
  • is pip-installable
  • has PyPI distribution

Python compatibility

  • CPython 3.6+
  • PyPy3 5.8+

Versioning

This project's versions follow the following pattern: MAJOR.MINOR.PATCH.

  • MAJOR version has been 0 so far
  • MINOR version is incremented on backward incompatible changes
  • PATCH version is incremented on backward compatible changes

Status

There are some people using this package. I don't actively use it and as such any help I can offer with regard to any issues is very limited.

IPv6 support

IPv6 support is relatively new and currently limited, specifically:

  • InterfaceChoice.All is an alias for InterfaceChoice.Default on non-POSIX systems.
  • On Windows specific interfaces can only be requested as interface indexes, not as IP addresses.
  • Dual-stack IPv6 sockets are used, which may not be supported everywhere (some BSD variants do not have them).
  • Listening on localhost (::1) does not work. Help with understanding why is appreciated.

How to get python-zeroconf?

The easiest way to install python-zeroconf is using pip:

pip install zeroconf

How do I use it?

Here's an example of browsing for a service:

from zeroconf import ServiceBrowser, Zeroconf


class MyListener:

    def remove_service(self, zeroconf, type, name):
        print("Service %s removed" % (name,))

    def add_service(self, zeroconf, type, name):
        info = zeroconf.get_service_info(type, name)
        print("Service %s added, service info: %s" % (name, info))


zeroconf = Zeroconf()
listener = MyListener()
browser = ServiceBrowser(zeroconf, "_http._tcp.local.", listener)
try:
    input("Press enter to exit...\n\n")
finally:
    zeroconf.close()

Note

Discovery and service registration use all available network interfaces by default. If you want to customize that you need to specify interfaces argument when constructing Zeroconf object (see the code for details).

If you don't know the name of the service you need to browse for, try:

from zeroconf import ZeroconfServiceTypes
print('\n'.join(ZeroconfServiceTypes.find()))

See examples directory for more.

GitHub

https://github.com/jstasiak/python-zeroconf