py_byte_channel (erlang_python v3.0.0)
View SourceRaw byte channel for Erlang-Python communication.
ByteChannel provides raw byte streaming without term serialization, suitable for HTTP bodies, file transfers, and binary protocols.
Unlike py_channel which serializes Erlang terms, ByteChannel passes raw binaries directly without any encoding/decoding overhead.
Usage
%% Create a byte channel
{ok, Ch} = py_byte_channel:new(),
%% Send raw bytes to Python
ok = py_byte_channel:send(Ch, <<"HTTP/1.1 200 OK\r\n">>),
%% Python receives via ByteChannel.receive_bytes()
%% Python sends back via ByteChannel.send_bytes()
%% Close when done
py_byte_channel:close(Ch).When to Use
- HTTP request/response bodies
- File streaming
- Binary protocols without Erlang term overhead
Summary
Functions
Close a byte channel.
Get channel information.
Create a new byte channel with default settings.
Create a new byte channel with options.
Receive raw bytes from a channel (blocking).
Receive raw bytes from a channel with timeout.
Register byte channel callback handlers for Python.
Send raw bytes to a channel.
Try to receive raw bytes from a channel (non-blocking).
Types
-type channel() :: reference().
-type opts() :: #{max_size => non_neg_integer()}.
Functions
-spec close(channel()) -> ok.
Close a byte channel.
Signals Python receivers that no more bytes will arrive.
Get channel information.
Returns a map with:
size- Current queue size in bytesmax_size- Maximum queue size (0 = unlimited)closed- Whether the channel is closed
Create a new byte channel with default settings.
Creates an unbounded channel for raw byte passing.
Create a new byte channel with options.
Options:
max_size- Maximum queue size in bytes for backpressure (0 = unlimited)
Receive raw bytes from a channel (blocking).
Blocks until data is available. Equivalent to recv(Channel, infinity).
Receive raw bytes from a channel with timeout.
Blocks until data is available or timeout expires.
-spec register_callbacks() -> ok.
Register byte channel callback handlers for Python.
This should be called during application startup to enable Python's erlang.call('_py_byte_channel_receive', ...) etc.
Send raw bytes to a channel.
The binary is queued directly for Python to receive without any term serialization. If the queue exceeds max_size, returns busy (backpressure).
Try to receive raw bytes from a channel (non-blocking).
Returns immediately with binary data or empty/closed status.