Skip to main content

Module python_client

Module python_client 

Source
Expand description

§Python client emitter

Produces a standalone Python module from a ProgramManifest that mirrors the TypeScript emitter in clientgen.rs. The generated Python has no runtime dependency outside of the standard library. everything decodes through struct (the stdlib module).

§What gets emitted

  • One dataclass per account layout (Vault, Config, …) with a decode(bytes) -> Self classmethod that verifies the layout_id and reads field offsets directly from the raw bytes.
  • One dataclass per event with a decode(bytes) -> Self classmethod keyed off the 1-byte event tag.
  • build_<instruction> helper functions that return the raw bytes instruction payload. The caller wires the returned bytes into their preferred Solana client (solders, solana-py, …).
  • A DISCRIMINATORS dict mapping layout name to (disc, layout_id).

§Design notes

Hopper emits Python that:

  1. Verifies the layout_id fingerprint before decoding (impossible in Anchor because Anchor has no layout fingerprint).
  2. Honors FieldIntent by emitting typed int / bytes / bool field types that match the field’s semantic role, not just the underlying u8/u64.
  3. Ships segment-aware partial readers (Vault.read_balance(buf)) parallel to the zero-copy on-chain side.

Structs§

PyAccounts
Generates accounts.py content from a ProgramManifest.
PyClientGen
Convenience emitter that produces a single concatenated Python file combining every section above. Useful for CLI users who want one flat file they can cp into their project.
PyEvents
Generates events.py content from a ProgramManifest.
PyIndex
Generates an __init__.py that re-exports the public surface of the generated package.
PyInstructions
Generates instructions.py content from a ProgramManifest.
PyTypes
Generates the shared types.py content: header parser, fingerprint assertion helper, and a single source-of-truth DECODERS union table.