THE ORIONIS API
Build with clarity.
Explore the building blocks of an async-first Python framework. Every module, class, and method — connected, searchable, and ready to build with.
class BodyStream(IBodyStream): (source)
Constructor: BodyStream(interface, receive_or_protocol, max_body_size, max_buffer_size)
Own and manage the raw HTTP request body stream.
Enforce the max-body-size limit and provide transparent replay when the body has already been buffered by read().
Notes
The underlying transport stream is consumed at most once. After read() completes, stream() replays the cached buffer so callers such as the multipart parser keep working even after a plain body() call. Calling stream() after a streaming consumer has iterated it—without a prior read()—raises RuntimeError. Raw bytes are gone after streaming multipart.
| Method | __init__ |
Initialize a BodyStream for the given transport interface. |
| Async Method | read |
Buffer and return the full request body. Idempotent. |
| Async Method | stream |
Yield body chunks from the transport. |
| Class Variable | __slots__ |
Declare the instance attribute slots reserved by this class. |
| Instance Variable | __body |
Initialize the body buffer to None (not yet read). |
| Instance Variable | __consumed |
Track whether the raw transport stream has been consumed. |
| Instance Variable | __is |
Record which transport provides the body chunks. |
| Instance Variable | __max |
Maximum bytes buffered by read() (default 2 MiB). An explicit None disables this limit for a manually built stream. |
| Instance Variable | __max |
Maximum allowed body size in bytes (default 16 MiB). An explicit None disables the transport limit for a manually built stream. |
| Instance Variable | __receive |
ASGI receive callable or RSGI HTTPProtocol instance. |
| Property | is |
Return True when the full body has been cached by read(). |
| Property | is |
Return True when the raw transport stream has been consumed. |
Interface, receive_or_protocol: object, max_body_size: int | None = _DEFAULT_LIMITS[int | None = _DEFAULT_LIMITS[Initialize a BodyStream for the given transport interface.
| Parameters | |
interface:orionis.http.enums.Interface | Transport protocol type (ASGI or RSGI). |
receiveobject | ASGI receive callable or RSGI HTTPProtocol instance. |
maxint | None, optional | Maximum allowed body size in bytes (default 16 MiB). An explicit None disables the transport limit for a manually built stream. |
maxint | None, optional | Maximum bytes buffered by read() (default 2 MiB). An explicit None disables this limit for a manually built stream. |
| Returns | |
None | Initialize a BodyStream for the given transport interface. |
Buffer and return the full request body. Idempotent.
Subsequent calls return the cached buffer without re-reading the transport.
| Returns | |
bytes | Complete request body as a contiguous bytes object. |
| Raises | |
RuntimeError | If the stream was consumed by a streaming consumer without having been buffered first. |
orionis.http.payload.body.PayloadTooLargeException | If the body exceeds max_body_size or max_buffer_size. |
Yield body chunks from the transport.
Replay the internal buffer as a single chunk when read() was called first, making this method safe to call multiple times.
| Yields | |
bytes | A chunk of the raw request body. |
| Raises | |
RuntimeError | If the stream was consumed by a streaming consumer (e.g. multipart) before the body was buffered. |
ConnectionError | If the ASGI client disconnects before the final request-body frame. |
orionis.http.payload.body.PayloadTooLargeException | If incoming data exceeds max_body_size. |
Maximum bytes buffered by read() (default 2 MiB). An explicit None disables this limit for a manually built stream.
Maximum allowed body size in bytes (default 16 MiB). An explicit None disables the transport limit for a manually built stream.
Return True when the full body has been cached by read().
| Returns | |
bool | True if the body has been fully buffered, False otherwise. |