Skip to main content

PyTapo

Python library for communication with Tapo Cameras.

Used inside Home Assistant Integration HomeAssistant-Tapo-Control.

Pre-Requirements

  • Python3.13
  • PIP modules installed

Install:

python3 -m pip install pytapo

Usage examples:

Initiate library:

from pytapo import Tapo

user = "" # user you set in Advanced Settings -> Camera Account
password = "" # password you set in Advanced Settings -> Camera Account
host = "" # ip of the camera, example: 192.168.1.52

tapo = Tapo(host, user, password)

print(tapo.getBasicInfo())

Authentication

Depending on your camera model and firmware version, the authentication method varies.

Normally you should be able to authenticate using the "camera account" created via the Tapo App (Settings > Advanced settings > Camera account).

In case of a similar stack trace:

Traceback (most recent call last):
  File "/home/user/Projects/pytapo/pytapo/__init__.py", line 41, in __init__
    self.basicInfo = self.getBasicInfo()
  File "/home/user/Projects/pytapo/pytapo/__init__.py", line 232, in getBasicInfo
    return self.performRequest(
  File "/home/user/Projects/pytapo/pytapo/__init__.py", line 95, in performRequest
    self.ensureAuthenticated()
  File "/home/user/Projects/pytapo/pytapo/__init__.py", line 61, in ensureAuthenticated
    return self.refreshStok()
  File "/home/user/Projects/pytapo/pytapo/__init__.py", line 80, in refreshStok
    raise Exception("Invalid authentication data")
Exception: Invalid authentication data

Attempt to authenticate using admin as user and your TP-Link cloud account password as password.

Downloading Recordings

Integration supports downloading recordings saved on camera's SD card.

See example script. You need to call it with following ENV values:

  • HOST: IP Address of your camera
  • PASSWORD_CLOUD: Tapo cloud account password, it is required to access the recordings, everything is still local
  • OUTPUT: Directory where you wish to save all the recordings
  • DATE: Date for which to download recordings in format of YYYYMMDD, for example 20230221.

You also need to have ffmpeg installed as that is used for converting the streams to watchable file.

Performance notes

Recordings are downloaded through the camera's encrypted streaming protocol (/stream). The camera does not expose the raw MP4 files directly, so a true "file copy" is not possible; the stream is AES-decrypted and the resulting MPEG-TS data is remuxed into an MP4 container by ffmpeg (the video track is copied as-is, the audio track is re-encoded to AAC).

You can tune the download behavior with the following Downloader parameters:

  • window_size: Affects throughput and stability. Higher values usually download faster but can cause some cameras to stop responding. Common values are 50 (stable) or 200 (default).
  • progressInterval: Minimum time in seconds between progress updates (default 1.0). Increasing this value reduces CPU overhead because the library no longer runs an ffprobe subprocess on every chunk just to report progress. Use progressInterval=0 to restore the previous per-chunk behavior.
  • stall_timeout: Seconds to wait for data before treating the stream as stalled and retrying (default 120).

Contributions:

Contributions to pytapo are welcomed.

By creating a PR you acknowledge and agree that you are not breaking any TOS, law and/or have a permission to provide and share the code changes.

Owner of this repository is not legally responsible for any PRs or code changes to this project created by 3rd parties.

When you make a new change to the code base, make sure to have 100% unit test coverage, see below for more information about tests.

Test instructions

Set the following environment variables:

PYTAPO_USER - user you set in Advanced Settings -> Camera Account

PYTAPO_PASSWORD - password you set in Advanced Settings -> Camera Account

PYTAPO_IP - ip of the camera, example: 192.168.1.52

Install pre-commit and tox from pip.

Run pre-commit install and pre-commit install -t pre-push.

Then run tox to run all the tests.

Linters are ran on every commit.

Tests are ran on push.

Your camera may do all the actions supported by this library, including, but not limited to, move, change privacy mode and reboot while tests are running. Camera does not format SD card during tests.

After the tests are done, your camera should be in the initial state.

Thank you

FAQ

See https://github.com/JurajNyiri/HomeAssistant-Tapo-Control?tab=readme-ov-file#troubleshooting--faq

Disclaimer

Pytapo is an unofficial module for achieving interoperability with Tapo cameras.

Author is in no way affiliated with Tp-Link or Tapo.

All the api requests used within the library are available and published on the internet (examples linked above) and this module is purely just a wrapper around those https requests.

Author does not guarantee functionality of this library and is not responsible for any damage.

All product names, trademarks and registered trademarks in this repository, are property of their respective owners.

Release files for pytapo 3.4.19

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

Source distribution (sdist)

Source distribution for pytapo 3.4.19
File Size Uploaded
pytapo-3.4.19.tar.gz 61.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytapo 3.4.19
File Interpreter ABI Platform
pytapo-3.4.19-py3-none-any.whl Python 3 none any Details

Total release size: 128.0 kB

Release files / pytapo-3.4.19.tar.gz

Download URL pytapo-3.4.19.tar.gz
Size 61.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8b017b7f9a70718141c3a98f430d9881121c125aab713329cc608d26cb6d258f
BLAKE2b-256 checksum
How to use checksums
fe94623e286f3cd675149b7698dbbb240cb2c3d559ec2e7d632b83d5f4d2a858
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.10.15

Release files / pytapo-3.4.19-py3-none-any.whl

Download URL pytapo-3.4.19-py3-none-any.whl
Size 66.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
08893230f34d2c394cd4cd71ad68331ce2a03db05b59f9d32f401fe4104b84ff
BLAKE2b-256 checksum
How to use checksums
229ceae35fdf4c84f92ab3ccfd0178272d60626210d4eba8705bc01f9cc8589c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.10.15

Release history Release notifications | RSS feed

This release

3.4.19 This release

2 release files

3.4.15

2 release files

3.4.14

2 release files

3.4.13

2 release files

3.4.11

2 release files

3.4.10

2 release files

3.4.9

2 release files

3.4.8

2 release files

3.4.7

2 release files

3.4.6

2 release files

3.4.5

2 release files

3.4.4

2 release files

3.4.3

2 release files

3.4.2

2 release files

3.4.1

2 release files

3.4.0

2 release files

3.3.56

2 release files

3.3.55

2 release files

3.3.54

2 release files

3.3.53

2 release files

3.3.52

2 release files

3.3.51

2 release files

3.3.50

2 release files

3.3.49

2 release files

3.3.48

2 release files

3.3.47

2 release files

3.3.44

2 release files

3.3.43

2 release files

3.3.38

2 release files

3.3.36

2 release files

3.3.35

2 release files

3.3.34

2 release files

3.3.33

2 release files

3.3.32

2 release files

3.3.30

2 release files

3.3.29

2 release files

3.3.28

2 release files

3.3.27

2 release files

3.3.26

2 release files

3.3.25

2 release files

3.3.24

2 release files

3.3.20

2 release files

3.3.19

2 release files

3.3.18

2 release files

3.3.17

2 release files

3.3.16

2 release files

3.3.15

2 release files

3.3.14

2 release files

3.3.13

2 release files

3.3.12

2 release files

3.3.11

2 release files

3.3.10

2 release files

3.3.9

2 release files

3.3.8

2 release files

3.3.7

2 release files

3.3.6

2 release files

3.3.5

2 release files

3.3.4

2 release files

3.3.3

2 release files

3.3.2

2 release files

3.3.1

2 release files

3.3.0

2 release files

3.2.14

2 release files

3.2.13

2 release files

3.2.12

2 release files

3.2.11

2 release files

3.2.10

2 release files

3.2.9

2 release files

3.2.8

2 release files

3.2.7

2 release files

3.2.6

2 release files

3.2.5

2 release files

3.2.4

2 release files

3.2.3

2 release files

3.2.2

2 release files

3.2.1

2 release files

3.2

2 release files

3.1.12

2 release files

3.1.11

2 release files

3.1.9

2 release files

3.1.8

2 release files

3.1.7

2 release files

3.1.6

2 release files

3.1.5

2 release files

3.1.4

2 release files

3.1.3

2 release files

3.1.2

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.9

2 release files

3.0.8

2 release files

3.0.7

2 release files

3.0.6

2 release files

3.0.5

2 release files

3.0.4

2 release files

3.0.3

2 release files

3.0.2

2 release files

3.0.1

2 release files

2.9.2

2 release files

2.9.1

2 release files

2.9

2 release files

2.8.3

2 release files

2.8.2

2 release files

2.8.1

2 release files

2.8

2 release files

2.7

2 release files

2.6

2 release files

2.5.1

2 release files

2.5

2 release files

2.4

2 release files

2.3

2 release files

2.2

2 release files

2.1

2 release files

2.0

2 release files

1.2.1

2 release files

1.2

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1

2 release files

1.0

2 release files

0.11

2 release files

0.10

2 release files

0.9

2 release files

0.8

2 release files

0.7

2 release files

0.6

2 release files

0.5

2 release files

0.4

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

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