Skip to main content

async-websocket-pool is a Python library that enables efficient creation and management of a pool of asynchronous WebSocket clients.

Project description

codecov GitHub PyPI - Python Version CodeQL PyPI - Version

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

async_websocket_pool-0.3.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

async_websocket_pool-0.3.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

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

Hashes for async_websocket_pool-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d5de890566be4125430ec82d8e125ee6b078de697847f622e0e4d5be25b1cec4
MD5 4eaf1fc2474f8dd210f9c934d9199272
BLAKE2b-256 194bb1925050f1b994dde71458b94109593b87edafe6da549a81c8e9f66ccc42

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file async_websocket_pool-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for async_websocket_pool-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fa0bd061b0044a82250ce652651120ab7489dc56cb6cd3cbe1e1396ca403bb46
MD5 703ee6e647628452838f3c8b82158f41
BLAKE2b-256 b0e2de3e49a84201c56ba2cedd12ad72e8574aee24caca872f6935a350ebf1a6

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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