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 ⚡

PyPI - Version PyPI - License PyPI - Python Version build

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.

Note: Due to a limitation in the Pishock API, you will need to share your own shocker with yourself in order to use it via the API.

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.2.tar.gz (41.8 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.2-py3-none-any.whl (51.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyshock-0.1.2.tar.gz
  • Upload date:
  • Size: 41.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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.2.tar.gz
Algorithm Hash digest
SHA256 fde42eedce1a889181e344d1e8d7c476589299a8bc8c260dbe6d104a5cdda496
MD5 67b6236ce9e18de1fa9fecb2665c2080
BLAKE2b-256 dd1bd259055cf095312fe824b4692102bde420eee07b667f54e4f3789df4e62a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyshock-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 51.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5f9961491547428e3957f5258b8e49311ee4749cc5dd8137683a9520f05f944e
MD5 981599cfef0a692cf4d8e7ea5e213198
BLAKE2b-256 bfd3c5c9123f064b3ba9460bd314ec525bbb70ace0c27d0ced6f0946477728b4

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