Skip to main content

monosmith-plugin-sdk

The Python SDK for writing smith plugins: the protocol's types, the serve loop, a host to test a plugin with, the conformance checks of smith plugin check, [[ ]] templating and JSON editing that keeps key order. No runtime dependencies; Python 3.10 or later; fully type-annotated.

pip install monosmith-plugin-sdk

A plugin is an object with describe and one method for each thing it does. The SDK frames the JSON-RPC messages, answers initialize, derives the capabilities from the methods the object has and keeps standard output for the protocol:

from monosmith_plugin_sdk import contribute_to, serve, task


class WidgetLint:
    def describe(self, params):
        return {
            "plugin": {"name": "widget-lint", "version": "0.1.0"},
            "kind": "convention",
            "roles": ["structure"],
            "languages": ["widget"],
        }

    def contribute(self, params):
        return contribute_to(
            params["projects"],
            lambda project: {
                "tasks": {"layout-check": task(["python", "check.py"], cache=True)},
                "dependsOn": {"lint": ["layout-check"]},
            },
        )


if __name__ == "__main__":
    serve(WidgetLint())

Test it in-process, with the real handshake and framing, and run the same checks as smith plugin check:

from monosmith_plugin_sdk import HostOptions, check_plugin, connect_in_process

with connect_in_process(WidgetLint(), HostOptions(workspace_root=str(tmp_path))) as client:
    report = check_plugin(client)
    assert report.ok, report.failures()

The full guide and API reference: The Python SDK. Examples that use it: structure-layout-py, structure-scan-py and language-widget-py.

The protocol schema is the source of truth

The types in src/monosmith_plugin_sdk/protocol are not written by hand. The Go types of the protocol (packages/plugin-sdk/protocol) are the source of truth; their JSON Schema is committed as packages/plugin-sdk/schema/protocol.schema.json, and tools/generate_protocol turns that into protocol_types_contract.py (a TypedDict per message, the methods table, the error codes) and protocol_schema_contract.py (the schema itself, which the wire codec and the host's capability check read at run time). After a change to the protocol:

smith run schema -p plugin-sdk          # the Go side writes the schema
smith run generate -p plugin-sdk-py     # this side writes the types

A test (tests/generate_protocol) and smith run generate-check -p plugin-sdk-py fail when either file is stale. A test also fails when the schema has a method this SDK does not know how to serve (PLUGIN_MEMBERS), so a new method has to be given its place in the plugin object.

What is where

Folder of src/monosmith_plugin_sdk What it holds
protocol the generated types, the schema as data, RpcError
codec the wire form of the messages: key order, omitempty, sorted maps and escaping as the Go SDK writes them, so the bytes are equal; params shaped as the types promise
framing Content-Length framing over a byte stream
cancellation CancelToken, what a cancellable method watches
serve serve, serve_streams (a bounded pool of worker threads, cancel and the plugin's concurrency), the plugin protocols, capability derivation, standard input and output claimed for the protocol
concurrency what a declared concurrency means: one at a time by default, a count, or unlimited
host start_plugin, connect_plugin, connect_in_process, PluginClient: the host side, for tests; it keeps to the plugin's concurrency and cancels a call with a CancelToken
conformance check_plugin: the checks of smith plugin check
templating, jsondoc ports of the Go SDK's templating and jsondoc
tasks, scaffold, ci helpers to build the answers of contribute, generate and ci
build_dir, plugin_roles, plugin_refs, projects the protocol package's small functions: build directories, roles, plugin references, project kinds, manifests

The source is organised by vertical slices (smith slices check lints it); tests/integration holds the tests that start real processes: the examples under smith plugin check and in a throwaway workspace, and the compatibility test that a Python plugin, a TypeScript plugin and a Go plugin with the same logic answer with the same bytes.

Develop

smith run lint typecheck test build generate-check -p plugin-sdk-py

The integration tests need smith, go and node on the path and skip themselves without them (in CI, where they exist, a missing one fails the test). The package is released by smith from conventional commits, like the other packages of this repository.

Metadata

Release files for monosmith-plugin-sdk 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for monosmith-plugin-sdk 0.1.0
File Size Uploaded Provenance
monosmith_plugin_sdk-0.1.0.tar.gz 86.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for monosmith-plugin-sdk 0.1.0
File Interpreter ABI Platform
monosmith_plugin_sdk-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 201.5 kB

Release files / monosmith_plugin_sdk-0.1.0.tar.gz

Download URL monosmith_plugin_sdk-0.1.0.tar.gz
Size 86.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1ae555ff56142d28d206d03567f87897fefb8ad180d41abb016474274d032898
BLAKE2b-256 checksum
How to use checksums
6cc569e8db206bfaa6e4e0093f60093662db33a4eae9487f30bd6d8a5d0b76d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release files / monosmith_plugin_sdk-0.1.0-py3-none-any.whl

Download URL monosmith_plugin_sdk-0.1.0-py3-none-any.whl
Size 115.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e18dd198a8ad75ce6a73a482829b8df6ba70d05988c4e10122ffe37efe4dfe79
BLAKE2b-256 checksum
How to use checksums
a5e783380d38a971aafcd74426f8105c965365afb74d76723febaae86d3fc9a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Security for monosmith-plugin-sdk 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page