Skip to main content

A Blink camera Python Library.

Project description

blinkpy Build Status Coverage Status PyPi Version Codestyle

A Python library for the Blink Camera system (Python 3.9+)

Like the library? Consider buying me a cup of coffee!

Buy me a Coffee!

Disclaimer: Published under the MIT license - See LICENSE file for more details.

“Blink Wire-Free HS Home Monitoring & Alert Systems” is a trademark owned by Immedia Inc., see www.blinkforhome.com for more information. I am in no way affiliated with Blink, nor Immedia Inc.

Original protocol hacking by MattTW : https://github.com/MattTW/BlinkMonitorProtocol

API calls faster than 60 seconds is not recommended as it can overwhelm Blink’s servers. Please use this module responsibly.

Installation

pip install blinkpy

Installing Development Version

To install the current development version, perform the following steps. Note that the following will create a blinkpy directory in your home area:

$ cd ~
$ git clone https://github.com/fronzbot/blinkpy.git
$ cd blinkpy
$ pip install .

If you’d like to contribute to this library, please read the contributing instructions.

Purpose

This library was built with the intention of allowing easy communication with Blink camera systems, specifically to support the Blink component in homeassistant.

Quick Start

The simplest way to use this package from a terminal is to call await Blink.start() which will prompt for your Blink username and password and then log you in. In addition, http requests are throttled internally via use of the Blink.refresh_rate variable, which can be set at initialization and defaults to 30 seconds.

import asyncio
from aiohttp import ClientSession
from blinkpy.blinkpy import Blink

async def start():
    blink = Blink(session=ClientSession())
    try:
        await blink.start()
    except BlinkTwoFARequiredError:
        await blink.prompt_2fa()
    return blink

blink = asyncio.run(start())

This flow will prompt you for your username and password. Once entered, if you likely will need to send a 2FA key to the blink servers (this pin is sent to your email address). When you receive this pin, enter at the prompt and the Blink library will proceed with setup.

Supplying credentials from file

Other use cases may involved loading credentials from a file. This file must be json formatted and contain a minimum of username and password. A built in function in the blinkpy.helpers.util module can aid in loading this file. Note, if no_prompt is desired, a similar flow can be followed as above.

import asyncio
from aiohttp import ClientSession
from blinkpy.blinkpy import Blink
from blinkpy.auth import Auth
from blinkpy.helpers.util import json_load

async def start():
    blink = Blink()
    auth = Auth(await json_load("<File Location>"))
    blink.auth = auth
    try:
        await blink.start()
    except BlinkTwoFARequiredError:
        await blink.prompt_2fa()
    return blink

blink = asyncio.run(start())

Saving credentials

This library also allows you to save your credentials to use in future sessions. Saved information includes authentication tokens as well as unique ids which should allow for a more streamlined experience and limits the frequency of login requests. This data can be saved as follows (it can then be loaded by following the instructions above for supplying credentials from a file):

await blink.save("<File location>")

Getting cameras

Cameras are instantiated as individual BlinkCamera classes within a BlinkSyncModule instance. All of your sync modules are stored within the Blink.sync dictionary and can be accessed using the name of the sync module as the key (this is the name of your sync module in the Blink App).

The below code will display cameras and their available attributes:

for name, camera in blink.cameras.items():
  print(name)                   # Name of the camera
  print(camera.attributes)      # Print available attributes of camera

The most recent images and videos can be accessed as a bytes-object via internal variables. These can be updated with calls to Blink.refresh() but will only make a request if motion has been detected or other changes have been found. This can be overridden with the force flag, but this should be used for debugging only since it overrides the internal request throttling.

camera = blink.cameras['SOME CAMERA NAME']
await blink.refresh(force=True)  # force a cache update USE WITH CAUTION
camera.image_from_cache  # bytes-like image object (jpg)
camera.video_from_cache  # bytes-like video object (mp4)

The blinkpy api also allows for saving images and videos to a file and snapping a new picture from the camera remotely:

camera = blink.cameras['SOME CAMERA NAME']
await camera.snap_picture()       # Take a new picture with the camera
await blink.refresh()             # Get new information from server
await camera.image_to_file('/local/path/for/image.jpg')
await camera.video_to_file('/local/path/for/video.mp4')

Download videos

You can also use this library to download all videos from the server. In order to do this, you must specify a path. You may also specify a how far back in time to go to retrieve videos via the since= variable (a simple string such as "2017/09/21" is sufficient), as well as how many pages to traverse via the stop= variable. Note that by default, the library will search the first ten pages which is sufficient in most use cases. Additionally, you can specify one or more cameras via the camera= property. This can be a single string indicating the name of the camera, or a list of camera names. By default, it is set to the string 'all' to grab videos from all cameras. If you are downloading many items, setting the delay parameter is advised in order to throttle sequential calls to the API. By default this is set to 1 but can be any integer representing the number of seconds to delay between calls.

Example usage, which downloads all videos recorded since July 4th, 2018 at 9:34am to the /home/blink directory with a 2s delay between calls:

await blink.download_videos('/home/blink', since='2018/07/04 09:34', delay=2)

Sync Module Local Storage

API steps

  1. Request the local storage manifest be created by the sync module.

    • POST {base_url}/api/v1/accounts/{account_id}/networks/{network_id}/sync_modules/{sync_id}/local_storage/manifest/request

    • Returns an ID that is used to get the manifest.

  2. Retrieve the local storage manifest.

    • GET {base_url}/api/v1/accounts/{account_id}/networks/{network_id}/sync_modules/{sync_id}/local_storage/manifest/request/{manifest_request_id}

    • Returns full manifest.

    • Extract the manifest ID from the response.

  3. Find a clip ID in the clips list from the manifest to retrieve, and request an upload.

    • POST {base_url}/api/v1/accounts/{account_id}/networks/{network_id}/sync_modules/{sync_id}/local_storage/manifest/{manifest_id}/clip/request/{clip_id}

    • When the response is returned, the upload has finished.

  4. Download the clip using the same clip ID.

    • GET {base_url}/api/v1/accounts/{account_id}/networks/{network_id}/sync_modules/{sync_id}/local_storage/manifest/{manifest_id}/clip/request/{clip_id}

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

blinkpy-0.25.5.tar.gz (67.5 kB view details)

Uploaded Source

Built Distribution

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

blinkpy-0.25.5-py3-none-any.whl (39.9 kB view details)

Uploaded Python 3

File details

Details for the file blinkpy-0.25.5.tar.gz.

File metadata

  • Download URL: blinkpy-0.25.5.tar.gz
  • Upload date:
  • Size: 67.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for blinkpy-0.25.5.tar.gz
Algorithm Hash digest
SHA256 43a83b5d52d7b803eb56e2a3c8c7d739b64d9e5ec9ffc2f45e420f61af33f1f3
MD5 5a9806feac123474a5687d5c9fab17d9
BLAKE2b-256 7208278b9d9d2d53b0369553a37845ab8ab8720c891ca9f1a3663411888d323a

See more details on using hashes here.

File details

Details for the file blinkpy-0.25.5-py3-none-any.whl.

File metadata

  • Download URL: blinkpy-0.25.5-py3-none-any.whl
  • Upload date:
  • Size: 39.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for blinkpy-0.25.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d3198d61536d276d66663b5347ecf4d68536271af4a56aca024f116206fe4598
MD5 fca48e07c7755a9d5627b92d1d459c0a
BLAKE2b-256 24b67b1758594173ab74e0a95299c8b0e94e3004a92ca901ac5d2cd7d3ec5f1f

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