PyTapo: Tapo Camera Communication Library
PyTapo is an unofficial Python library designed for communication with Tapo Cameras. It facilitates interoperability by wrapping HTTP requests used to control and retrieve data from Tapo devices. The library is actively maintained, currently at version 3.4.13, and receives regular updates focused on bug fixes, performance enhancements, and support for new camera features such as dual-cam linkage.
Common errors
-
Exception: Invalid authentication data
cause The username or password provided to the `Tapo` class constructor is incorrect, or you are attempting to use TP-Link cloud credentials instead of the local 'Camera Account' credentials.fixVerify the host IP, username, and password. Create or use the 'Camera Account' credentials from the Tapo App (Settings > Advanced settings > Camera account). These are distinct from your TP-Link cloud account. -
PyTapo KLAP Error #3: ('Device connection error: XXX.XXX.XXX.XXX: Server disconnected', ServerDisconnectedError('Server disconnected'))cause A connection issue specific to KLAP-protocol cameras, often occurring when the camera's local authentication service isn't fully active, or the camera hasn't completed initial setup via the official Tapo app.fixComplete the camera's setup process through the official Tapo mobile application. Ensure the 'Camera Account' is enabled and configured correctly. Verify network connectivity and that the camera IP is reachable. -
DependencyError: Could not setup dependencies: Incorrect pytapo version installed: X.X.X. Required: Y.Y.Y.
cause An integration (e.g., Home Assistant) explicitly requires a different or newer version of `pytapo` than what is currently installed in your environment.fixUpgrade `pytapo` to the exact required version (Y.Y.Y) or the latest version if the integration allows. Use `pip install --upgrade pytapo` or `pip install pytapo==Y.Y.Y`. -
Error code -71112 when browsing media
cause An internal error code indicating a failure when trying to retrieve or browse media from the camera.fixUpdate `pytapo` to version 3.4.9 or later, as this specific issue was addressed in that release.
Warnings
- gotcha Authentication often fails due to incorrect credentials. Users frequently attempt to use their TP-Link cloud account password or an 'admin' username not configured as a local camera account.
- gotcha Downloading recordings requires `ffmpeg` to be installed and available in your system's PATH, as `pytapo` uses it for stream conversion.
- breaking New Tapo camera firmware versions can introduce changes that break compatibility with `pytapo` functions, requiring updates to the library or dependent integrations.
- gotcha Users of `urllib3` versions 2.0 or higher might encounter `SSLV3_ALERT_HANDSHAKE_FAILURE` errors due to underlying changes in SSL/TLS handling.
- gotcha KLAP camera models (e.g., C206, C212) can exhibit 'Server disconnected' errors, particularly if the camera hasn't been fully initialized through the official app or if the local authentication service isn't active.
Install
-
pip install pytapo
Imports
- Tapo
from pytapo import Tapo
Quickstart
import os
from pytapo import Tapo
# It's recommended to store sensitive information in environment variables.
host = os.environ.get('TAPO_CAMERA_HOST', '192.168.1.100') # Replace with your camera's IP
user = os.environ.get('TAPO_CAMERA_USER', 'camera_username') # Camera Account username from Tapo App
password = os.environ.get('TAPO_CAMERA_PASSWORD', 'camera_password') # Camera Account password from Tapo App
try:
tapo = Tapo(host, user, password)
basic_info = tapo.getBasicInfo()
print(f"Successfully connected to Tapo camera {host}.")
print(f"Device Name: {basic_info['device_name']}")
print(f"Device ID: {basic_info['device_id']}")
except Exception as e:
print(f"Failed to connect to Tapo camera: {e}")
print("Please ensure the host, username, and password are correct.")
print("For authentication, use the 'Camera Account' created in the Tapo App (Settings > Advanced settings > Camera account).")