async-websocket-pool is a Python library that enables efficient creation and management of a pool of asynchronous WebSocket clients.
Project description
Async WebSocket Pool
This repository contains a Python-based asynchronous WebSocket pool that allows for asynchronous connections to multiple WebSocket endpoints.
Getting Started
These instructions will get you a copy of the project up and running on your local machine.
Installation
You can install the async-websocket-pool using pip:
pip install async-websocket-pool
Please note that this project requires Python 3.10 or later.
Usage
from async_websocket_pool import connect, run_pool
async def on_message(message):
print(message)
tasks = [
lambda: connect(
'ws://example1.com',
on_message=on_message,
timeout=5,
handler_drain_timeout=2.0,
handler_cancel_grace=0.5,
),
lambda: connect(
'ws://example2.com',
on_message=on_message,
timeout=5,
handler_drain_timeout=2.0,
handler_cancel_grace=0.5,
),
]
await run_pool(tasks)
Reconnect and handler shutdown
connect() processes messages concurrently up to max_concurrent_tasks. When a connection
times out or disconnects, the library waits for in-flight on_message handlers to finish for
up to handler_drain_timeout seconds. Any handlers still running after that are cancelled, and
the client waits up to handler_cancel_grace more seconds before reconnecting.
This keeps reconnect latency bounded while still giving well-behaved handlers time to finish. Library users are expected to write cancellation-friendly handlers.
Built With
- Poetry - Packaging and dependency management
Documentation
For more information, review the API usage in this README and the release notes in
CHANGELOG.md.
Contribution
Contributions are always welcome. Please read CONTRIBUTING.md for the development
workflow and SECURITY.md for vulnerability reporting.
Authors
mpol1t
License
This project is licensed under the MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file async_websocket_pool-0.3.0.tar.gz.
File metadata
- Download URL: async_websocket_pool-0.3.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5de890566be4125430ec82d8e125ee6b078de697847f622e0e4d5be25b1cec4
|
|
| MD5 |
4eaf1fc2474f8dd210f9c934d9199272
|
|
| BLAKE2b-256 |
194bb1925050f1b994dde71458b94109593b87edafe6da549a81c8e9f66ccc42
|
Provenance
The following attestation bundles were made for async_websocket_pool-0.3.0.tar.gz:
Publisher:
python-pypi.yml on mpol1t/async-websocket-pool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
async_websocket_pool-0.3.0.tar.gz -
Subject digest:
d5de890566be4125430ec82d8e125ee6b078de697847f622e0e4d5be25b1cec4 - Sigstore transparency entry: 1006677017
- Sigstore integration time:
-
Permalink:
mpol1t/async-websocket-pool@77ba91f8cb807ed04b390f28bcb5d8d99a5a1815 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/mpol1t
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-pypi.yml@77ba91f8cb807ed04b390f28bcb5d8d99a5a1815 -
Trigger Event:
push
-
Statement type:
File details
Details for the file async_websocket_pool-0.3.0-py3-none-any.whl.
File metadata
- Download URL: async_websocket_pool-0.3.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa0bd061b0044a82250ce652651120ab7489dc56cb6cd3cbe1e1396ca403bb46
|
|
| MD5 |
703ee6e647628452838f3c8b82158f41
|
|
| BLAKE2b-256 |
b0e2de3e49a84201c56ba2cedd12ad72e8574aee24caca872f6935a350ebf1a6
|
Provenance
The following attestation bundles were made for async_websocket_pool-0.3.0-py3-none-any.whl:
Publisher:
python-pypi.yml on mpol1t/async-websocket-pool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
async_websocket_pool-0.3.0-py3-none-any.whl -
Subject digest:
fa0bd061b0044a82250ce652651120ab7489dc56cb6cd3cbe1e1396ca403bb46 - Sigstore transparency entry: 1006677020
- Sigstore integration time:
-
Permalink:
mpol1t/async-websocket-pool@77ba91f8cb807ed04b390f28bcb5d8d99a5a1815 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/mpol1t
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-pypi.yml@77ba91f8cb807ed04b390f28bcb5d8d99a5a1815 -
Trigger Event:
push
-
Statement type: