Python client for the HypeRate WebSocket API
Project description
Official HypeRate Python Bindings
A Python client library for connecting to the HypeRate WebSocket API to receive real-time heartbeat and clip data.
Features
- Real-time heartbeat monitoring - Subscribe to live heart rate data from HypeRate devices
- Clip notifications - Receive notifications when clips are created
- Async/await support - Built with asyncio for efficient WebSocket handling
- Event-driven architecture - Register handlers for different event types
- Type hints - Full type annotation support for better IDE integration
- Comprehensive logging - Built-in logging with configurable levels
- Error handling - Robust error handling and connection management
Supported Python Versions
This library supports and is tested on:
- Python 3.8
- Python 3.9
- Python 3.10
- Python 3.11
- Python 3.12
- Python 3.13
- Python 3.14
Installation
pip install hyperate
Quick Start
import asyncio
import hyperate
async def main():
# Initialize and connect to HypeRate
client = hyperate.HypeRate("your_api_token_here")
await client.connect()
# Define and register event handlers
def on_heartbeat(data):
print(f"Heartbeat received: {data['hr']} BPM")
def on_connected():
print("Connected to HypeRate!")
def on_clip(data):
print(f"New clip: {data['twitch_slug']}")
client.on('heartbeat', on_heartbeat)
client.on('connected', on_connected) # Note: this fires after connection is already established
client.on('clip', on_clip)
# Subscribe to a device's heartbeat data
await client.join_heartbeat_channel("internal-testing") # Use "internal-testing" for testing
# Keep the connection alive
try:
while True:
await asyncio.sleep(1)
except KeyboardInterrupt:
print("Exiting...")
finally:
await client.disconnect()
# Run the client
if __name__ == "__main__":
asyncio.run(main())
Alternative Quick Start (Lambda Style)
import asyncio
from hyperate import HypeRate
async def main():
client = HypeRate("your_api_token_here")
await client.connect()
# Register handlers with lambda functions
client.on('heartbeat', lambda data: print(f"❤️ {data['hr']} BPM"))
client.on('clip', lambda data: print(f"🎬 Clip: {data['twitch_slug']}"))
await client.join_heartbeat_channel("internal-testing")
try:
while True:
await asyncio.sleep(1)
except KeyboardInterrupt:
pass
finally:
await client.disconnect()
asyncio.run(main())
API Documentation
HypeRate Class
Constructor
HypeRate(api_token: str, base_url: str = "wss://app.hyperate.io/socket/websocket", logger: Optional[logging.Logger] = None)
Methods
connect()- Connect to the HypeRate WebSocketdisconnect()- Disconnect from the WebSocketjoin_heartbeat_channel(device_id)- Subscribe to heartbeat data for a deviceleave_heartbeat_channel(device_id)- Unsubscribe from heartbeat datajoin_clips_channel(device_id)- Subscribe to clip notifications for a deviceleave_clips_channel(device_id)- Unsubscribe from clip notificationson(event, handler)- Register an event handler
Events
connected- Fired when connected to HypeRatedisconnected- Fired when disconnected from HypeRateheartbeat- Fired when heartbeat data is receivedclip- Fired when clip data is receivedchannel_joined- Fired when a channel is successfully joinedchannel_left- Fired when a channel is successfully left
Usage Notes
- Connect to HypeRate first with
await client.connect()before registering handlers - Use
"internal-testing"as device ID for testing purposes - Event handlers registered after connection won't receive the initial
connectedevent - Use
while True:for the main loop as the client manages the connection state internally
Device Class
Utility class for device ID validation and extraction.
Methods
is_valid_device_id(device_id)- Check if a device ID is validextract_device_id(input_str)- Extract device ID from URL or string
Development
Setting up the development environment
- Clone the repository
- Install development dependencies:
pip install -r .\Tests\test_requirements.txt
- Install the package in development mode:
pip install -e .
Running Tests
Use the comprehensive test runner:
# Run all tests
python Tests/run_tests.py --all
# Run specific test types
python Tests/run_tests.py --unit # Unit tests only
python Tests/run_tests.py --integration # Mocked scenario tests
python Tests/run_tests.py --real-integration --token=your_token # Real API integration
python Tests/run_tests.py --performance # Performance tests
# Run with coverage
python Tests/run_tests.py --coverage
# Run code quality checks
python Tests/run_tests.py --lint
Real Integration Tests
To run tests against the actual HypeRate API, provide your API token via command line:
# Using pytest (recommended)
python -m pytest Tests/test_real_integration.py --token=your_actual_api_token_here
# Using direct script execution
python Tests/test_real_integration.py --token=your_actual_api_token_here
# Using the test runner with token
python Tests/run_tests.py --real-integration --token=your_actual_api_token_here
Code Quality
This project maintains high code quality standards:
- Code Quality Checks: PyLint (10.0/10.0), Mypy (strict mode), and Flake8 style checking
- Test Coverage: Minimum 85% code coverage required
- Comprehensive Testing: Unit, integration, and performance tests
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass and code quality checks pass
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Links
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
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 hyperate-1.0.1.tar.gz.
File metadata
- Download URL: hyperate-1.0.1.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96511256e870d3c09589187f12cadb82e8365be9420c82b80e9511bc5e3173fa
|
|
| MD5 |
f23e774e1e31b7f583883bc5b9f433f2
|
|
| BLAKE2b-256 |
f4cd6843331c1080e1d0ff24488393410b22701bba97240190bac2e8afb4572e
|
Provenance
The following attestation bundles were made for hyperate-1.0.1.tar.gz:
Publisher:
publish-pypi.yml on Serpensin/HypeRate-Python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hyperate-1.0.1.tar.gz -
Subject digest:
96511256e870d3c09589187f12cadb82e8365be9420c82b80e9511bc5e3173fa - Sigstore transparency entry: 601046360
- Sigstore integration time:
-
Permalink:
Serpensin/HypeRate-Python@1b737ba71723534998968d9ac06d482a9c685a8a -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/Serpensin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@1b737ba71723534998968d9ac06d482a9c685a8a -
Trigger Event:
release
-
Statement type:
File details
Details for the file hyperate-1.0.1-py3-none-any.whl.
File metadata
- Download URL: hyperate-1.0.1-py3-none-any.whl
- Upload date:
- Size: 10.6 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 |
2723f0e2eb3289d0b7126429240cb7de05d4cdcd122777285af3bd1ddbfed3e4
|
|
| MD5 |
4cbfa42192ab6f517dadb580cf5534b0
|
|
| BLAKE2b-256 |
6886f4fab8f841fa7bd4d57de3db007f4b3e22f05a2c9131d8b810d19ca643de
|
Provenance
The following attestation bundles were made for hyperate-1.0.1-py3-none-any.whl:
Publisher:
publish-pypi.yml on Serpensin/HypeRate-Python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hyperate-1.0.1-py3-none-any.whl -
Subject digest:
2723f0e2eb3289d0b7126429240cb7de05d4cdcd122777285af3bd1ddbfed3e4 - Sigstore transparency entry: 601046362
- Sigstore integration time:
-
Permalink:
Serpensin/HypeRate-Python@1b737ba71723534998968d9ac06d482a9c685a8a -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/Serpensin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@1b737ba71723534998968d9ac06d482a9c685a8a -
Trigger Event:
release
-
Statement type: