Infrastructure API¶
Configuration¶
config ¶
ExtraConfig ¶
Bases: BaseConfig
model_config
class-attribute
instance-attribute
¶
model_config = ConfigDict(arbitrary_types_allowed=True)
transport
class-attribute
instance-attribute
¶
transport: BaseTransportConfig = Field(
default_factory=DefaultTransportConfig
)
encoding
class-attribute
instance-attribute
¶
encoding: BaseEncodingConfig = DefaultEncodingConfig()
protocol
class-attribute
instance-attribute
¶
protocol: BaseProtocolConfig = Field(
default_factory=DefaultProtocolConfig
)
mapper
class-attribute
instance-attribute
¶
mapper: BaseMapperConfig = Field(
default_factory=DefaultMapperConfig
)
session_storage
class-attribute
instance-attribute
¶
session_storage: BaseSessionStorage | None = None
app_fingerprint
class-attribute
instance-attribute
¶
app_fingerprint: ApkBuildFingerprint | None = None
restore_user_agent_from_session
class-attribute
instance-attribute
¶
restore_user_agent_from_session: bool = True
autochange_app_version_if_current_unsupported
class-attribute
instance-attribute
¶
autochange_app_version_if_current_unsupported: bool = True
sync
class-attribute
instance-attribute
¶
sync: SyncOverrides = Field(default_factory=SyncOverrides)
validate_version_api_aliases ¶
validate_version_api_aliases() -> Self
Source code in src/pyromax/config.py
559 560 561 562 563 | |
resolve_app_version ¶
resolve_app_version() -> None
Apply an explicit app version to a compatible user agent.
Source code in src/pyromax/config.py
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
resolve_app_fingerprint
async
¶
resolve_app_fingerprint() -> None
Resolve and apply an Android APK fingerprint when requested.
Source code in src/pyromax/config.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 | |
validate_transport
classmethod
¶
validate_transport(data: Any) -> Any
Source code in src/pyromax/config.py
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 | |
config_rebuild ¶
config_rebuild(
transport: TransportRegistry | None,
encoding: EncodingRegistry | None,
protocol: ProtocolRegistry | None,
mapper: MapperRegistry | None,
) -> ExtraConfig
Source code in src/pyromax/config.py
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 | |
SocketTransportConfig ¶
WebSocketTransportConfig ¶
Bases: BaseTransportConfig
user_agent_header
class-attribute
instance-attribute
¶
user_agent_header: str = DEFAULT_WEB_HEADER_USER_AGENT
JsonEncodingConfig ¶
Bases: BaseEncodingConfig
MsgPackDictEncodingConfig ¶
Bases: BaseEncodingConfig
EnvelopeProtocolConfig ¶
Bases: BaseProtocolConfig
EnvelopeMapperConfigV11 ¶
Bases: BaseMapperConfig
user_agent_config
class-attribute
instance-attribute
¶
user_agent_config: BaseEnvelopeMappingUserAgentConfigV11 = (
WebEnvelopeMappingUserAgentConfigV11()
)
registration_config
class-attribute
instance-attribute
¶
registration_config: RegistrationConfig | None = None
circuit_breakers
class-attribute
instance-attribute
¶
circuit_breakers: MappingCircuitBreakersConfig = Field(
default_factory=MappingCircuitBreakersConfig
)
validate_config ¶
validate_config() -> Self
Source code in src/pyromax/config.py
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
CircuitBreakerConfig ¶
Bases: BaseConfig
Failure policy for one category of operations.
failure_threshold
class-attribute
instance-attribute
¶
failure_threshold: int = Field(default=1, ge=1)
recovery_timeout
class-attribute
instance-attribute
¶
recovery_timeout: float = Field(default=1.0, ge=0)
backoff_factor
class-attribute
instance-attribute
¶
backoff_factor: float = Field(default=2.75, ge=1)
max_recovery_timeout
class-attribute
instance-attribute
¶
max_recovery_timeout: float = Field(default=30.0, ge=0)
validate_recovery_timeouts ¶
validate_recovery_timeouts() -> Self
Source code in src/pyromax/config.py
338 339 340 341 342 343 344 | |
MappingCircuitBreakersConfig ¶
Bases: BaseConfig
Independent failure policies for mapper transport and API errors.
WebEnvelopeMappingUserAgentConfigV11 ¶
Bases: BaseEnvelopeMappingUserAgentConfigV11
device_id
class-attribute
instance-attribute
¶
device_id: str = Field(default_factory=get_random_device_id)
header_user_agent
class-attribute
instance-attribute
¶
header_user_agent: str = DEFAULT_WEB_HEADER_USER_AGENT
client_session_id
class-attribute
instance-attribute
¶
client_session_id: int = Field(
default_factory=lambda: round(time() * 1000)
)
DesktopEnvelopeMappingUserAgentConfigV11 ¶
Bases: BaseEnvelopeMappingUserAgentConfigV11
device_id
class-attribute
instance-attribute
¶
device_id: str = Field(
default_factory=get_random_device_id_numeric
)
AndroidEnvelopeMappingUserAgentConfigV11 ¶
Bases: BaseEnvelopeMappingUserAgentConfigV11
device_id
class-attribute
instance-attribute
¶
device_id: str = Field(default_factory=lambda: str(uuid4()))
mt_instance_id
class-attribute
instance-attribute
¶
mt_instance_id: str = Field(
default_factory=lambda: str(uuid4())
)
from_session_info
classmethod
¶
from_session_info(
session_info: SessionInfo, *args: Any, **kwargs: Any
) -> Self
Source code in src/pyromax/config.py
292 293 294 295 296 297 298 299 300 301 302 303 304 | |
Sessions¶
session ¶
BaseSessionStorage ¶
Bases: ABC
save_session
async
¶
save_session(
session_info: SessionInfo, session_key: SessionKey
) -> None
Source code in src/pyromax/session/base.py
13 14 15 | |
load_session
async
¶
load_session(session_key: SessionKey) -> SessionInfo | None
Source code in src/pyromax/session/base.py
16 | |
update_session
async
¶
update_session(
session_key: SessionKey, session_info: SessionInfo
) -> None
Source code in src/pyromax/session/base.py
17 18 19 | |
delete_session
async
¶
delete_session(session_key: SessionKey) -> None
Source code in src/pyromax/session/base.py
20 | |
close
async
¶
close() -> None
Source code in src/pyromax/session/base.py
21 | |
AioSqLiteSessionStorage ¶
AioSqLiteSessionStorage(
work_dir: str, db_name: str | None = "session.db"
)
Bases: BaseSessionStorage
Source code in src/pyromax/session/aiosqlite.py
27 28 29 30 31 32 33 34 35 | |
save_session
async
¶
save_session(
session_info: SessionInfo, session_key: SessionKey
) -> None
Source code in src/pyromax/session/aiosqlite.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
load_session
async
¶
load_session(session_key: SessionKey) -> SessionInfo | None
Source code in src/pyromax/session/aiosqlite.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
update_session
async
¶
update_session(
session_key: SessionKey, session_info: SessionInfo
) -> None
Source code in src/pyromax/session/aiosqlite.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
delete_session
async
¶
delete_session(session_key: SessionKey) -> None
Source code in src/pyromax/session/aiosqlite.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
delete_all_sessions
async
¶
delete_all_sessions() -> None
Source code in src/pyromax/session/aiosqlite.py
305 306 307 308 309 310 311 312 | |
close
async
¶
close() -> None
Source code in src/pyromax/session/aiosqlite.py
314 315 316 317 318 319 320 321 322 323 324 325 326 | |
Authentication interaction¶
interaction ¶
__all__
module-attribute
¶
__all__ = [
"BaseInteractor",
"AuthInteractor",
"TerminalAuthInteractor",
"AuthCallbacks",
"PasswordRequest",
]
AuthCallbacks
dataclass
¶
AuthCallbacks(
qr_url: Callable[[str], Awaitable[None]] | None = None,
sms_code: (
Callable[[str], Awaitable[str | int]] | None
) = None,
password: (
Callable[[PasswordRequest], Awaitable[str]] | None
) = None,
)
AuthInteractor ¶
Bases: BaseInteractor
Interaction contract required by the built-in authentication flow.
show_qr
abstractmethod
async
¶
show_qr(url: str) -> None
Source code in src/pyromax/interaction/auth.py
30 31 | |
request_sms_code
abstractmethod
async
¶
request_sms_code(phone: str) -> str
Source code in src/pyromax/interaction/auth.py
33 34 | |
request_password
abstractmethod
async
¶
request_password(request: PasswordRequest) -> str
Source code in src/pyromax/interaction/auth.py
36 37 | |
PasswordRequest
dataclass
¶
PasswordRequest(track_id: str, phone: str | None = None)
BaseInteractor ¶
Bases: ABC
Base class for user interaction implementations.
The class intentionally has no domain-specific methods. Authentication and future interaction areas extend it with their own contracts.
TerminalAuthInteractor ¶
TerminalAuthInteractor(
callbacks: AuthCallbacks | None = None,
)
Bases: AuthInteractor
Default auth interaction using callbacks with terminal fallbacks.
Source code in src/pyromax/interaction/terminal.py
16 17 | |
show_qr
async
¶
show_qr(url: str) -> None
Source code in src/pyromax/interaction/terminal.py
23 24 25 26 27 28 29 30 31 | |
request_sms_code
async
¶
request_sms_code(phone: str) -> str
Source code in src/pyromax/interaction/terminal.py
33 34 35 36 37 38 39 40 41 42 43 44 45 | |
request_password
async
¶
request_password(request: PasswordRequest) -> str
Source code in src/pyromax/interaction/terminal.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
Encodings¶
encoding ¶
__all__
module-attribute
¶
__all__ = [
"BaseEncoding",
"BaseSymmetricEncoding",
"DictAndBytesEncoding",
"SocketEncoding",
"JsonEncoding",
"NoEncoding",
"MsgPackDictEncoding",
]
BaseEncoding ¶
BaseEncoding(extra_config: ExtraConfig)
Bases: ABC, Generic[ENCODE_IN_TYPE, ENCODE_OUT_TYPE, DECODE_IN_TYPE, DECODE_OUT_TYPE]
Source code in src/pyromax/encoding/base.py
19 20 | |
encode
abstractmethod
¶
encode(
data: ENCODE_IN_TYPE, *args: Any, **kwargs: Any
) -> ENCODE_OUT_TYPE
Encode the given data to the given encoding type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ENCODE_IN_TYPE
|
The data to encode. |
required |
Source code in src/pyromax/encoding/base.py
22 23 24 25 26 27 28 29 30 31 | |
decode
abstractmethod
¶
decode(
data: DECODE_IN_TYPE, *args: Any, **kwargs: Any
) -> DECODE_OUT_TYPE
Decode the given data to the given decoded type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DECODE_IN_TYPE
|
The data to decode. |
required |
Returns:
| Type | Description |
|---|---|
DECODE_OUT_TYPE
|
|
Source code in src/pyromax/encoding/base.py
33 34 35 36 37 38 39 40 41 42 43 | |
BaseSymmetricEncoding ¶
BaseSymmetricEncoding(extra_config: ExtraConfig)
Bases: BaseEncoding[DECODED_TYPE, ENCODED_TYPE, ENCODED_TYPE, DECODED_TYPE], Generic[ENCODED_TYPE, DECODED_TYPE]
a subtype of the basic encoding, for encodings that work symmetrically, i.e. they accept one type of data for encoding and return another, and for decoding the same data types are used, but in the opposite way, i.e. the data type returned from encoding is accepted, and the data type that was originally encoded is returned
Source code in src/pyromax/encoding/base.py
19 20 | |
DictAndBytesEncoding ¶
DictAndBytesEncoding(extra_config: ExtraConfig)
Bases: SocketEncoding[bytes, dict[Any, Any]]
Replacement of JsonAndBytesEncoding since, due to architectural changes, EnvelopeProtocol is no longer tied to Json and now the encoding does not need to specifically serialize data in Json.
Source code in src/pyromax/encoding/base.py
19 20 | |
SocketEncoding ¶
SocketEncoding(extra_config: ExtraConfig)
Bases: BaseSymmetricEncoding[ENCODED_TYPE, DECODED_TYPE]
Encoding for Socket transport, it is assumed that the socket transport will expect a subtype of this class, and with its help understand how many bytes to read from the bus. This is done to avoid mixing abstraction levels, and the "dumb" transport is not responsible for the message structure, but simply reads bytes from the bus. Simply put, the socket transport delegates the work with the message size to it.
Source code in src/pyromax/encoding/base.py
19 20 | |
HEADER_SIZE
abstractmethod
property
¶
HEADER_SIZE: int
Get the minimum size to read from the bus (i.e., the header size) to further understand how many more bytes need to be read from the bus.
Returns:
| Type | Description |
|---|---|
int
|
Header size (number of bytes). |
unpack_header_to_get_payload_length
abstractmethod
¶
unpack_header_to_get_payload_length(data: bytes) -> int
Unpack the bytes header, obtained using HEADER_SIZE
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
bytes
|
bytes of header |
required |
Returns:
| Type | Description |
|---|---|
int
|
the length of the remaining message(payload) |
Source code in src/pyromax/encoding/base.py
87 88 89 90 91 92 93 94 95 96 97 | |
MsgPackDictEncoding ¶
MsgPackDictEncoding(extra_config: ExtraConfig)
Bases: DictAndBytesEncoding
An encoding implementation suitable for use with the Envelope protocol and socket transport determines the size of the socket message header and provides an implementation for obtaining the message length from the header. Serializes Json data into bytes and deserializes bytes into Json.
Source code in src/pyromax/encoding/MsgPack.py
32 33 34 | |
encode ¶
encode(
data: str | dict[Any, Any], *args: Any, **kwargs: Any
) -> bytes
Source code in src/pyromax/encoding/MsgPack.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
unpack_header_to_get_payload_length ¶
unpack_header_to_get_payload_length(data: bytes) -> int
Source code in src/pyromax/encoding/MsgPack.py
76 77 78 | |
decode ¶
decode(
data: bytes, *args: Any, **kwargs: Any
) -> dict[Any, Any]
Source code in src/pyromax/encoding/MsgPack.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
Transports¶
transport ¶
BaseTransport ¶
BaseTransport(
encoding: ENCODING_TYPE,
extra_config: ExtraConfig,
*args: Any,
**kwargs: Any
)
Bases: AsyncInitializerMixin, Generic[ENCODING_TYPE]
Source code in src/pyromax/transport/bases/base.py
30 31 32 33 34 35 36 37 | |
WebSocketTransport ¶
WebSocketTransport(
encoding: BaseEncoding[Any, Any, Any, Any],
extra_config: ExtraConfig,
*args: Any,
**kwargs: Any
)
Bases: StreamTransport[BaseEncoding[Any, Any, Any, Any]]
Initialize the web socket transport.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Resource URL. |
required |
origin
|
str
|
The origin value. |
required |
user_agent_header
|
str
|
The user agent header value. |
required |
Source code in src/pyromax/transport/websocket.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
connect
async
¶
connect(**kwargs: Any) -> None
Connect.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kwargs
|
Any
|
Keyword arguments forwarded to the wrapped callable. |
{}
|
Raises:
| Type | Description |
|---|---|
ConnectTransportError
|
If connection handshake timed out or handle unknown error. |
Source code in src/pyromax/transport/websocket.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
close
async
¶
close() -> None
Close.
Source code in src/pyromax/transport/websocket.py
132 133 134 135 136 137 138 139 140 141 | |
send
async
¶
send(data: str | bytes) -> None
Send.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | bytes
|
Contextual data passed through the processing pipeline. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If data must be str or bytes. |
SendingTransportError
|
If you try to send before initialization connection. |
Source code in src/pyromax/transport/websocket.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
recv
async
¶
recv() -> Any
Recv.
Returns:
| Type | Description |
|---|---|
Any
|
The value returned by backend. |
Raises:
| Type | Description |
|---|---|
ConnectionTransportError
|
If you try to recv before initialization connection. |
Source code in src/pyromax/transport/websocket.py
163 164 165 166 167 168 169 170 171 172 173 | |
SocketTransport ¶
SocketTransport(
encoding: SocketEncoding[Any, Any],
extra_config: ExtraConfig,
*args: Any,
**kwargs: Any
)
Bases: StreamTransport[SocketEncoding[Any, Any]]
Initialize the socket transport.
Source code in src/pyromax/transport/socket.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
BASE_EXCEPTION_FOR_TRANSPORT
class-attribute
instance-attribute
¶
BASE_EXCEPTION_FOR_TRANSPORT = BaseTransportError
OTHER_EXCEPTIONS_FOR_TRANSPORT
class-attribute
instance-attribute
¶
OTHER_EXCEPTIONS_FOR_TRANSPORT = [
ConnectionTransportError,
SendingTransportError,
]
send
async
¶
send(request: bytes) -> None
Send.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
bytes
|
Protocol request envelope to populate or send. |
required |
Source code in src/pyromax/transport/socket.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
recv
async
¶
recv() -> Any
Recv.
Returns:
| Type | Description |
|---|---|
Any
|
The bytes of one message returned by backend. |
Raises:
| Type | Description |
|---|---|
ConnectionTransportError
|
If connection broken/shutdown while receiving. |
Source code in src/pyromax/transport/socket.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
connect
async
¶
connect(**kwargs: Any) -> None
Connect.
:param kwargs: Keyword arguments forwarded to the wrapped callable.¶
:type kwargs: Any¶
Raises:
| Type | Description |
|---|---|
ConnectTransportError
|
If handler unknown error. |
Source code in src/pyromax/transport/socket.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
close
async
¶
close() -> None
Close.
Source code in src/pyromax/transport/socket.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
Protocols¶
protocol ¶
BaseMaxProtocol ¶
BaseMaxProtocol(
transport: BaseTransport[Any],
encoding: BaseEncoding[Any, Any, Any, Any],
extra_config: ExtraConfig,
*args: Any,
**kwargs: Any
)
Bases: AsyncInitializerMixin, Generic[T, R, TRANSPORT_TYPE]
Source code in src/pyromax/protocol/bases/base.py
35 36 37 38 39 40 41 42 43 | |
transport
abstractmethod
property
¶
transport: BaseTransport[Any]
Transport.
Returns:
| Type | Description |
|---|---|
BaseTransport
|
The resulting BaseTransport value. |
send
abstractmethod
async
¶
send(
method: BaseMaxProtocolMethod[T],
data: Any | None = None,
) -> Awaitable[R]
Send.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
BaseMaxProtocolMethod[T]
|
BaseMaxProtocolMethod[T] instance to process. |
required |
data
|
Any | None
|
Contextual data passed through the processing pipeline. |
None
|
Returns:
| Type | Description |
|---|---|
Awaitable[R]
|
The resulting Awaitable[R] value. |
Source code in src/pyromax/protocol/bases/base.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
get_updates
abstractmethod
async
¶
get_updates() -> Iterable[Any]
Retrieve updates.
Returns:
| Type | Description |
|---|---|
Iterable[Any]
|
The resulting collection. |
Source code in src/pyromax/protocol/bases/base.py
60 61 62 63 64 65 66 67 | |
StreamMaxProtocol ¶
StreamMaxProtocol(
transport: BaseTransport[Any],
encoding: BaseEncoding[Any, Any, Any, Any],
extra_config: ExtraConfig,
*args: Any,
**kwargs: Any
)
Bases: BaseMaxProtocol[T, R, TRANSPORT_TYPE], Generic[T, R, TRANSPORT_TYPE]
Source code in src/pyromax/protocol/bases/base.py
35 36 37 38 39 40 41 42 43 | |
transport
abstractmethod
property
¶
transport: TRANSPORT_TYPE
Transport.
Returns:
| Type | Description |
|---|---|
StreamTransport
|
The resulting StreamTransport value. |
connect
abstractmethod
async
¶
connect(gen: int) -> None
Connect the protocol transport and start its response reader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gen
|
int
|
The current error gen. |
required |
Raises:
| Type | Description |
|---|---|
ConnectProtocolError
|
If the transport cannot be connected. |
Source code in src/pyromax/protocol/bases/StreamProtocol.py
11 12 13 14 15 16 17 18 19 20 21 | |
close
abstractmethod
async
¶
close() -> None
Close.
Source code in src/pyromax/protocol/bases/StreamProtocol.py
23 24 25 26 | |
EnvelopeProtocol ¶
EnvelopeProtocol(
transport: StreamTransport[
BaseEncoding[Any, Any, Any, Any]
],
encoding: BaseEncoding[Any, Any, Any, Any],
extra_config: ExtraConfig,
)
Bases: StreamMaxProtocol[Envelope, Envelope, StreamTransport[BaseEncoding[Any, Any, Any, Any]]]
Initialize the envelope protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transport
|
StreamTransport[BaseEncoding[Any, Any, Any, Any]]
|
Transport instance. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If transport must be StreamTransport. |
Source code in src/pyromax/protocol/envelope/envelope.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
exceptions_callback
instance-attribute
¶
exceptions_callback: (
Callable[[Exception, int, str], Any] | None
) = None
transport
property
¶
transport: StreamTransport[BaseEncoding[Any, Any, Any, Any]]
Transport.
Returns:
| Type | Description |
|---|---|
StreamTransport
|
The using transport. |
set_generation_getter ¶
set_generation_getter(
generation_getter: Callable[..., Awaitable[int]] | None,
) -> None
Set generation getter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
generation_getter
|
Callable[..., Awaitable[int]] | None
|
Callable to invoke. |
required |
Source code in src/pyromax/protocol/envelope/envelope.py
115 116 117 118 119 120 121 122 123 | |
set_exceptions_callback ¶
set_exceptions_callback(
exceptions_callback: (
Callable[[Exception, int, str], Any] | None
),
) -> None
Set exceptions callback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exceptions_callback
|
Callable[[Exception, int, str], Any] | None
|
Callable to invoke. |
required |
Source code in src/pyromax/protocol/envelope/envelope.py
125 126 127 128 129 130 131 132 133 | |
connect
async
¶
connect(current_gen: int) -> None
Connect the protocol transport and start its response reader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_gen
|
int
|
The current gen value. |
required |
Raises:
| Type | Description |
|---|---|
ConnectProtocolError
|
If the transport cannot be connected. |
Source code in src/pyromax/protocol/envelope/envelope.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
close
async
¶
close(
pending_requests_exc: Exception | None = None,
) -> None
Close.
Source code in src/pyromax/protocol/envelope/envelope.py
310 311 312 313 314 315 316 | |
send
async
¶
send(
method: BaseMaxProtocolMethod[Envelope],
data: Any | None = None,
) -> Future[Envelope]
send a envelope
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
BaseMaxProtocolMethod[Envelope]
|
BaseMaxProtocolMethod[Envelope] instance to process. |
required |
data
|
Any | None
|
Contextual data passed through the processing pipeline. |
None
|
Returns:
| Type | Description |
|---|---|
Future[Envelope]
|
The envelope populated with the request opcode and payload. |
Raises:
| Type | Description |
|---|---|
SendingProtocolError
|
If the operation fails. :raises AlreadyCancelledError: If the operation fails.¶ |
SendingProtocolError
|
If you try to send something before protocol init(event router is None). |
TypeError
|
If data must be dict instance. |
Source code in src/pyromax/protocol/envelope/envelope.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
receive_reader
async
¶
receive_reader(gen: int) -> None
Receive reader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gen
|
int
|
The gen value. |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no event router while receive. |
Source code in src/pyromax/protocol/envelope/envelope.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | |
get_updates
async
¶
get_updates() -> Iterable[Envelope]
get updates from event router
Returns:
| Type | Description |
|---|---|
Iterable[Envelope]
|
The envelope populated with the request opcode and payload. |
Raises:
| Type | Description |
|---|---|
GetUpdatesProtocolError
|
If the operation fails. |
Source code in src/pyromax/protocol/envelope/envelope.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |
from_request
async
¶
from_request(request_data: dict[str, Any]) -> Envelope
From request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request_data
|
dict[str, Any]
|
dict[str, Any] instance to process. |
required |
Returns:
| Type | Description |
|---|---|
Envelope
|
The envelope populated with the request opcode and payload. |
Raises:
| Type | Description |
|---|---|
BaseProtocolError
|
If no event router while parse request. |
Source code in src/pyromax/protocol/envelope/envelope.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | |
from_response ¶
from_response(data: dict[str, Any]) -> Envelope
From response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
Contextual data passed through the processing pipeline. |
required |
Returns:
| Type | Description |
|---|---|
Envelope
|
The envelope populated with the request opcode and payload. |
Source code in src/pyromax/protocol/envelope/envelope.py
505 506 507 508 509 510 511 512 513 | |
Request ¶
Bases: ABC, Generic[T_response]
is_my_response
abstractmethod
¶
is_my_response(response: T_response) -> bool
Return whether my response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
T_response
|
Protocol response to process. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True when the requested condition is satisfied; otherwise False. |
Source code in src/pyromax/protocol/bases/request_response.py
24 25 26 27 28 29 30 31 32 33 | |
__hash__
abstractmethod
¶
__hash__() -> int
Hash.
Returns:
| Type | Description |
|---|---|
int
|
The resulting int value. |
Source code in src/pyromax/protocol/bases/request_response.py
35 36 37 38 39 40 41 42 | |
Response ¶
Bases: ABC
Mappers¶
mapping ¶
EnvelopeMapperV11 ¶
EnvelopeMapperV11(
protocol: EnvelopeProtocol, extra_config: ExtraConfig
)
Bases: FullMixin
Source code in src/pyromax/mapping/envelope/v11/mixins/construct.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
listen_updates ¶
listen_updates(
context: Any,
) -> tuple[
Callable[[Response], Response | BaseMaxObject],
AsyncGenerator[Response, None],
]
Listen for updates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
Any
|
Runtime context used while processing the request. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Callable[[Response], Response | BaseMaxObject], AsyncGenerator[Response, None]]
|
Items produced by the iterator. |
Source code in src/pyromax/mapping/envelope/v11/Mapper.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
High-level methods¶
BaseMaxApiMethod ¶
Bases: ContextController, BaseModel, Generic[T], ABC
__call__
abstractmethod
async
¶
__call__(*args: Any, **kwargs: Any) -> T | Any
Execute the base max api MAX API method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Any
|
Positional arguments forwarded to the wrapped callable. |
()
|
kwargs
|
Any
|
Keyword arguments forwarded to the wrapped callable. |
{}
|
Returns:
| Type | Description |
|---|---|
T | Any
|
The resulting T | Any value. |
Source code in src/pyromax/methods/Base.py
13 14 15 16 17 18 19 20 21 22 23 24 | |
Versions¶
versions ¶
__all__
module-attribute
¶
__all__ = [
"ApkBuildFingerprint",
"VersionAlreadyExistsError",
"VersionApi",
"VersionCatalog",
"VersionNotFoundError",
]
ApkBuildFingerprint ¶
Bases: BaseModel
Hashes and build metadata for one Android MAX release.
so_meta_sha256_arm64_v8a
class-attribute
instance-attribute
¶
so_meta_sha256_arm64_v8a: str | None = None
VersionAlreadyExistsError ¶
VersionAlreadyExistsError(version: str)
Bases: ValueError
Raised when adding a version that is already in the catalog.
Source code in src/pyromax/exceptions/VersionError.py
11 12 | |
VersionNotFoundError ¶
VersionNotFoundError(version: str)
Bases: ValueError
Raised when an application version is absent from the catalog.
Source code in src/pyromax/exceptions/VersionError.py
4 5 | |
VersionApi ¶
VersionApi(remote_url: str | None = None)
Catalog of Android MAX versions and their APK fingerprints.
Built-in versions are available immediately. When remote_url is set,
:meth:load merges that remote catalog over the bundled data.
Network, HTTP, JSON, and validation errors are intentionally propagated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
remote_url
|
str | None
|
Optional URL fetched when :meth: |
None
|
Source code in src/pyromax/versions/catalog.py
23 24 25 26 | |
recommended
staticmethod
¶
recommended() -> str
Return the application version used by mobile clients by default.
Source code in src/pyromax/versions/catalog.py
28 29 30 31 32 | |
recommended_pair ¶
recommended_pair() -> tuple[str, int]
Return the recommended app version and its build number.
Source code in src/pyromax/versions/catalog.py
34 35 36 37 38 | |
load
async
¶
load() -> VersionApi
Load and merge remote versions when remote loading is enabled.
Source code in src/pyromax/versions/catalog.py
40 41 42 43 44 45 | |
add ¶
add(
version: str,
fingerprint: ApkBuildFingerprint,
override: bool = False,
) -> None
Add a version to this catalog.
Source code in src/pyromax/versions/catalog.py
47 48 49 50 51 52 53 54 55 56 57 | |
resolve ¶
resolve(version: str) -> ApkBuildFingerprint
Resolve a version or raise :class:VersionNotFoundError.
Source code in src/pyromax/versions/catalog.py
59 60 61 62 63 64 65 | |
fetch
async
¶
fetch() -> dict[str, ApkBuildFingerprint]
Source code in src/pyromax/versions/catalog.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
Dispatcher modes¶
UpdateTranslationFailure
dataclass
¶
UpdateTranslationFailure(exception: Exception)
Translation failure exposed to raw update middlewares through data.
Circuit breaker¶
circuit_breaker ¶
CircuitBreakerState ¶
CircuitBreaker ¶
CircuitBreaker(
failure_threshold: int = 1,
recovery_timeout: float = 1.0,
*,
max_cycles: int = 5,
backoff_factor: float = 2.0,
max_recovery_timeout: float = 30.0,
wait_when_open: bool = True,
name: str | None = None,
time_func: Callable[[], float] = time.monotonic
)
Async circuit breaker for logical operations.
Failures are counted consecutively. Once failure_threshold is reached,
calls fail fast until recovery_timeout has elapsed. Exactly one call is
then admitted as a half-open probe. Failed probes increase the recovery
timeout by backoff_factor up to max_recovery_timeout.
Source code in src/pyromax/utils/circuit_breaker.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
before_call
async
¶
before_call() -> _CircuitBreakerPermit
Admit a call or raise when the circuit is not ready.
Source code in src/pyromax/utils/circuit_breaker.py
98 99 100 101 102 103 104 105 106 107 108 109 | |
wait_for_call
async
¶
wait_for_call() -> _CircuitBreakerPermit
Wait for the cooldown and acquire the next available call permit.
Source code in src/pyromax/utils/circuit_breaker.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
wait_until_available
async
¶
wait_until_available() -> None
Wait until a call may attempt to acquire the circuit.
Source code in src/pyromax/utils/circuit_breaker.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
record_success
async
¶
record_success(permit: _CircuitBreakerPermit) -> None
Record a successful admitted call.
Source code in src/pyromax/utils/circuit_breaker.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
record_failure
async
¶
record_failure(permit: _CircuitBreakerPermit) -> None
Record a dependency failure for an admitted call.
Source code in src/pyromax/utils/circuit_breaker.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
record_ignored
async
¶
record_ignored(permit: _CircuitBreakerPermit) -> None
Release a cancelled half-open probe without counting a failure.
Source code in src/pyromax/utils/circuit_breaker.py
201 202 203 204 205 206 207 208 209 | |
reset
async
¶
reset() -> None
Close the circuit and clear its failure history.
Source code in src/pyromax/utils/circuit_breaker.py
211 212 213 214 215 216 217 218 219 | |
Registry decorators¶
register_transport ¶
register_transport(
transport: str,
) -> Callable[
[type[BaseTransport[Any]]], type[BaseTransport[Any]]
]
Register transport.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transport
|
str
|
name of the transport. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[type[BaseTransport]], type[BaseTransport]]
|
The decorator Callable[[type[BaseTransport]], type[BaseTransport]]. |
Source code in src/pyromax/transport/registry.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
register_encoding ¶
register_encoding(
encoding: str,
) -> Callable[
[type[BaseEncoding[Any, Any, Any, Any]]],
type[BaseEncoding[Any, Any, Any, Any]],
]
Register protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoding
|
str
|
name of protocol. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[type[BaseMaxProtocol[Any, Any]]], type[BaseMaxProtocol[Any, Any]]]
|
The resulting Callable[[type[BaseMaxProtocol[Any, Any]]], type[BaseMaxProtocol[Any, Any]]] value. |
Source code in src/pyromax/encoding/registry.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
register_protocol ¶
register_protocol(
protocol: str,
) -> Callable[
[type[BaseMaxProtocol[Any, Any]]],
type[BaseMaxProtocol[Any, Any]],
]
Register protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
protocol
|
str
|
name of protocol. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[type[BaseMaxProtocol[Any, Any]]], type[BaseMaxProtocol[Any, Any]]]
|
The resulting Callable[[type[BaseMaxProtocol[Any, Any]]], type[BaseMaxProtocol[Any, Any]]] value. |
Source code in src/pyromax/protocol/registry.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
register_mapper ¶
register_mapper(
mapper: str,
) -> Callable[
[type[BaseMapper[Any, Any]]], type[BaseMapper[Any, Any]]
]
Register mapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapper
|
str
|
Mapper backend or mapper instance. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[type[BaseMapper[Any, Any]]], type[BaseMapper[Any, Any]]]
|
The resulting Callable[[type[BaseMapper[Any, Any]]], type[BaseMapper[Any, Any]]] value. |
Source code in src/pyromax/mapping/registry.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |