Installation¶
You can install the cli with pip
:
$ pip install websockets-cli
or use a better package manager like poetry:
# you probably want to add this dependency as a dev one, this is why I put -D into square brackets
$ poetry add websockets-cli -G dev
ws starts working from python3.8 and also supports pypy3. It has the following dependencies:
- trio for structured (async) concurrency support.
- trio-websocket the library implementing the websocket protocol.
- pydantic / pydantic-settings for input validation and settings management.
- certifi to manage TLS and certificates.
- click to write the cli.
- click-didyoumean for command suggestions in case of typos.
- rich for beautiful output display.
- shellingham to detect the shell used.
To confirm the installation works, you can type the command name in the terminal.
$ ws
Usage: ws [OPTIONS] COMMAND [ARGS]...
A convenient websocket cli.
Example usage:
# listens incoming messages from endpoint ws://localhost:8000/path
$ ws listen ws://localhost:8000/path
# sends text "hello world" in a text frame
$ ws text wss://ws.postman-echo.com/raw "hello world"
# sends the content from json file "hello.json" in a binary frame
$ ws byte wss://ws.postman-echo.com/raw file@hello.json
Options:
--version Show the version and exit.
-h, --help Show this message and exit.
Commands:
byte Sends binary message to URL endpoint.
echo-server Runs an echo websocket server.
install-completion Install completion script for bash, zsh and fish...
listen Listens messages on a given URL.
ping Pings a websocket server located at URL.
pong Sends a pong to websocket server located at URL.
session Opens an interactive session to communicate with...
tail An emulator of the tail unix command that output...
text Sends text message on URL endpoint.