Skip to main content

An up to date implementation of the PiShock and OpenShock APIs in Python. Includes functionality as a library and as a command line program.

Project description

PyShock

Python client for the new, unified PiShock API and the Openshock API.

Control a shocker from the terminal, or add control to your program!

Install

For the command line tool:

uv tool install 'pyshock[cli]'

Use it as a library in your python program:

uv add pyshock

Usage

Set up credentials:

pyshock init

Control a device:

pyshock shock --duration 2 --intensity 75 --shocker-id 00000

# or, if you only have one shocker associated with your account:
pyshock shock 2 75

Run pyshock info 00000 for device details. Run pyshock devices to list devices and capabilities.

Authentication

Pass credentials on the command line or cache them with pyshock init.

With a flag:

pyshock --key KEY shock --duration 2 --intensity 15 --shocker-id 00000

Interactively:

pyshock auth

Enter your API key: _____

Or in one step:

pyshock auth --key KEY

PyShock stores credentials in your user configuration folder. Shockers are cached to avoid API lookups. Refresh with pyshock devices.

Be advised, your API key will be stored in plain text.

API

PiShockAPI

from pyshock import PiShockAPI, ShockerOperation

with PiShockAPI(api_key="key") as api:
    for shocker in api.list_shockers():
        print(shocker.name, shocker.shocker_id)

    shared_shocker = api.get_shocker_by_share_code("ABC123456")

    api.operate_shocker(
        shocker=shared_shocker,
        operation=ShockerOperation.SHOCK,
        duration=2000, # 2 seconds
        intensity=50,
    )

Operations: ShockerOperation.SHOCK, VIBRATE, BEEP. Duration in milliseconds (0-15000), intensity 0-100.

OpenShockAPI

from pyshock import OpenShockAPI, ShockerOperation

# Token authentication (limited endpoints)
with OpenShockAPI(api_token="token") as api:
    for shocker in api.list_shockers():
        print(shocker.name, shocker.shocker_id)
        api.operate_shocker(
            shocker=shocker,
            operation=ShockerOperation.SHOCK,
            duration=2000,
            intensity=50,
        )

# Cookie authentication (full access, including share codes)
from http.cookiejar import MozillaCookieJar

jar = MozillaCookieJar("cookies.txt")
jar.load(ignore_discard=True, ignore_expires=True)
cookie = jar["openShockSession"].value

with OpenShockAPI(session_cookie=cookie) as api:
    account = api.get_account()
    print(account.username)

    for shocker in api.list_share_codes():
        print(shocker.name, shocker.shocker_id)

    api.link_share_code("ABC123456")

Operations: ShockerOperation.SHOCK, VIBRATE, BEEP. Duration in milliseconds (300-65535), intensity 0-100.

Requirements

Python 3.10+. Niquests for the library. The [cli] extra adds cyclopts, platformdirs, and rich for the terminal interface.

License

Your choice of AGPLv3-or-later or commercial. See LICENSE for more information.

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

pyshock-0.1.1.tar.gz (41.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyshock-0.1.1-py3-none-any.whl (51.6 kB view details)

Uploaded Python 3

File details

Details for the file pyshock-0.1.1.tar.gz.

File metadata

  • Download URL: pyshock-0.1.1.tar.gz
  • Upload date:
  • Size: 41.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyshock-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b065835e23642e50202e8ceea6c02322d7aae1ca52c90d4513ea4e37964d1c58
MD5 7d346aed7e25b7bd1be28bf00ca827ee
BLAKE2b-256 32097ec7843f2de5cedfc140adc3ce5850bc348a6f08e3f84c327f0cc9d42b01

See more details on using hashes here.

File details

Details for the file pyshock-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pyshock-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 51.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pyshock-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6225fd4ade7e3c39630e5a59d22a9e345afeaf144879031d6cc3676b0130e12b
MD5 cfb69d6a4cd7ba8f2e469928deeb61f3
BLAKE2b-256 0a20eb5f8c6611fb2ea5a89076c7084709d2f05dfa25ec9883816e1aa62054ab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page