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 adecode(bytes) -> Selfclassmethod that verifies the layout_id and reads field offsets directly from the raw bytes. - One dataclass per event with a
decode(bytes) -> Selfclassmethod keyed off the 1-byte event tag. build_<instruction>helper functions that return the rawbytesinstruction payload. The caller wires the returned bytes into their preferred Solana client (solders, solana-py, …).- A
DISCRIMINATORSdict mapping layout name to(disc, layout_id).
§Design notes
Hopper emits Python that:
- Verifies the
layout_idfingerprint before decoding (impossible in Anchor because Anchor has no layout fingerprint). - Honors
FieldIntentby emitting typedint/bytes/boolfield types that match the field’s semantic role, not just the underlying u8/u64. - Ships segment-aware partial readers (
Vault.read_balance(buf)) parallel to the zero-copy on-chain side.
Structs§
- PyAccounts
- Generates
accounts.pycontent from aProgramManifest. - PyClient
Gen - Convenience emitter that produces a single concatenated Python file
combining every section above. Useful for CLI users who want one flat
file they can
cpinto their project. - PyEvents
- Generates
events.pycontent from aProgramManifest. - PyIndex
- Generates an
__init__.pythat re-exports the public surface of the generated package. - PyInstructions
- Generates
instructions.pycontent from aProgramManifest. - PyTypes
- Generates the shared
types.pycontent: header parser, fingerprint assertion helper, and a single source-of-truthDECODERSunion table.