English فارسی

Protocol index

The heart of the library: 683 request types and 683 response types built at import time from a single JSON description. No protoc, no generated Python checked into the repo.

What the index contains

{
  "release": "web@5.5.1+169491",
  "services": {
    "bale.meet.v1.Meet": {
      "StartGroupCall": {
        "req": "m77108_local_3a9",
        "res": "m77108_local_3aP",
        "fields": [ ... ]
      }
    }
  },
  "codecs": { ... 1960 wire definitions ... },
  "aliases": { ... },
  "scalars": { ... }
}
KeyMeaning
releaseWeb build the description came from
services52 services → method → request/response type ids
codecs1,960 message definitions with field numbers and types
aliasesAlternative service names seen in different bundles
scalarsPrimitive type metadata

How a type gets built

  1. Topological sort. The module dependency graph is a DAG (proved with an SCC check — no cycles). Types are registered in dependency order.
  2. Register once. AddSerializedFile silently ignores a second file with the same name. Early builds stalled at depth 3 because of this; ordering fixed it.
  3. Resolve references. Each field points at another generated type, so nested messages are real messages, not raw bytes.
Result.

5,520 typed fields, 1,960 codecs, and all 683 request/response pairs built in about 0.08 s. Only 30 fields remain as raw bytes — and those really are bytes in the protocol.

Inspecting the index

from balexyz import dynamic

level = dynamic.INDEX

len(level.services)             # 52
len(level.all_methods())        # 683

level.method_names("bale.meet.v1.Meet")     # 30 names, sorted
level.search("story")                       # [(service, method), ...]
level.canonical("Meet")                     # alias resolution

Getting message classes

Request = dynamic.request_type("bale.meet.v1.Meet", "StartGroupCall")
Response = dynamic.response_type("bale.meet.v1.Meet", "StartGroupCall")

for field in Request.DESCRIPTOR.fields:
    print(field.number, field.name, field.type)

req = Request()
req.video = False
req.mode = 2
print(req.SerializeToString().hex())

Signatures

print(dynamic.describe("bale.meet.v1.Meet", "StartGroupCall"))
bale.meet.v1.Meet.StartGroupCall(peer: message, randomId: int64, video: bool,
  mode: int32, invitees: list[message])
  -> {groupCall: message, seq: int32}

The camelCase story

Field names in the descriptor are camelCase.

They come from the webpack AST, so groupCall, not group_call. Everything crossing into Python is normalised: the dicts you get from to_dict(), invoke() and every high-level method use snake_case at all nesting levels. When you build a payload you may use either spelling — _fill tries both.

m = dynamic.response_type("bale.meet.v1.Meet", "GenerateCallLink")()
from balexyz.dynamic import _fill
_fill(m, {"group_call": {"id": 1, "link": "x"}, "link_expiration_period": 10800})

dynamic.to_dict(m)
# {"group_call": {"id": 1, "link": "x"}, "link_expiration_period": 10800}

Rebuilding the index

When Bale ships a new web build:

python scripts/build_protocol_index.py

The script reads src/balexyz/proto/protocol.json (the upstream description) and emits index.json plus the compact proto modules. Then verify nothing regressed:

python -m pytest tests/ -q
bale-xyz info
Why pin the version at all?

A protocol index that silently drifts produces wrong field numbers, which corrupts binary payloads in ways that look like server bugs. Pinning means a mismatch fails loudly — as an UNIMPLEMENTED RPC.

bale xyz 1.0.0 · MIT licensed · unofficial client © 2026 bale xyz contributors