cayu.egress.broker
Public Cayu API. Definitions are grouped by their public source module, and definitions from private implementation modules appear on their package’s page; adding a symbol does not move existing links. The import shown at each entry is a supported public namespace. Read the Python API overview and install the required extra.
CapturedRequest
Section titled “CapturedRequest”from cayu.egress import CapturedRequestOne outbound request captured outside the sandbox by the egress proxy.
Bases: BaseModel.
Fields and attributes
Section titled “Fields and attributes”Defaults below are source expressions; Field(...) includes schema/validation settings and default_factory creates a fresh value. Inherited declarations are included. Constructor behavior follows the model or dataclass shown in the bases/decorators.
| Name | Type | Default |
|---|---|---|
method |
str |
required |
host |
str |
required |
path |
str |
required |
protocol |
EgressProtocol |
'https' |
port |
int |
443 |
query |
str |
'' |
headers |
dict[str, str] |
Field(default_factory=dict) |
body |
bytes |
b'' |
normalize_method (method)
Section titled “normalize_method (method)”CapturedRequest.normalize_method(value: str, info) -> strnormalize_host (method)
Section titled “normalize_host (method)”CapturedRequest.normalize_host(value: str, info) -> strvalidate_path (method)
Section titled “validate_path (method)”CapturedRequest.validate_path(value: str, info) -> strvalidate_port (method)
Section titled “validate_port (method)”CapturedRequest.validate_port(value: int) -> intpolicy_view (method)
Section titled “policy_view (method)”CapturedRequest.policy_view() -> EgressRequesturl (method)
Section titled “url (method)”CapturedRequest.url() -> strRelease source · Runtime guarantees · Capability guides
CapturedResponse
Section titled “CapturedResponse”from cayu.egress import CapturedResponseThe provider response returned to the sandbox after scrubbing.
Repeated Set-Cookie values belong in set_cookie_headers, in wire order,
not a comma-joined mapping value. A single Set-Cookie in headers is also
supported and precedes the separate values when both are supplied.
Bases: BaseModel.
Fields and attributes
Section titled “Fields and attributes”Defaults below are source expressions; Field(...) includes schema/validation settings and default_factory creates a fresh value. Inherited declarations are included. Constructor behavior follows the model or dataclass shown in the bases/decorators.
| Name | Type | Default |
|---|---|---|
status_code |
int |
required |
headers |
dict[str, str] |
Field(default_factory=dict) |
set_cookie_headers |
tuple[str, ...] |
Field(default_factory=tuple, repr=False) |
body |
bytes |
b'' |
validate_set_cookie_headers (method)
Section titled “validate_set_cookie_headers (method)”CapturedResponse.validate_set_cookie_headers(value: object) -> tuple[str, ...]Release source · Runtime guarantees · Capability guides
EgressDecision
Section titled “EgressDecision”from cayu.egress import EgressDecisionSecret-free audit record of one broker decision.
Intentionally has no field that could carry the real credential, so it is always safe to log or emit as an event.
Decorators: @dataclass(frozen=True).
Fields and attributes
Section titled “Fields and attributes”Defaults below are source expressions; Field(...) includes schema/validation settings and default_factory creates a fresh value. Inherited declarations are included. Constructor behavior follows the model or dataclass shown in the bases/decorators.
| Name | Type | Default |
|---|---|---|
allowed |
bool |
required |
status_code |
int |
required |
destination |
str |
required |
method |
str |
required |
path |
str |
required |
grant_id |
str | None |
required |
policy_name |
str | None |
required |
reason |
str | None |
required |
authorization_kind |
Literal['virtual_credential', 'credentialless', 'transport'] |
'virtual_credential' |
error_code |
str | None |
None |
Release source · Runtime guarantees · Capability guides
EgressResponseBuffer
Section titled “EgressResponseBuffer”from cayu.egress import EgressResponseBufferOne forwarded request’s reservation against an egress buffer budget.
The broker creates one per forwarded request. It holds the reservation until
the response body has been handed on: handle_request releases it when it
returns, and the proxy server releases it only after it has written or
dropped the body. reserve_to only grows the reservation; it raises when
the shared budget cannot hold the new total, or after release. Both are
thread-safe, so a custom upstream may reserve from another thread.
init (method)
Section titled “init (method)”EgressResponseBuffer.__init__(budget: EgressResponseBufferBudget) -> Nonereserved_bytes (property)
Section titled “reserved_bytes (property)”EgressResponseBuffer.reserved_bytes() -> intreleased (property)
Section titled “released (property)”EgressResponseBuffer.released() -> boolreserve_to (method)
Section titled “reserve_to (method)”EgressResponseBuffer.reserve_to(total_bytes: int) -> Nonerelease (method)
Section titled “release (method)”EgressResponseBuffer.release() -> NoneReturn the reservation to the budget; later calls do nothing.
Release source · Runtime guarantees · Capability guides
EgressResponseBufferBudget
Section titled “EgressResponseBufferBudget”from cayu.egress import EgressResponseBufferBudgetBytes of buffered upstream responses held at once, shared by brokers.
One budget may back many brokers (VirtualEgressEnvironmentFactory shares
one across every session it creates), so its accounting is thread-safe.
init (method)
Section titled “init (method)”EgressResponseBufferBudget.__init__(limit_bytes: int=DEFAULT_EGRESS_RESPONSE_BUFFER_BUDGET_BYTES) -> Nonelimit_bytes (property)
Section titled “limit_bytes (property)”EgressResponseBufferBudget.limit_bytes() -> intused_bytes (property)
Section titled “used_bytes (property)”EgressResponseBufferBudget.used_bytes() -> intRelease source · Runtime guarantees · Capability guides
EgressUpstream
Section titled “EgressUpstream”from cayu.egress import EgressUpstreamPrepares a bounded provider call without dispatching it.
Decorators: @runtime_checkable.
Bases: Protocol.
prepare (method)
Section titled “prepare (method)”EgressUpstream.prepare(request: CapturedRequest, *, limits: EgressUpstreamLimits) -> EgressUpstreamOperationRelease source · Runtime guarantees · Capability guides
EgressUpstreamLimits
Section titled “EgressUpstreamLimits”from cayu.egress import EgressUpstreamLimitsCayu-owned limits that an upstream must enforce while reading.
response_buffer, when present, is this operation’s share of the
broker-wide buffer budget: an upstream calls reserve_to with the bytes
it holds for the response so far, and stops reading if that raises.
Decorators: @dataclass(frozen=True).
Fields and attributes
Section titled “Fields and attributes”Defaults below are source expressions; Field(...) includes schema/validation settings and default_factory creates a fresh value. Inherited declarations are included. Constructor behavior follows the model or dataclass shown in the bases/decorators.
| Name | Type | Default |
|---|---|---|
max_response_bytes |
int |
required |
total_timeout_s |
float |
required |
response_buffer |
EgressResponseBuffer | None |
None |
Release source · Runtime guarantees · Capability guides
EgressUpstreamOperation
Section titled “EgressUpstreamOperation”from cayu.egress import EgressUpstreamOperationOne prepared upstream call with positive cancellation settlement.
Construction is side-effect free. result() starts the operation once.
When no cancellation owner is supplied, cancellation waits for natural
completion rather than treating cancellation of an asyncio wrapper as
proof that opaque delegated work stopped.
init (method)
Section titled “init (method)”EgressUpstreamOperation.__init__(operation_factory: UpstreamOperationFactory, *, cancel_and_wait: UpstreamCancellationOwner | None=None) -> Noneresult (method)
Section titled “result (method)”async EgressUpstreamOperation.result() -> CapturedResponseReturn the provider result, preserving fatal signals for direct callers.
cancel_and_wait (method)
Section titled “cancel_and_wait (method)”async EgressUpstreamOperation.cancel_and_wait() -> NoneRequest cancellation and return only after positive quiescence.
Release source · Runtime guarantees · Capability guides
HttpxUpstream
Section titled “HttpxUpstream”from cayu.egress import HttpxUpstreamDefault upstream that forwards requests to the provider over HTTPS.
init (method)
Section titled “init (method)”HttpxUpstream.__init__(*, timeout_s: float=DEFAULT_EGRESS_UPSTREAM_TOTAL_TIMEOUT_S, max_response_bytes: int=DEFAULT_EGRESS_UPSTREAM_MAX_RESPONSE_BYTES, transport: httpx.AsyncBaseTransport | None=None, routes: Mapping[str, str] | None=None, destination_resolver: DestinationResolver | None=None) -> Noneprepare (method)
Section titled “prepare (method)”HttpxUpstream.prepare(request: CapturedRequest, *, limits: EgressUpstreamLimits) -> EgressUpstreamOperationsend (method)
Section titled “send (method)”async HttpxUpstream.send(request: CapturedRequest) -> CapturedResponseDirect convenience entrance using this upstream’s configured limits.
Release source · Runtime guarantees · Capability guides
TransparentEgressBroker
Section titled “TransparentEgressBroker”from cayu.egress import TransparentEgressBrokerAuthorizes, resolves, rewrites, forwards, and scrubs outbound requests.
The broker is the only place a SecretRef is resolved to a real value.
The real value is written into the upstream request and nowhere else — never
into a decision record, a returned response’s diagnostics, or an exception.
init (method)
Section titled “init (method)”TransparentEgressBroker.__init__(*, registry: VirtualCredentialRegistry, resolver: SecretResolver | None=None, policies: Mapping[str, EgressPolicy], approved_destinations: Sequence[ApprovedEgressDestination]=(), public_web_policy: str | None=None, upstream: EgressUpstream | None=None, audit: Callable[[EgressDecision], None] | None=None, require_test_mode_credentials: bool=True, browser_max_response_bytes: int | None=None, max_active_upstream_operations: int=DEFAULT_EGRESS_MAX_ACTIVE_UPSTREAM_OPERATIONS, upstream_max_response_bytes: int=DEFAULT_EGRESS_UPSTREAM_MAX_RESPONSE_BYTES, upstream_total_timeout_s: float=DEFAULT_EGRESS_UPSTREAM_TOTAL_TIMEOUT_S, response_buffer_budget_bytes: int | None=None, response_buffer_budget: EgressResponseBufferBudget | None=None) -> Noneupstream_total_timeout_s (property)
Section titled “upstream_total_timeout_s (property)”TransparentEgressBroker.upstream_total_timeout_s() -> floatTotal time one upstream request may take, including the response body.
registry (property)
Section titled “registry (property)”TransparentEgressBroker.registry() -> VirtualCredentialRegistryThe credential registry, for session-close revocation by adapters.
has_credentialless_destinations (property)
Section titled “has_credentialless_destinations (property)”TransparentEgressBroker.has_credentialless_destinations() -> boolWhether the broker requires an isolated, independently authenticated transport.
authorize_connect_destination (method)
Section titled “authorize_connect_destination (method)”async TransparentEgressBroker.authorize_connect_destination(*, host: str, port: int) -> boolReturn positive coarse authority before the proxy mints a leaf certificate.
This entrance deliberately authorizes only the HTTPS destination. It does
not acquire a credential lease, resolve a secret, or replace the complete
method/path authorization performed by handle_request after TLS.
Keeping the lookup on the broker’s event loop also avoids reading the
mutable grant registry from a proxy worker thread.
begin_connect_destination_admission (method)
Section titled “begin_connect_destination_admission (method)”async TransparentEgressBroker.begin_connect_destination_admission(*, host: str, port: int) -> _ConnectDestinationAdmission | NoneLease coarse CONNECT authority through leaf generation and success.
connect_destination_admission_is_active (method)
Section titled “connect_destination_admission_is_active (method)”async TransparentEgressBroker.connect_destination_admission_is_active(admission: _ConnectDestinationAdmission) -> boolRevalidate one broker-owned CONNECT admission before success.
end_connect_destination_admission (method)
Section titled “end_connect_destination_admission (method)”async TransparentEgressBroker.end_connect_destination_admission(admission: _ConnectDestinationAdmission) -> NoneRelease one CONNECT admission after success or denial is written.
handle_request (method)
Section titled “handle_request (method)”async TransparentEgressBroker.handle_request(request: CapturedRequest) -> CapturedResponserevoke_authority_and_wait (method)
Section titled “revoke_authority_and_wait (method)”async TransparentEgressBroker.revoke_authority_and_wait(presented_values: Sequence[str]) -> intRevoke routes, settle dispatched upstream work, and drain requests.
settle_active_operations (method)
Section titled “settle_active_operations (method)”async TransparentEgressBroker.settle_active_operations() -> NoneSettle every dispatched credential resolution and upstream call.
settle_active_credential_resolutions (method)
Section titled “settle_active_credential_resolutions (method)”async TransparentEgressBroker.settle_active_credential_resolutions() -> NoneRetain cancellation-opaque resolution work until natural settlement.
settle_active_upstream_operations (method)
Section titled “settle_active_upstream_operations (method)”async TransparentEgressBroker.settle_active_upstream_operations() -> NoneCancel dispatched upstream calls and retain failures for retry.
renew_authority (method)
Section titled “renew_authority (method)”TransparentEgressBroker.renew_authority(grants: Sequence[VirtualCredentialGrant]) -> NoneInstall fresh virtual values and reopen unchanged credentialless routes.