Sign in

    smithy-codegen-python

    A Smithy code generator for Python JSON-RPC peers

    Download zip
    Author
    Version
    0.7.0
    License
    Apache-2.0
    Last updated
    4 hours ago
    Downloads
    5

    #moonrockz/smithy-codegen-python

    A Smithy code generator for Python JSON-RPC 2.0 peers. Register it in the build runner as python-jsonrpc-codegen. One run generates one peer of a protocol.

    { "version": "1.0", "plugins": { "python-jsonrpc-codegen::python-terminal": { "service": "example.payments#PaymentTerminal", "protocol": "example.payments#TerminalProtocol", "peer": "terminal", "package": "payment_terminal", "integrations": ["fastapi"] } } }

    #Settings

    • service, protocol, peer and transports: the shared settings of the JSON-RPC plugins (PeerSettings in moonrockz/smithy-codegen-jsonrpc).
    • package (required): the Python package name of the output, such as payment_terminal.
    • integrations (optional): ["fastapi"] adds FastAPI and uvicorn to the dependencies.

    #Output

    FileContent
    pyproject.tomlThe project, with exact versions of the dependencies and the checks (pyright strict, ruff, pytest).
    <package>/models.pyA frozen Pydantic v2 model for each structure, a model for each union member and a tagged type alias for each union, a StrEnum or IntEnum for each enum. Fields are snake_case; the wire names are the aliases.
    <package>/errors.pyFor each modeled error: a data model <Name>Data and an exception <Name> with to_rpc_error() and from_data(data).
    <package>/handler.pyA Protocol with one method for each method that the peer accepts, and register_<service>(peer, handler). The cancel method has no handler: the runtime cancels the call.
    <package>/client.pyA typed client of the service that the peer calls. Each call has checked: bool = True.
    <package>/session.pysession_rules() from the prepared session contract, and new_peer(log=None).
    <package>/_runtime/A copy of runtimes/python/smithy_jsonrpc_runtime.
    tests/test_generated.pyA check of the session rules, the peer and one model.

    Exact values: a bigDecimal is a Decimal (BigDecimal), an integer of any size is an int (BigInteger), a blob is bytes (base64 on the wire). A number never goes through float.

    The generator does not interpret the RPC traits again. It renders the prepared contracts of moonrockz/smithy-validation/rpc, so the generated peers and smithy validate rpc transcript agree.

    mise run runtime:embed copies the runtime into runtime_files.mbt. mise run validate checks that the copy is current.

    class_name

    fn class_name(name : String) -> String

    The name of a generated class: the contextual name with an upper-case first letter. A name that the generated modules use gets a _ suffix.

    enum_member_name

    fn enum_member_name(name : String) -> String

    An UPPER_SNAKE name for an enum member. insertCard is INSERT_CARD and USD stays USD.

    method_name

    fn method_name(name : String) -> String

    The name of a handler or client method: a snake_case name. The client keeps its peer in attribute peer, so a method peer gets a _ suffix.

    pascal_name

    fn pascal_name(name : String) -> String

    A PascalCase part of a class name, such as the member part of a union member class. manualEntry is ManualEntry.

    plugin

    fn plugin(model :
    Model
    , settings : Json) -> Map[String, String] raise
    BuildError

    The plugin for the build runner. Register it as python-jsonrpc-codegen.

    py_string

    fn py_string(text : String) -> String

    The text of a Python string literal in double quotes.

    run

    Generate a Python JSON-RPC peer. Settings: service, protocol, peer, transports (see PeerSettings), package, the Python package name of the output, such as payment_terminal, and integrations (optional), such as ["fastapi"].

    snake_name

    fn snake_name(name : String) -> String

    A snake_case name for a field, a method or a function. A keyword or a model attribute gets a _ suffix. A name that starts with a digit gets an n prefix.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io