=====================
Python Ring Door Bell
=====================
.. image:: https://badge.fury.io/py/ring-doorbell.svg
:alt: PyPI Version
:target: https://badge.fury.io/py/ring-doorbell
.. image:: https://github.com/python-ring-doorbell/python-ring-doorbell/actions/workflows/ci.yml/badge.svg?branch=master
:alt: Build Status
:target: https://github.com/python-ring-doorbell/python-ring-doorbell/actions/workflows/ci.yml?branch=master
.. image:: https://coveralls.io/repos/github/python-ring-doorbell/python-ring-doorbell/badge.svg?branch=master
:alt: Coverage
:target: https://coveralls.io/github/python-ring-doorbell/python-ring-doorbell?branch=master
.. image:: https://readthedocs.org/projects/python-ring-doorbell/badge/?version=latest
:alt: Documentation Status
:target: https://python-ring-doorbell.readthedocs.io/?badge=latest
.. image:: https://img.shields.io/pypi/pyversions/ring-doorbell.svg
:alt: Py Versions
:target: https://pypi.python.org/pypi/ring-doorbell
Python Ring Door Bell is a library written for Python that exposes the Ring.com devices as Python objects.
There is also a command line interface that is work in progress. `Contributors welcome <https://python-ring-doorbell.readthedocs.io/latest/contributing.html>`_.
*Currently Ring.com does not provide an official API. The results of this project are merely from reverse engineering.*
Documentation: `http://python-ring-doorbell.readthedocs.io/ <http://python-ring-doorbell.readthedocs.io/>`_
Installation
------------
.. code-block:: bash
# Installing from PyPi
$ pip install ring_doorbell
# Installing latest development
$ pip install \
git+https://github.com/python-ring-doorbell/python-ring-doorbell@master
Using the CLI
-------------
The CLI is work in progress and currently has the following commands:
1. Show your devices::
$ ring-doorbell
Or::
$ ring-doorbell show
#. List your device names (with device kind)::
$ ring-doorbell list
#. Either count or download your vidoes or both::
$ ring-doorbell videos --count --download-all
#. Enable disable motion detection::
$ ring-doorbell motion-detection --device-name "DEVICENAME" --on
$ ring-doorbell motion-detection --device-name "DEVICENAME" --off
#. Listen for push notifications like the ones sent to your phone::
$ ring-doorbell listen
#. List your ring groups::
$ ring-doorbell groups
#. Show your ding history::
$ ring-doorbell history --device-name "Front Door"
#. Show your currently active dings::
$ ring-doorbell dings
#. See or manage your doorbell in-home chime settings::
$ ring-doorbell in-home-chime --device-name "Front Door"
$ ring-doorbell in-home-chime --device-name "Front Door" type Mechanical
$ ring-doorbell in-home-chime --device-name "Front Door" enabled True
$ ring-doorbell in-home-chime --device-name "Front Door" duration 5
#. Query a ring api url directly::
$ ring-doorbell raw-query --url /clients_api/dings/active
#. Run ``ring-doorbell --help`` or ``ring-doorbell <command> --help`` for full options
Using the API
-------------
The API has an async interface and a sync interface. All api calls starting `async` are
asynchronous. This is the preferred method of interacting with the ring api and the sync
versions are maintained for backwards compatability.
*You cannot call sync api functions from inside a running event loop.*
Initializing your Ring object
+++++++++++++++++++++++++++++
This code example is in the `test.py <https://github.com/python-ring-doorbell/python-ring-doorbell/blob/master/test.py>`_ file.
For the deprecated sync example see `test_sync.py <https://github.com/python-ring-doorbell/python-ring-doorbell/blob/master/test_sync.py>`_.
.. code-block:: python
import getpass
import asyncio
import json
from pathlib import Path
from ring_doorbell import Auth, AuthenticationError, Requires2FAError, Ring
user_agent = "YourProjectName-1.0" # Change this
cache_file = Path(user_agent + ".token.cache")
def token_updated(token):
cache_file.write_text(json.dumps(token))
def otp_callback():
auth_code = input("2FA code: ")
return auth_code
async def do_auth():
username = input("Username: ")
password = getpass.getpass("Password: ")
auth = Auth(user_agent, None, token_updated)
try:
await auth.async_fetch_token(username, password)
except Requires2FAError:
await auth.async_fetch_token(username, password, otp_callback())
return auth
async def main():
if cache_file.is_file(): # auth token is cached
auth = Auth(user_agent, json.loads(cache_file.read_text()), token_updated)
ring = Ring(auth)
try:
await ring.async_create_session() # auth token still valid
except AuthenticationError: # auth token has expired
auth = await do_auth()
else:
auth = await do_auth() # Get new auth token
ring = Ring(auth)
await ring.async_update_data()
devices = ring.devices()
pprint(devices.devices_combined)
await auth.async_close()
if __name__ == "__main__":
asyncio.run(main())
Event Listener
++++++++++++++
.. code-block:: python
event_listener = RingEventListener(ring, credentials, credentials_updated_callback)
event_listener.add_notification_callback(_event_handler(ring).on_event)
await event_listener.start()
Listing devices linked to your account
++++++++++++++++++++++++++++++++++++++
.. code-block:: python
# All devices
devices = ring.devices()
{'chimes': [<RingChime: Downstairs>],
'doorbots': [<RingDoorBell: Front Door>]}
# All doorbells
doorbells = devices['doorbots']
[<RingDoorBell: Front Door>]
# All chimes
chimes = devices['chimes']
[<RingChime: Downstairs>]
# All stickup cams
stickup_cams = devices['stickup_cams']
[<RingStickUpCam: Driveway>]
Playing with the attributes and functions
+++++++++++++++++++++++++++++++++++++++++
.. code-block:: python
devices = ring.devices()
for dev in list(devices['stickup_cams'] + devices['chimes'] + devices['doorbots']):
await dev.async_update_health_data()
print('Address: %s' % dev.address)
print('Family: %s' % dev.family)
print('ID: %s' % dev.id)
print('Name: %s' % dev.name)
print('Timezone: %s' % dev.timezone)
print('Wifi Name: %s' % dev.wifi_name)
print('Wifi RSSI: %s' % dev.wifi_signal_strength)
# setting dev volume
print('Volume: %s' % dev.volume)
await dev.async_set_volume(5)
print('Volume: %s' % dev.volume)
# play dev test shound
if dev.family == 'chimes':
await dev.async_test_sound(kind = 'ding')
await dev.async_test_sound(kind = 'motion')
# turn on lights on floodlight cam
if dev.family == 'stickup_cams' and dev.lights:
await dev.async_lights('on')
Showing door bell events
++++++++++++++++++++++++
.. code-block:: python
devices = ring.devices()
for doorbell in devices['doorbots']:
# listing the last 15 events of any kind
for event in await doorbell.async_history(limit=15):
print('ID: %s' % event['id'])
print('Kind: %s' % event['kind'])
print('Answered: %s' % event['answered'])
print('When: %s' % event['created_at'])
print('--' * 50)
# get a event list only the triggered by motion
events = await doorbell.async_history(kind='motion')
Downloading the last video triggered by a ding or motion event
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.. code-block:: python
devices = ring.devices()
doorbell = devices['doorbots'][0]
await doorbell.async_recording_download(
await doorbell.async_history(limit=100, kind='ding')[0]['id'],
filename='last_ding.mp4',
override=True)
Displaying the last video capture URL
+++++++++++++++++++++++++++++++++++++
.. code-block:: python
print(await doorbell.async_recording_url(await doorbell.async_last_recording_id()))
'https://ring-transcoded-videos.s3.amazonaws.com/99999999.mp4?X-Amz-Expires=3600&X-Amz-Date=20170313T232537Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=TOKEN_SECRET/us-east-1/s3/aws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=secret'
Controlling a Light Group
+++++++++++++++++++++++++
.. code-block:: python
groups = ring.groups()
group = groups['the-group-you-want']
print(group.lights)
# Prints True if lights are on, False if off
# Turn on lights indefinitely
await group.async_set_lights(True)
# Turn off lights
await group.async_set_lights(False)
# Turn on lights for 30 seconds
await group.async_set_lights(True, 30)
How to contribute
-----------------
See our `Contributing Page <https://python-ring-doorbell.readthedocs.io/latest/contributing.html>`_.
Credits && Thanks
-----------------
* This project was inspired and based on https://github.com/jeroenmoors/php-ring-api. Many thanks @jeroenmoors.
* A guy named MadBagger at Prism19 for his initial research (http://www.prism19.com/doorbot/second-pass-and-comm-reversing/)
* The creators of mitmproxy (https://mitmproxy.org/) great http and https traffic inspector
* @mfussenegger for his post on mitmproxy and virtualbox https://zignar.net/2015/12/31/sniffing-vbox-traffic-mitmproxy/
* To the project http://www.android-x86.org/ which allowed me to install Android on KVM.
* Many thanks to Carles Pina I Estany <carles@pina.cat> for creating the python-ring-doorbell Debian Package (https://tracker.debian.org/pkg/python-ring-doorbell).
Raw data
{
"_id": null,
"home_page": null,
"name": "ring-doorbell",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9.0",
"maintainer_email": null,
"keywords": "camera, door bell, home automation, ring",
"author": "python-ring-doorbell developers",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/42/fb/bd2c1466525c0e67d5486be366065c2133925362351ac06ecd6e61ac330e/ring_doorbell-0.9.13.tar.gz",
"platform": null,
"description": "=====================\nPython Ring Door Bell\n=====================\n\n.. image:: https://badge.fury.io/py/ring-doorbell.svg\n :alt: PyPI Version\n :target: https://badge.fury.io/py/ring-doorbell\n\n.. image:: https://github.com/python-ring-doorbell/python-ring-doorbell/actions/workflows/ci.yml/badge.svg?branch=master\n :alt: Build Status\n :target: https://github.com/python-ring-doorbell/python-ring-doorbell/actions/workflows/ci.yml?branch=master\n\n.. image:: https://coveralls.io/repos/github/python-ring-doorbell/python-ring-doorbell/badge.svg?branch=master\n :alt: Coverage\n :target: https://coveralls.io/github/python-ring-doorbell/python-ring-doorbell?branch=master\n\n.. image:: https://readthedocs.org/projects/python-ring-doorbell/badge/?version=latest\n :alt: Documentation Status\n :target: https://python-ring-doorbell.readthedocs.io/?badge=latest\n\n.. image:: https://img.shields.io/pypi/pyversions/ring-doorbell.svg\n :alt: Py Versions\n :target: https://pypi.python.org/pypi/ring-doorbell\n\n\nPython Ring Door Bell is a library written for Python that exposes the Ring.com devices as Python objects.\n\nThere is also a command line interface that is work in progress. `Contributors welcome <https://python-ring-doorbell.readthedocs.io/latest/contributing.html>`_.\n\n*Currently Ring.com does not provide an official API. The results of this project are merely from reverse engineering.*\n\nDocumentation: `http://python-ring-doorbell.readthedocs.io/ <http://python-ring-doorbell.readthedocs.io/>`_\n\n\nInstallation\n------------\n\n.. code-block:: bash\n\n # Installing from PyPi\n $ pip install ring_doorbell\n\n # Installing latest development\n $ pip install \\\n git+https://github.com/python-ring-doorbell/python-ring-doorbell@master\n\n\nUsing the CLI\n-------------\n\nThe CLI is work in progress and currently has the following commands:\n\n1. Show your devices::\n\n $ ring-doorbell\n\n Or::\n\n $ ring-doorbell show\n\n#. List your device names (with device kind)::\n\n $ ring-doorbell list\n\n#. Either count or download your vidoes or both::\n\n $ ring-doorbell videos --count --download-all\n\n#. Enable disable motion detection::\n\n $ ring-doorbell motion-detection --device-name \"DEVICENAME\" --on\n $ ring-doorbell motion-detection --device-name \"DEVICENAME\" --off\n\n#. Listen for push notifications like the ones sent to your phone::\n\n $ ring-doorbell listen\n\n#. List your ring groups::\n\n $ ring-doorbell groups\n\n#. Show your ding history::\n\n $ ring-doorbell history --device-name \"Front Door\"\n\n#. Show your currently active dings::\n\n $ ring-doorbell dings\n\n#. See or manage your doorbell in-home chime settings::\n\n $ ring-doorbell in-home-chime --device-name \"Front Door\"\n $ ring-doorbell in-home-chime --device-name \"Front Door\" type Mechanical\n $ ring-doorbell in-home-chime --device-name \"Front Door\" enabled True\n $ ring-doorbell in-home-chime --device-name \"Front Door\" duration 5\n\n#. Query a ring api url directly::\n\n $ ring-doorbell raw-query --url /clients_api/dings/active\n\n#. Run ``ring-doorbell --help`` or ``ring-doorbell <command> --help`` for full options\n\nUsing the API\n-------------\n\nThe API has an async interface and a sync interface. All api calls starting `async` are\nasynchronous. This is the preferred method of interacting with the ring api and the sync\nversions are maintained for backwards compatability.\n\n*You cannot call sync api functions from inside a running event loop.*\n\nInitializing your Ring object\n+++++++++++++++++++++++++++++\n\nThis code example is in the `test.py <https://github.com/python-ring-doorbell/python-ring-doorbell/blob/master/test.py>`_ file.\nFor the deprecated sync example see `test_sync.py <https://github.com/python-ring-doorbell/python-ring-doorbell/blob/master/test_sync.py>`_.\n\n.. code-block:: python\n\n import getpass\n import asyncio\n import json\n from pathlib import Path\n\n from ring_doorbell import Auth, AuthenticationError, Requires2FAError, Ring\n\n user_agent = \"YourProjectName-1.0\" # Change this\n cache_file = Path(user_agent + \".token.cache\")\n\n\n def token_updated(token):\n cache_file.write_text(json.dumps(token))\n\n\n def otp_callback():\n auth_code = input(\"2FA code: \")\n return auth_code\n\n\n async def do_auth():\n username = input(\"Username: \")\n password = getpass.getpass(\"Password: \")\n auth = Auth(user_agent, None, token_updated)\n try:\n await auth.async_fetch_token(username, password)\n except Requires2FAError:\n await auth.async_fetch_token(username, password, otp_callback())\n return auth\n\n\n async def main():\n if cache_file.is_file(): # auth token is cached\n auth = Auth(user_agent, json.loads(cache_file.read_text()), token_updated)\n ring = Ring(auth)\n try:\n await ring.async_create_session() # auth token still valid\n except AuthenticationError: # auth token has expired\n auth = await do_auth()\n else:\n auth = await do_auth() # Get new auth token\n ring = Ring(auth)\n\n await ring.async_update_data()\n\n devices = ring.devices()\n pprint(devices.devices_combined)\n await auth.async_close()\n\n\n if __name__ == \"__main__\":\n asyncio.run(main())\n\nEvent Listener\n++++++++++++++\n\n.. code-block:: python\n\n event_listener = RingEventListener(ring, credentials, credentials_updated_callback)\n event_listener.add_notification_callback(_event_handler(ring).on_event)\n await event_listener.start()\n\nListing devices linked to your account\n++++++++++++++++++++++++++++++++++++++\n.. code-block:: python\n\n # All devices\n devices = ring.devices()\n {'chimes': [<RingChime: Downstairs>],\n 'doorbots': [<RingDoorBell: Front Door>]}\n\n # All doorbells\n doorbells = devices['doorbots']\n [<RingDoorBell: Front Door>]\n\n # All chimes\n chimes = devices['chimes']\n [<RingChime: Downstairs>]\n\n # All stickup cams\n stickup_cams = devices['stickup_cams']\n [<RingStickUpCam: Driveway>]\n\nPlaying with the attributes and functions\n+++++++++++++++++++++++++++++++++++++++++\n.. code-block:: python\n\n devices = ring.devices()\n for dev in list(devices['stickup_cams'] + devices['chimes'] + devices['doorbots']):\n await dev.async_update_health_data()\n print('Address: %s' % dev.address)\n print('Family: %s' % dev.family)\n print('ID: %s' % dev.id)\n print('Name: %s' % dev.name)\n print('Timezone: %s' % dev.timezone)\n print('Wifi Name: %s' % dev.wifi_name)\n print('Wifi RSSI: %s' % dev.wifi_signal_strength)\n\n # setting dev volume\n print('Volume: %s' % dev.volume)\n await dev.async_set_volume(5)\n print('Volume: %s' % dev.volume)\n\n # play dev test shound\n if dev.family == 'chimes':\n await dev.async_test_sound(kind = 'ding')\n await dev.async_test_sound(kind = 'motion')\n\n # turn on lights on floodlight cam\n if dev.family == 'stickup_cams' and dev.lights:\n await dev.async_lights('on')\n\n\nShowing door bell events\n++++++++++++++++++++++++\n.. code-block:: python\n\n devices = ring.devices()\n for doorbell in devices['doorbots']:\n\n # listing the last 15 events of any kind\n for event in await doorbell.async_history(limit=15):\n print('ID: %s' % event['id'])\n print('Kind: %s' % event['kind'])\n print('Answered: %s' % event['answered'])\n print('When: %s' % event['created_at'])\n print('--' * 50)\n\n # get a event list only the triggered by motion\n events = await doorbell.async_history(kind='motion')\n\n\nDownloading the last video triggered by a ding or motion event\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n.. code-block:: python\n\n devices = ring.devices()\n doorbell = devices['doorbots'][0]\n await doorbell.async_recording_download(\n await doorbell.async_history(limit=100, kind='ding')[0]['id'],\n filename='last_ding.mp4',\n override=True)\n\n\nDisplaying the last video capture URL\n+++++++++++++++++++++++++++++++++++++\n.. code-block:: python\n\n print(await doorbell.async_recording_url(await doorbell.async_last_recording_id()))\n 'https://ring-transcoded-videos.s3.amazonaws.com/99999999.mp4?X-Amz-Expires=3600&X-Amz-Date=20170313T232537Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=TOKEN_SECRET/us-east-1/s3/aws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=secret'\n\nControlling a Light Group\n+++++++++++++++++++++++++\n.. code-block:: python\n\n groups = ring.groups()\n group = groups['the-group-you-want']\n\n print(group.lights)\n # Prints True if lights are on, False if off\n\n # Turn on lights indefinitely\n await group.async_set_lights(True)\n\n # Turn off lights\n await group.async_set_lights(False)\n\n # Turn on lights for 30 seconds\n await group.async_set_lights(True, 30)\n\nHow to contribute\n-----------------\nSee our `Contributing Page <https://python-ring-doorbell.readthedocs.io/latest/contributing.html>`_.\n\n\nCredits && Thanks\n-----------------\n\n* This project was inspired and based on https://github.com/jeroenmoors/php-ring-api. Many thanks @jeroenmoors.\n* A guy named MadBagger at Prism19 for his initial research (http://www.prism19.com/doorbot/second-pass-and-comm-reversing/)\n* The creators of mitmproxy (https://mitmproxy.org/) great http and https traffic inspector\n* @mfussenegger for his post on mitmproxy and virtualbox https://zignar.net/2015/12/31/sniffing-vbox-traffic-mitmproxy/\n* To the project http://www.android-x86.org/ which allowed me to install Android on KVM.\n* Many thanks to Carles Pina I Estany <carles@pina.cat> for creating the python-ring-doorbell Debian Package (https://tracker.debian.org/pkg/python-ring-doorbell).\n",
"bugtrack_url": null,
"license": "LGPL-3.0-or-later",
"summary": "A Python library to communicate with Ring Door Bell (https://ring.com/)",
"version": "0.9.13",
"project_urls": {
"Bug Tracker": "https://github.com/python-ring-doorbell/python-ring-doorbell/issues",
"documentation": "http://python-ring-doorbell.readthedocs.io/",
"homepage": "https://github.com/python-ring-doorbell/python-ring-doorbell",
"repository": "https://github.com/python-ring-doorbell/python-ring-doorbell"
},
"split_keywords": [
"camera",
" door bell",
" home automation",
" ring"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b069125824998fa56a81972ee26b3fc32675199143227f5e08da87b3823f651b",
"md5": "578d86a2768f237693dbbd0b625c8837",
"sha256": "efe57e94666b671ca5eb2f46eeb4c94dbdea229761fb257f0c8f95d90e778551"
},
"downloads": -1,
"filename": "ring_doorbell-0.9.13-py3-none-any.whl",
"has_sig": false,
"md5_digest": "578d86a2768f237693dbbd0b625c8837",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9.0",
"size": 49725,
"upload_time": "2024-11-26T14:09:29",
"upload_time_iso_8601": "2024-11-26T14:09:29.702968Z",
"url": "https://files.pythonhosted.org/packages/b0/69/125824998fa56a81972ee26b3fc32675199143227f5e08da87b3823f651b/ring_doorbell-0.9.13-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "42fbbd2c1466525c0e67d5486be366065c2133925362351ac06ecd6e61ac330e",
"md5": "05d3a82a8b9525abb5045c88e42783af",
"sha256": "33c9473831dd5972efac36d031e12019a40c6025e27074d0b5af978c9c524253"
},
"downloads": -1,
"filename": "ring_doorbell-0.9.13.tar.gz",
"has_sig": false,
"md5_digest": "05d3a82a8b9525abb5045c88e42783af",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9.0",
"size": 67477,
"upload_time": "2024-11-26T14:09:31",
"upload_time_iso_8601": "2024-11-26T14:09:31.336179Z",
"url": "https://files.pythonhosted.org/packages/42/fb/bd2c1466525c0e67d5486be366065c2133925362351ac06ecd6e61ac330e/ring_doorbell-0.9.13.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-26 14:09:31",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "python-ring-doorbell",
"github_project": "python-ring-doorbell",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "ring-doorbell"
}