Skip to content

Repository files navigation

OpenShock Python SDK

CIPyPIPythonLicense

The official OpenShock Python SDK to integrate with an OpenShock backend easily. Provides a typed REST API client with planned support for live WebSocket connections.

Install

pip install openshock

Quick start

fromopenshockimportOpenShockClientclient=OpenShockClient(api_token="your-api-token")
# Get backend infoinfo=client.meta.backend_info()
print(f"OpenShock {info.version}")
# List your shockersshockers=client.shockers.list_own()
# Send a vibrate commandfromopenshockimportControlclient.shockers.control([
Control(id="shocker-uuid", type="Vibrate", intensity=50, duration=1000)
])
client.close()

Or use as a context manager:

withOpenShockClient(api_token="your-api-token") asclient:
stats=client.meta.online_stats()
print(f"Devices online: {stats.devices_online}")

Resources

ResourceDescriptionExample
client.metaBackend info and statsclient.meta.backend_info()
client.accountUser info and API tokensclient.account.user_self()
client.devicesHub (device) managementclient.devices.list()
client.shockersShocker CRUD, control, logsclient.shockers.control(...)
client.sharesPublic share links and codesclient.shares.list_public()
client.user_sharesUser-to-user shares (V2)client.user_shares.get()
client.sessionsLogin session managementclient.sessions.list()

For hub/device endpoints, use OpenShockHubClient:

fromopenshockimportOpenShockHubClienthub=OpenShockHubClient(hub_token="device-token")
lcg=hub.hub.assign_lcg()
print(f"Connect to {lcg.host}:{lcg.port}")

Authentication

Two client types for two auth schemes:

  • OpenShockClient(api_token=...) — User API token (OpenShockToken header)
  • OpenShockHubClient(hub_token=...) — Device token (DeviceToken header)

Create API tokens at openshock.app under Settings > API Tokens.

Typed models

All responses are parsed into typed dataclasses:

fromopenshockimport (
BackendInfo, Stats, User, Token, Device, Shocker,
ShockerPermissions, ShockerLimits, ShockerLog, Control,
Session, PublicShare, UserShares, ShareInvite, PauseReason,
)

Self-hosting

To connect to a self-hosted instance:

client=OpenShockClient(
api_token="your-token",
base_url="https://api.your-instance.com",
)

Development

git clone https://github.com/OpenShock/SDK.Python.git
cd SDK.Python
pip install -e ".[dev]"# Format
ruff format .# Lint
ruff check .# Type check
mypy openshock/
# Test
pytest

License

MIT

About

OpenShock Python SDK to integrate with an OpenShock backend easily

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages