Skip to main content

Channels Build Status codecov BCH compliance donate using paypal

Simple wrapper around file objects and sockets that provides uniform interface to both.

Example:

from channels import PipeChannel, SocketChannel

pipe_chan = PipeChannel(sys.stdin.fileno(), sys.stdout.fileno())
sock_chan = SocketChannel(socket.create_connection(('127.0.0.1', 8080))

Classes

Channel

Channel is the base class for different channels. Every channel implements the following methods:

read(self)

Performs a non-blocking read and returns any bytes available. Raises EndpointClosedException if the channel is closed.

write(self, *data)

Writes chunks of bytes to the channel. Raises EndpointClosedException.

close(self)

Closes the channel and frees up the resources.

get_fd(self)

Returns a file descriptor number that can be used for poll or epoll for reading. Raises NotImplementedError if (custom) channel doesn't support reading.

Every channel has a buffering property (read-only). It is equal to 'line' for line-buffered channels. It should be 'bytes' otherwise but any value other than 'line' works.

The following channel classes are implemented:

PipeChannel

from channels import PipeChannel

PipeChannel(faucet=None, sink=None, *, buffering='bytes')

faucet should be a file descriptor open for reading. sink should be a file descriptor open for writing. If both are provided, the channel is bi-directional. Sets faucet to non-blocking mode.

If buffering is set to 'line' the channel uses line-buffering for reading. Every read call will return b'' if there is no complete line available even if there is any data at all. If channel is closed but there is data in buffer, calls to read will return lines from buffer until it is exhausted. Last line maybe an incomplete line (no '\n' in the end).

SocketChannel

from channels import SocketChannel

SocketChannel(sock, *, buffering='bytes')

Wraps a socket for non-blocking IO. See PipeChannel for more info on buffering parameter.

TestChannel

(in package channels.testing)

from channels.testing import TestChannel

TestChannel(*, buffering='bytes')

See PipeChannel for more info on buffering parameter.

Provides put and get methods to to feed data to read and fetch "written" data respectively.

Poller

(in package channels.poller)

Poller is a wrapper for select.poll that also supports accepting and keeping track of TCP/Unix clients.

from channels.poller import Poller

Poller(*, buffering='bytes')

Creates a poller object. All accepted client channels inherit the buffering parameter.

register(self, channel)

Registers the channel for polling.

add_server(self, sock)

Registers a server socket. Poller will accept incoming connections and automatically register clients.

unregister(self, channel)

Removes a registered channel. Silently does nothing if channel is not registered.

close_all(self)

Closes all registered channels and servers.

poll(self, timeout=None)

Performs a single call to select.poll(). timeout is the number of seconds for polling or None for infinite polling. Return value is a list of pairs in format of (data, channel) for channels and ((addr, client_channel), sock) for server sockets. addr depends on socket type. For line-based channels single poll call will return one result for every line available.

Release files for yet-another-io-channels-library 0.2.4.post1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yet-another-io-channels-library 0.2.4.post1
File Size Uploaded
yet_another_io_channels_library-0.2.4.post1.tar.gz 5.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yet-another-io-channels-library 0.2.4.post1
File Interpreter ABI Platform
yet_another_io_channels_library-0.2.4.post1-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / yet_another_io_channels_library-0.2.4.post1.tar.gz

Download URL yet_another_io_channels_library-0.2.4.post1.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e2f7c6b7dbbf4c4eeb2374f66183f1e16bc34d8d48306bb8d9d3080eb39dcb83
BLAKE2b-256 checksum
How to use checksums
96955595d7f48d3a386cd13b79b88b487d23f57e28a652325d1afbdbab7e38a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.9 Linux/6.6.30-gentoo

Release files / yet_another_io_channels_library-0.2.4.post1-py3-none-any.whl

Download URL yet_another_io_channels_library-0.2.4.post1-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0f8a1e861108e39700e2827e83ef77b3dfef5804e5dc156d597c0ff86a12d265
BLAKE2b-256 checksum
How to use checksums
91bdffe32d7bf0ba157878db255721332ad18e681f2567d6eda3ea6286dfda3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.9 Linux/6.6.30-gentoo

Release history Release notifications | RSS feed

This release

0.2.4.post1 This release

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page