A Python library for the EZVIZ OpenAPI platform, handling authentication and API requests.
Project description
EZVIZ OpenAPI Utils
简体中文 | English
A Python library designed to simplify interactions with the EZVIZ OpenAPI platform. It handles authentication, automatic token refreshing, and provides a clean, unified interface for all API endpoints.
✨ Key Features
- Automatic Token Management: The client automatically handles Access Token expiration and renewal, requiring no manual intervention from the user.
- Multi-Region Support: Fully supports all 8 global regions (cn, en, eu, us, sa, sg, in, ru), ensuring compatibility worldwide.
- Type Safe: Uses
TypedDictfor API responses, providing excellent IDE support and code completion for developers. - Clean Architecture: Clearly separates concerns:
Clienthandles authentication, andEZVIZOpenAPIhandles API calls, resulting in a codebase that is easy to understand and maintain.
📦 Installation
Install the package:
pip install ezviz-openapi-utils
This will install the package along with its core dependency requests.
(Note: For development, clone the repository and use pip install -e .[dev] to include dev dependencies.)
🧪 Testing
Setup
Create a .env file in the repository root with your EZVIZ credentials:
EZVIZ_APP_KEY=your_app_key_here
EZVIZ_APP_SECRET=your_app_secret_here
Running Tests
# Run all tests
pytest
# Run specific test file
pytest tests/test_client.py
# Tests automatically skip integration tests if credentials are not configured
🚀 Getting Started
from ezviz_openapi_utils import Client, EZVIZOpenAPI
# 1. Create a client instance (automatically fetches the access token)
client = Client(
app_key="YOUR_APP_KEY",
app_secret="YOUR_APP_SECRET",
region="cn" # Specify your region
)
# 2. Create an API instance
api = EZVIZOpenAPI(client)
# Add a device
add_device_response = api.add_device(device_serial="427734888", validate_code="ABCDEF")
print(add_device_response)
# Output: {'code': '200', 'msg': 'Operation succeeded!'}
# Get device information
device_info_response = api.get_device_info(device_serial="427734888")
print(device_info_response)
# Output: {'data': {'deviceSerial': '427734888', 'deviceName': 'niuxiaoge device', 'model': 'CS-C1-11WPFR', 'status': 0, 'defence': 1, 'isEncrypt': 0}, 'code': '200', 'msg': 'Operating succeeded!'}
# Delete a device
delete_response = api.delete_device(device_serial="427734888")
print(delete_response)
# Output: {'code': '200', 'msg': 'Operation succeeded!'}
🛡️ Error Handling
The library provides custom exceptions for different error scenarios:
from ezviz_openapi_utils import Client, EZVIZOpenAPI
from ezviz_openapi_utils.exceptions import EZVIZAuthError, EZVIZAPIError
client = Client(app_key="YOUR_APP_KEY", app_secret="YOUR_APP_SECRET", region="cn")
api = EZVIZOpenAPI(client)
try:
response = api.add_device(device_serial="427734888", validate_code="ABCDEF")
print(f"Success: {response}")
except EZVIZAuthError as e:
print(f"Authentication error: {e.code} - {e.message}")
except EZVIZAPIError as e:
print(f"API error: {e.code} - {e.message}")
except Exception as e:
print(f"Unexpected error: {e}")
🔒 Security
- Never commit credentials: Keep your
EZVIZ_APP_KEYandEZVIZ_APP_SECRETout of version control - Use environment variables: Store credentials in
.envfile (ensure.gitignoreincludes.env) - Regular rotation: Rotate your API credentials periodically for security
- Least privilege: Use API keys with minimal required permissions
🤝 Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details on how to set up the development environment, run tests, and submit pull requests.
If you find a bug or have a feature request, please open an issue.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ezviz_openapi_utils-0.2.0.tar.gz.
File metadata
- Download URL: ezviz_openapi_utils-0.2.0.tar.gz
- Upload date:
- Size: 51.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61deb116e93d0cf3f43ca038b39b36621775a344a27be0fa3386a0c8212f7f4f
|
|
| MD5 |
e774fa084b067662588bd3f52dbeefe0
|
|
| BLAKE2b-256 |
efde54e56e97f4597aec68d1f2d951a32c1391864ac76cf7d39523b1e74b2a20
|
Provenance
The following attestation bundles were made for ezviz_openapi_utils-0.2.0.tar.gz:
Publisher:
python-publish.yml on sunbos/ezviz-openapi-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ezviz_openapi_utils-0.2.0.tar.gz -
Subject digest:
61deb116e93d0cf3f43ca038b39b36621775a344a27be0fa3386a0c8212f7f4f - Sigstore transparency entry: 649369431
- Sigstore integration time:
-
Permalink:
sunbos/ezviz-openapi-utils@90d918a7d7ef8e203bbd7a92693741ca44cd822d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/sunbos
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@90d918a7d7ef8e203bbd7a92693741ca44cd822d -
Trigger Event:
release
-
Statement type:
File details
Details for the file ezviz_openapi_utils-0.2.0-py3-none-any.whl.
File metadata
- Download URL: ezviz_openapi_utils-0.2.0-py3-none-any.whl
- Upload date:
- Size: 35.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a677c1e1b5ce4c7ea49bf5f17e1324103307ed6ed8d1428d46cb986729f1fd4
|
|
| MD5 |
48a5a7f431727743aebc000ee4d4af84
|
|
| BLAKE2b-256 |
c601bee6c021eca80e23b81f0142481fcebecd932331e23ef374a7a44f689148
|
Provenance
The following attestation bundles were made for ezviz_openapi_utils-0.2.0-py3-none-any.whl:
Publisher:
python-publish.yml on sunbos/ezviz-openapi-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ezviz_openapi_utils-0.2.0-py3-none-any.whl -
Subject digest:
3a677c1e1b5ce4c7ea49bf5f17e1324103307ed6ed8d1428d46cb986729f1fd4 - Sigstore transparency entry: 649369468
- Sigstore integration time:
-
Permalink:
sunbos/ezviz-openapi-utils@90d918a7d7ef8e203bbd7a92693741ca44cd822d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/sunbos
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@90d918a7d7ef8e203bbd7a92693741ca44cd822d -
Trigger Event:
release
-
Statement type: