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.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| monosmith_plugin_sdk-0.2.0.tar.gz | 88.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| monosmith_plugin_sdk-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 204.6 kB
Release files / monosmith_plugin_sdk-0.2.0.tar.gz
| Download URL | monosmith_plugin_sdk-0.2.0.tar.gz |
|---|---|
| Size | 88.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a111675e3b437a2a789da08770449240142a6c7f6c1bbcada05d1b1afb0d0197
|
|
BLAKE2b-256 checksum How to use checksums |
d2be8b62d3164434a906ff901001def08c56cfd1a27037baf1092a3c5675ab23
|
| 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.2.0-py3-none-any.whl
| Download URL | monosmith_plugin_sdk-0.2.0-py3-none-any.whl |
|---|---|
| Size | 116.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ee1fc0d1155d7c97f02b9203c65278894c84bea94ccfd132a77aaac84a511802
|
|
BLAKE2b-256 checksum How to use checksums |
6add0d564e36f7af91f305498cae4400dc34c3cda8ee23b29ce3cf54c8b7c943
|
| 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.2.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.