Skip to main content

pychromecast Build Status

Library for Python 2 and 3 to communicate with the Google Chromecast. It currently supports:

  • Auto discovering connected Chromecasts on the network

  • Start the default media receiver and play any online media

  • Control playback of current playing media

  • Implement Google Chromecast api v2

  • Communicate with apps via channels

  • Easily extendable to add support for unsupported namespaces

  • Multi-room setups with Audio cast devices

PyChromecast 0.6 introduces some backward incompatible changes due to the migration from DIAL to socket for retrieving the app status.

Dependencies

PyChromecast depends on the Python packages requests, protobuf and zeroconf. Make sure you have these dependencies installed using pip install -r requirements.txt

Some users running Python 2.7 have reported that they had to upgrade their version of pip using pip install --upgrade pip before they were able to install the latest version of the dependencies.

How to use

>> from __future__ import print_function
>> import time
>> import pychromecast

>> pychromecast.get_chromecasts_as_dict().keys()
['Dev', 'Living Room', 'Den', 'Bedroom']

>> cast = pychromecast.get_chromecast(friendly_name="Living Room")
>> # Wait for cast device to be ready
>> cast.wait()
>> print(cast.device)
DeviceStatus(friendly_name='Living Room', model_name='Chromecast', manufacturer='Google Inc.', api_version=(1, 0), uuid=UUID('df6944da-f016-4cb8-97d0-3da2ccaa380b'), cast_type='cast')

>> print(cast.status)
CastStatus(is_active_input=True, is_stand_by=False, volume_level=1.0, volume_muted=False, app_id=u'CC1AD845', display_name=u'Default Media Receiver', namespaces=[u'urn:x-cast:com.google.cast.player.message', u'urn:x-cast:com.google.cast.media'], session_id=u'CCA39713-9A4F-34A6-A8BF-5D97BE7ECA5C', transport_id=u'web-9', status_text='')

>> mc = cast.media_controller
>> mc.play_media('http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4', 'video/mp4')
>> print(mc.status)
MediaStatus(current_time=42.458322, content_id=u'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4', content_type=u'video/mp4', duration=596.474195, stream_type=u'BUFFERED', idle_reason=None, media_session_id=1, playback_rate=1, player_state=u'PLAYING', supported_media_commands=15, volume_level=1, volume_muted=False)

>> mc.pause()
>> time.sleep(5)
>> mc.play()

Adding support for extra namespaces

Each app that runs on the Chromecast supports namespaces. They specify a JSON-based mini-protocol. This is used to communicate between the Chromecast and your phone/browser and now Python.

Support for extra namespaces is added by using controllers. To add your own namespace to a current chromecast instance you will first have to define your controller. Example of a minimal controller:

from pychromecast.controllers import BaseController

class MyController(BaseController):
    def __init__(self):
        super(MyController, self).__init__(
            "urn:x-cast:my.super.awesome.namespace")

    def receive_message(self, message, data):
        print("Wow, I received this message: {}".format(data))

        return True  # indicate you handled this message

    def request_beer(self):
        self.send_message({'request': 'beer'})

After you have defined your controller you will have to add an instance to a Chromecast object: cast.register_handler(MyController()). When a message is received with your namespace it will be routed to your controller.

For more options see the BaseController. For an example of a fully implemented controller see the MediaController.

Exploring existing namespaces

So you’ve got PyChromecast running and decided it is time to add support to your favorite app. No worries, the following instructions will have you covered in exploring the possibilities.

The following instructions require the use of the Google Chrome browser and the Google Cast plugin.

  • In Chrome, go to chrome://net-internals/#capture

  • Enable the checkbox ‘Include the actual bytes sent/received.’

  • Open a new tab, browse to your favorite application on the web that has Chromecast support and start casting.

  • Go back to the tab that is capturing events and click on stop.

  • From the dropdown click on events. This will show you a table with events that happened while you were recording.

  • In the filter box enter the text Tr@n$p0rt. This should give one SOCKET connection as result: the connection with your Chromecast.

  • Go through the results and collect the JSON that is exchanged.

  • Now write a controller that is able to mimic this behavior :-)

Ignoring CEC Data

The Chromecast typically reports whether it is the active input on the device to which it is connected. This value is stored inside a cast object in the following property.

cast.status.is_active_input

Some Chromecast users have reported CEC incompatibilities with their media center devices. These incompatibilities may sometimes cause this active input value to be reported improperly.

This active input value is typically used to determine if the Chromecast is idle. PyChromecast is capable of ignoring the active input value when determining if the Chromecast is idle in the instance that the Chromecast is returning erroneous values. To ignore this CEC detection data in PyChromecast, append a Linux style wildcard formatted string to the IGNORE_CEC list in PyChromecast like in the example below.

pychromecast.IGNORE_CEC.append('*')  # Ignore CEC on all devices
pychromecast.IGNORE_CEC.append('Living Room')  # Ignore CEC on Chromecasts named Living Room

Maintainers

Thanks

I would like to thank Fred Clift for laying the socket client ground work. Without him it would not have been possible!

Metadata

Release files for PyChromecast 0.7.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyChromecast 0.7.3
File Size Uploaded Provenance Actions
PyChromecast-0.7.3.tar.gz 35.0 kB Without provenance Details for PyChromecast-0.7.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for PyChromecast 0.7.3
File Interpreter ABI Platform Actions
PyChromecast-0.7.3-py2.py3-none-any.whl Python 2, Python 3 none any Details for PyChromecast-0.7.3-py2.py3-none-any.whl

Total release size: 81.7 kB

Release files / PyChromecast-0.7.3.tar.gz

Download URL PyChromecast-0.7.3.tar.gz
Size 35.0 kB
Tags Source
SHA-256 checksum
How to use checksums
14cdf8869b4d5275f06274163fcca2e3567681a495cdac381e0adad97df17aaf
BLAKE2b-256 checksum
How to use checksums
a54398b12aadd695e8a71883b4c1a2e14da4eb3b5bc0fb7e5a0a9de77085bba5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / PyChromecast-0.7.3-py2.py3-none-any.whl

Download URL PyChromecast-0.7.3-py2.py3-none-any.whl
Size 46.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
6427ca09df08f51d7a89b7942606a979c7a75ff0e9af6a530bc3ba3f0e5e999f
BLAKE2b-256 checksum
How to use checksums
ddf5df297e87884589901d0ddb0e5b161d47f72d26bf7f9e721625821973b22c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for PyChromecast 0.7.3

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.

Release history Release notifications | RSS feed

This release

0.7.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page