libp2p.request_response package

Submodules

libp2p.request_response.api module

class libp2p.request_response.api.RequestContext(peer_id: 'ID', protocol_id: 'TProtocol')

Bases: object

peer_id: ID
protocol_id: TProtocol
class libp2p.request_response.api.RequestResponse(host: IHost)

Bases: object

Safe, one-shot request/response helper on top of libp2p streams.

remove_handler(protocol_id: TProtocol) None
async send_request(peer_id: ID, protocol_ids: Sequence[TProtocol], request: ReqT, codec: RequestResponseCodec[ReqT, RespT], config: RequestResponseConfig | None = None) RespT
set_handler(protocol_id: TProtocol, handler: Callable[[ReqT, RequestContext], Awaitable[RespT]], codec: RequestResponseCodec[ReqT, RespT], config: RequestResponseConfig | None = None) None
class libp2p.request_response.api.RequestResponseConfig(timeout: 'float' = 10.0, max_request_size: 'int' = 1048576, max_response_size: 'int' = 10485760, max_concurrent_inbound: 'int' = 128)

Bases: object

max_concurrent_inbound: int
max_request_size: int
max_response_size: int
timeout: float

libp2p.request_response.codec module

class libp2p.request_response.codec.BytesCodec(*args, **kwargs)

Bases: RequestResponseCodec[bytes, bytes]

Pass-through codec for raw bytes payloads.

decode_request(payload: bytes) bytes
decode_response(payload: bytes) bytes
encode_request(request: bytes) bytes
encode_response(response: bytes) bytes
class libp2p.request_response.codec.JSONCodec(*args, **kwargs)

Bases: RequestResponseCodec[Any, Any]

Codec for JSON-serializable Python values.

decode_request(payload: bytes) Any
decode_response(payload: bytes) Any
encode_request(request: Any) bytes
encode_response(response: Any) bytes
class libp2p.request_response.codec.RequestResponseCodec(*args, **kwargs)

Bases: Protocol[ReqT, RespT]

decode_request(payload: bytes) ReqT
decode_response(payload: bytes) RespT
encode_request(request: ReqT) bytes
encode_response(response: RespT) bytes

libp2p.request_response.exceptions module

exception libp2p.request_response.exceptions.MessageTooLargeError

Bases: RequestResponseError

Raised when a framed request or response exceeds configured limits.

exception libp2p.request_response.exceptions.ProtocolNotSupportedError

Bases: RequestResponseError

Raised when the remote peer supports none of the requested protocols.

exception libp2p.request_response.exceptions.RequestDecodeError

Bases: RequestResponseError

Raised when request deserialization fails on the server side.

exception libp2p.request_response.exceptions.RequestEncodeError

Bases: RequestResponseError

Raised when request serialization fails.

exception libp2p.request_response.exceptions.RequestResponseError

Bases: BaseLibp2pError

Base error for the request/response helper.

exception libp2p.request_response.exceptions.RequestTimeoutError

Bases: RequestResponseError

Raised when a request/response exchange exceeds the configured timeout.

exception libp2p.request_response.exceptions.RequestTransportError

Bases: RequestResponseError

Raised when transport- or stream-level failures interrupt a request.

exception libp2p.request_response.exceptions.ResponseDecodeError

Bases: RequestResponseError

Raised when response deserialization fails on the client side.

exception libp2p.request_response.exceptions.ResponseEncodeError

Bases: RequestResponseError

Raised when response serialization fails on the server side.

Module contents

class libp2p.request_response.BytesCodec(*args, **kwargs)

Bases: RequestResponseCodec[bytes, bytes]

Pass-through codec for raw bytes payloads.

decode_request(payload: bytes) bytes
decode_response(payload: bytes) bytes
encode_request(request: bytes) bytes
encode_response(response: bytes) bytes
class libp2p.request_response.JSONCodec(*args, **kwargs)

Bases: RequestResponseCodec[Any, Any]

Codec for JSON-serializable Python values.

decode_request(payload: bytes) Any
decode_response(payload: bytes) Any
encode_request(request: Any) bytes
encode_response(response: Any) bytes
exception libp2p.request_response.MessageTooLargeError

Bases: RequestResponseError

Raised when a framed request or response exceeds configured limits.

exception libp2p.request_response.ProtocolNotSupportedError

Bases: RequestResponseError

Raised when the remote peer supports none of the requested protocols.

class libp2p.request_response.RequestContext(peer_id: 'ID', protocol_id: 'TProtocol')

Bases: object

peer_id: ID
protocol_id: TProtocol
exception libp2p.request_response.RequestDecodeError

Bases: RequestResponseError

Raised when request deserialization fails on the server side.

exception libp2p.request_response.RequestEncodeError

Bases: RequestResponseError

Raised when request serialization fails.

class libp2p.request_response.RequestResponse(host: IHost)

Bases: object

Safe, one-shot request/response helper on top of libp2p streams.

remove_handler(protocol_id: TProtocol) None
async send_request(peer_id: ID, protocol_ids: Sequence[TProtocol], request: ReqT, codec: RequestResponseCodec[ReqT, RespT], config: RequestResponseConfig | None = None) RespT
set_handler(protocol_id: TProtocol, handler: Callable[[ReqT, RequestContext], Awaitable[RespT]], codec: RequestResponseCodec[ReqT, RespT], config: RequestResponseConfig | None = None) None
class libp2p.request_response.RequestResponseCodec(*args, **kwargs)

Bases: Protocol[ReqT, RespT]

decode_request(payload: bytes) ReqT
decode_response(payload: bytes) RespT
encode_request(request: ReqT) bytes
encode_response(response: RespT) bytes
class libp2p.request_response.RequestResponseConfig(timeout: 'float' = 10.0, max_request_size: 'int' = 1048576, max_response_size: 'int' = 10485760, max_concurrent_inbound: 'int' = 128)

Bases: object

max_concurrent_inbound: int
max_request_size: int
max_response_size: int
timeout: float
exception libp2p.request_response.RequestResponseError

Bases: BaseLibp2pError

Base error for the request/response helper.

exception libp2p.request_response.RequestTimeoutError

Bases: RequestResponseError

Raised when a request/response exchange exceeds the configured timeout.

exception libp2p.request_response.RequestTransportError

Bases: RequestResponseError

Raised when transport- or stream-level failures interrupt a request.

exception libp2p.request_response.ResponseDecodeError

Bases: RequestResponseError

Raised when response deserialization fails on the client side.

exception libp2p.request_response.ResponseEncodeError

Bases: RequestResponseError

Raised when response serialization fails on the server side.