This repository contains a pure-Python implementation of a WebSocket protocol stack. It’s written from the ground up to be embeddable in whatever program you choose to use, ensuring that you can communicate via WebSockets, as defined in RFC6455, regardless of your programming paradigm.
This repository does not provide a parsing layer, a network layer, or any rules about concurrency. Instead, it’s a purely in-memory solution, defined in terms of data actions and WebSocket frames. RFC6455 and Compression Extensions for WebSocket via RFC7692 are fully supported.
wsproto supports Python 3.6.1 or higher.
To install it, just run:
$ pip install wsproto
Usage
Let’s assume you have some form of network socket available. wsproto client connections automatically generate a HTTP request to initiate the WebSocket handshake. To create a WebSocket client connection:
from wsproto import WSConnection, ConnectionType
from wsproto.events import Request
ws = WSConnection(ConnectionType.CLIENT)
ws.send(Request(host='echo.websocket.org', target='/'))
To create a WebSocket server connection:
from wsproto.connection import WSConnection, ConnectionType
ws = WSConnection(ConnectionType.SERVER)
Every time you send a message, or call a ping, or simply if you receive incoming data, wsproto might respond with some outgoing data that you have to send:
some_socket.send(ws.bytes_to_send())
Both connection types need to receive incoming data:
ws.receive_data(some_byte_string_of_data)
And wsproto will issue events if the data contains any WebSocket messages or state changes:
for event in ws.events():
if isinstance(event, Request):
# only client connections get this event
ws.send(AcceptConnection())
elif isinstance(event, CloseConnection):
# guess nobody wants to talk to us any more...
elif isinstance(event, TextMessage):
print('We got text!', event.data)
elif isinstance(event, BytesMessage):
print('We got bytes!', event.data)
Take a look at our docs for a full list of events <https://wsproto.readthedocs.io/en/latest/api.html#events>!
Documentation
Documentation is available at https://wsproto.readthedocs.io/en/latest/.
Contributing
wsproto welcomes contributions from anyone! Unlike many other projects we are happy to accept cosmetic contributions and small contributions, in addition to large feature requests and changes.
Before you contribute (either by opening an issue or filing a pull request), please read the contribution guidelines.
License
wsproto is made available under the MIT License. For more details, see the LICENSE file in the repository.
Metadata
Release files for wsproto 1.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| wsproto-1.3.2.tar.gz | 50.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| wsproto-1.3.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 74.5 kB
Release files / wsproto-1.3.2.tar.gz
| Download URL | wsproto-1.3.2.tar.gz |
|---|---|
| Size | 50.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b86885dcf294e15204919950f666e06ffc6c7c114ca900b060d6e16293528294
|
|
BLAKE2b-256 checksum How to use checksums |
c77912135bdf8b9c9367b8701c2c19a14c913c120b882d50b014ca0d38083c2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / wsproto-1.3.2-py3-none-any.whl
| Download URL | wsproto-1.3.2-py3-none-any.whl |
|---|---|
| Size | 24.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
61eea322cdf56e8cc904bd3ad7573359a242ba65688716b0710a5eb12beab584
|
|
BLAKE2b-256 checksum How to use checksums |
a4f510b68b7b1544245097b2a1b8238f66f2fc6dcaeb24ba5d917f52bd2eed4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for wsproto 1.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.