English فارسی

Raw RPC escape hatch

83 methods have convenience wrappers. The other 600 are reachable through one function that still gives you typed encoding and a parsed response.

The one function you need

async call(service, method, payload=None) → protobuf message

Looks up the request type, fills it from your dict, sends it over the multiplexed WebSocket, then parses the response into the response type.

result = await client.call(
    "bale.poll.v1.Poll",
    "GetPollResults",
    {"pollId": 123},
)

print(result.describe())
print(dynamic.to_dict(result))

Finding the method you need

# every pair, 683 of them
for pair in client.methods()[:5]:
    print(pair)

# substring search
print(client.find("poll"))
print(client.find("story"))

# the full signature
print(client.describe("bale.poll.v1.Poll", "CreatePoll"))

Or from the shell, without Python:

bale-xyz search poll
bale-xyz methods -s bale.poll.v1.Poll
bale-xyz describe bale.story.v1.Story CreateStory

Typed proxies

client.api is a helper that returns a service proxy for a dotted name, so you get attribute access and editor completion instead of string pairs:

polls = client.api("bale.poll.v1.Poll")

print(polls.GetPollResults)                 # the proxy is introspectable
result = await polls.GetPollResults({"pollId": 123})

The proxy resolves names case-insensitively, so getpollresults also works. Snake_case is not translated — use the exact CamelCase spelling for clarity:

await client.api("bale.users.v1.Users").GetMe({})

Raw dicts instead of messages

data = await client.invoke("bale.users.v1.Users", "GetMe", {})
print(data["users"][0]["id"])      # plain snake_case dict

Streaming

async for chunk in client.rpc_stream("bale.messaging.v2.Messaging", "SomeStreaming", {}):
    print(chunk)

Manual encoding

Sometimes you want the bytes without a connection — for tests, for comparison against a capture, or to build a fixture:

from balexyz import dynamic

raw = dynamic.encode("bale.meet.v1.Meet", "GenerateCallLink", {"isPublic": True})
print(raw.hex())          # 0801

back = dynamic.decode("bale.meet.v1.Meet", "GenerateCallLink", bytes.fromhex("0801"))
print(dynamic.to_dict(back))   # {"is_public": True}
HelperPurpose
dynamic.encode(service, method, dict)Request message → bytes
dynamic.decode(service, method, bytes)Bytes → request message
dynamic.request_type(service, method)The generated message class
dynamic.response_type(service, method)Same for the response
dynamic.describe(service, method)Human-readable signature
dynamic.to_dict(message)Message → snake_case dict
dynamic.named_type("request.Metadata")Envelope types by name

Handling RPC errors

from balexyz import RpcError, FloodWait

try:
    await client.call("bale.groups.v1.Groups", "GetGroup", {"groupId": 1})
except FloodWait as exc:
    await asyncio.sleep(exc.seconds)
except RpcError as exc:
    print(exc.code, exc.message, exc.reason)

Server-fetched values

Some payloads need an access_hash or fileId that only the server knows. Fetch the entity first, then reuse its fields:

chat = await client.get_group_info("987654321|2")
peer = {"id": chat["group"]["id"], "type": 2,
        "accessHash": chat["group"].get("accessHash", 0)}
bale xyz 1.0.0 · MIT licensed · unofficial client © 2026 bale xyz contributors