Skip to main content

Async UPnP Client

Project description

Asyncio UPnP Client library for Python/asyncio.

Written initially for use in Home Assistant to drive DLNA DMR-capable devices, but useful for other projects as well.

Status

https://img.shields.io/travis/StevenLooman/async_upnp_client.svg https://img.shields.io/pypi/v/async_upnp_client.svg https://img.shields.io/pypi/format/async_upnp_client.svg https://img.shields.io/pypi/pyversions/async_upnp_client.svg https://img.shields.io/pypi/l/async_upnp_client.svg

Contributing

See CONTRIBUTING.rst.

Usage

See examples/ for examples on how to use async_upnp_client.

upnp-client

A command line interface is provided via the upnp-client script. This script can be used to:

  • call an action

  • subscribe to services and listen for events

  • show UPnP traffic (–debug-traffic) from and to the device

  • show pretty printed JSON (–pprint) for human readability

  • search for devices

  • listen for advertisements

The output of the script is a single line of JSON for each action-call or subscription-event. See the programs help for more information.

An example of calling an action:

$ upnp-client --pprint call-action http://192.168.178.10:49152/description.xml RC/GetVolume InstanceID=0 Channel=Master
{
    "timestamp": 1531482271.5603056,
    "service_id": "urn:upnp-org:serviceId:RenderingControl",
    "service_type": "urn:schemas-upnp-org:service:RenderingControl:1",
    "action": "GetVolume",
    "in_parameters": {
        "InstanceID": 0,
        "Channel": "Master"
    },
    "out_parameters": {
        "CurrentVolume": 70
    }
}

An example of subscribing to all services, note that the program stays running until you stop it (ctrl-c):

$ upnp-client --pprint subscribe http://192.168.178.10:49152/description.xml \*
{
    "timestamp": 1531482518.3663802,
    "service_id": "urn:upnp-org:serviceId:RenderingControl",
    "service_type": "urn:schemas-upnp-org:service:RenderingControl:1",
    "state_variables": {
        "LastChange": "<Event xmlns=\"urn:schemas-upnp-org:metadata-1-0/AVT_RCS\">\n<InstanceID val=\"0\">\n<Mute channel=\"Master\" val=\"0\"/>\n<Volume channel=\"Master\" val=\"70\"/>\n</InstanceID>\n</Event>\n"
    }
}
{
    "timestamp": 1531482518.366804,
    "service_id": "urn:upnp-org:serviceId:RenderingControl",
    "service_type": "urn:schemas-upnp-org:service:RenderingControl:1",
    "state_variables": {
        "Mute": false,
        "Volume": 70
    }
}
...

You can subscribe to list of services by providing these names or abbreviated names, such as:

$ upnp-client --pprint subscribe http://192.168.178.10:49152/description.xml RC AVTransport

An example of searching for devices:

$ upnp-client --pprint search
{
    "cache-control": "max-age=3600",
    "date": "Sat, 27 Oct 2018 10:43:42 GMT",
    "ext": "",
    "location": "http://192.168.178.1:49152/description.xml",
    "opt": "\"http://schemas.upnp.org/upnp/1/0/\"; ns=01",
    "01-nls": "906ad736-cfc4-11e8-9c22-8bb67c653324",
    "server": "Linux/4.14.26+, UPnP/1.0, Portable SDK for UPnP devices/1.6.20.jfd5",
    "x-user-agent": "redsonic",
    "st": "upnp:rootdevice",
    "usn": "uuid:e3a17dd5-9d85-3131-3c34-b827eb498d72::upnp:rootdevice",
    "_timestamp": "2018-10-27 12:43:09.125408"
}

An example of listening for advertisements:

$ upnp-client --print advertisements
{
    "Host": "239.255.255.250:1900",
    "Cache-Control": "max-age=30",
    "Location": "http://192.168.178.1:1900/WFADevice.xml",
    "NTS": "ssdp:alive",
    "Server": "POSIX, UPnP/1.0 UPnP Stack/2013.4.3.0",
    "NT": "urn:schemas-wifialliance-org:device:WFADevice:1",
    "USN": "uuid:99cb221c-1f15-c620-dc29-395f415623c6::urn:schemas-wifialliance-org:device:WFADevice:1",
    "_timestamp": "2018-12-23 11:22:47.154293",
    "_address": "('192.168.178.1', 1900)",
    "_udn": "uuid:99cb221c-1f15-c620-dc29-395f415623c6",
    "_source": "advertisement"
}

Abstractions

  • DLNA Digital Media Renderer (DLNA DMR) devices - Primarily built for use with Home Assistant, but might be useful in other projects too.

  • Internet Gateway Devices (IGD)

  • Printers

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

async_upnp_client-0.14.1.tar.gz (32.0 kB view details)

Uploaded Source

Built Distribution

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

async_upnp_client-0.14.1-py3-none-any.whl (40.9 kB view details)

Uploaded Python 3

File details

Details for the file async_upnp_client-0.14.1.tar.gz.

File metadata

  • Download URL: async_upnp_client-0.14.1.tar.gz
  • Upload date:
  • Size: 32.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.19.8 CPython/3.6.3

File hashes

Hashes for async_upnp_client-0.14.1.tar.gz
Algorithm Hash digest
SHA256 6a3cc4dcec93e5481af3f403553e7b8688cf2101d48c962ecd76d3d2efe91509
MD5 070d08ba6f5e5a364a1a79f4ece44587
BLAKE2b-256 2c34e52a5c7ba118100f96382a20f181f26714545f7614d18cbbb064296e4ff5

See more details on using hashes here.

File details

Details for the file async_upnp_client-0.14.1-py3-none-any.whl.

File metadata

  • Download URL: async_upnp_client-0.14.1-py3-none-any.whl
  • Upload date:
  • Size: 40.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.19.8 CPython/3.6.3

File hashes

Hashes for async_upnp_client-0.14.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cfc812734cd25dab0c2d12973763279a4c087302fff5dc9f78b2d7b9498bd66f
MD5 27dcecc323dcc0509c87c3556be80522
BLAKE2b-256 c78f3383566eca67b3f2a8892126348773ffd4537af336fc8f2557d26aa5948f

See more details on using hashes here.

Supported by

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