Client API Gateway¶
Tryx
¶
Tryx(backend: BackendBase | FfiStoreProtocol | StoreBase)
Main automation runtime controller.
Use this class to register event handlers and start the connection lifecycle.
Accepts any of the 3 storage backend tiers:
SqliteStore— built-in SQLite backendFfiStoreProtocol— native FFI backend (e.g. tryx-store-postgres)StoreBasesubclass — pure Python custom backend
Create a Tryx runtime with the given storage backend.
| PARAMETER | DESCRIPTION |
|---|---|
backend
|
Storage backend (SqliteStore, FfiStoreProtocol, or StoreBase).
TYPE:
|
Example::
from tryx.backend import SqliteStore
from tryx.client import Tryx
app = Tryx(SqliteStore('session.db'))
Methods:¶
get_client
¶
Return the connected client facade.
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If the client is not yet running. |
Example::
client = app.get_client()
await client.send_text(to=JID('123', 's.whatsapp.net'), text='hi')
on
¶
on(
event_type: type[EventT],
) -> Callable[
[Callable[[TryxClient, EventT], Awaitable[None]]],
Callable[[TryxClient, EventT], Awaitable[None]],
]
Decorator to register an async event handler.
Example::
@app.on(EvMessage)
async def handler(client: TryxClient, event: EvMessage) -> None:
text = event.data.get_text()
chat = event.data.message_info.source.chat
await client.send_text(to=chat, text=text)
run_blocking
¶
Start the client and block until it exits.
Example::
app.run_blocking()
TryxClient is the runtime facade passed to every handler, and it exposes
a root messaging surface plus 12 namespace clients.
How to read this section
- Start with this gateway page.
- Open the namespace page that matches your task.
- Jump to Events API for event contracts and Types API for enum/value-object constraints.
Client Topology¶
flowchart TD
A[TryxClient] --> B[Root send/download/upload methods]
A --> C[contact]
A --> D[chat_actions]
A --> E[community]
A --> F[newsletter]
A --> G[groups]
A --> H[status]
A --> I[chatstate]
A --> J[blocking]
A --> K[polls]
A --> L[presence]
A --> M[privacy]
A --> N[profile]
Namespace Router¶
Contact Find users, check registration state, fetch profile pictures
Chat Actions Archive, pin, mute, read-state, edit/revoke/react
Groups Group lifecycle, membership approval, participant admin
Community Community creation, subgroup management
Newsletter Channel subscription, posting, follower management
Status Status updates with privacy controls
Chatstate Typing and recording indicators
Blocking Block/unblock and blocklist queries
Polls Encrypted poll creation and vote aggregation
Presence Online/offline presence and subscriptions
Privacy Privacy settings and disallowed lists
Profile Push name, status text, profile picture
Root Transport Methods¶
These methods stay on TryxClient directly because they are cross-domain
primitives.
| Method | Purpose | Typical Usage |
|---|---|---|
is_connected() |
Connection health check | Guard before sends |
download_media(message) |
Download media blob | Save image/audio/document |
upload_file(path, media_type) |
Upload file for later use | Status media workflows |
upload(data, media_type) |
Upload in-memory bytes | Transform pipelines |
send_message(to, message) |
Raw protobuf send | Advanced custom payloads |
send_text(...) |
Text helper | Most command handlers |
send_photo(...) |
Image helper | Replies with screenshots |
send_document(...) |
File helper | Reports, exports |
send_audio(...) |
Audio helper | Voice notes / TTS |
send_video(...) |
Video helper | Clips, demos |
send_gif(...) |
GIF helper | Motion responses |
send_sticker(...) |
Sticker helper | Lightweight reactions |
request_media_reupload(...) |
Recover stale media | Retry failed downloads |
Reconnect-safe pattern
Avoid caching TryxClient on global module state across runtime
restarts. Always use the client object injected in the current
handler call.
Practical Flow by Goal¶
Use root send methods + chat_actions + chatstate.
- Parse incoming event.
- Signal typing with
client.chatstate.send_composing(chat). - Send reply with
client.send_text(...). - Optional message edit/revoke via
client.chat_actions.
Use groups, blocking, privacy.
- Resolve sender via Types API.
- Apply participant actions (
promote,remove,approve request). - Enforce policy with blocklist/privacy settings.
Use status, newsletter, polls.
- Upload content or build text payload.
- Publish status/newsletter message.
- Track engagement using polls and reactions.
Cross-References¶
- Event contracts: Events API
- Shared value objects: Types API
- Builders and utility helpers: Helpers API
- End-to-end client composition: Tutorial: Command Automation