Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Tests Coverage

pyspokes

pyspokes is a plugin system built around one idea: your application is the hub, and every implementation it can plug in is a spoke. Packages declare their spokes in a spokes.yaml file, and the application asks the hub for the interface it needs.

See the full documentation at https://ai-helpers.github.io/pyspokes

Table of Contents (ToC)

Usage

A package declares its spokes in a spokes.yaml file at its root:

# notify_app/spokes.yaml
- path: channels.EmailNotifier
  name: email

- path: channels.SlackNotifier
  name: slack
  priority: 5
# notify_app/channels.py
from notify_app.notifier import Notifier


class EmailNotifier(Notifier):
    def send(self, recipient: str, message: str) -> str:
        return f"email to {recipient}: {message}"


class SlackNotifier(Notifier):
    def send(self, recipient: str, message: str) -> str:
        return f"slack DM to {recipient}: {message}"

Once the package is installed, the application asks the hub for the interface and never imports an implementation:

from notify_app.notifier import Notifier
from pyspokes import get_spoke, get_spokes

notifier = get_spoke(Notifier)                 # highest priority: SlackNotifier
print(notifier.send("ada", "build finished"))  # slack DM to ada: build finished

email = get_spoke(Notifier, name="email")      # pick one by name
channels = get_spokes(Notifier)                # all of them, highest priority first

Adding a channel means installing a package that ships a spokes.yaml; the code above does not change. The quickstart walks through the whole example.

Concrete examples

A model gateway with local overrides

A platform team provides a chat model for the whole company. The catalog team must use a model hosted on premises, and wants a cheaper one for summarising reviews. Neither team edits the other's code, and the application is the same script throughout.

platform/                      catalog/
├── pyproject.toml             ├── pyproject.toml
└── llm_platform/              └── catalog_llm/
    ├── __init__.py                ├── __init__.py
    ├── chat.py                    ├── models.py
    └── spokes.yaml                └── spokes.yaml

The platform package owns the interface and a default implementation:

# llm_platform/chat.py
from abc import ABC, abstractmethod


class ChatModel(ABC):
    """Answer a prompt."""

    @abstractmethod
    def complete(self, prompt: str) -> str: ...


class HostedChat(ChatModel):
    def complete(self, prompt: str) -> str:
        return f"[hosted model] {prompt}"
# llm_platform/spokes.yaml
- path: chat.HostedChat

spokes.yaml has to ship inside the package. With setuptools:

# platform/pyproject.toml
[build-system]
requires = ["setuptools>=77"]
build-backend = "setuptools.build_meta"

[project]
name = "llm-platform"
version = "0.1.0"
requires-python = ">=3.13"
dependencies = ["pyspokes"]

[tool.setuptools]
packages = ["llm_platform"]

[tool.setuptools.package-data]
llm_platform = ["spokes.yaml"]

The catalog package adds two models. One outranks the platform default; the other has the default priority and is picked by name:

# catalog_llm/models.py
from llm_platform.chat import ChatModel


class OnPremChat(ChatModel):
    def complete(self, prompt: str) -> str:
        return f"[on-prem model] {prompt}"


class SmallChat(ChatModel):
    def complete(self, prompt: str) -> str:
        return f"[small model] {prompt}"
# catalog_llm/spokes.yaml
- path: models.OnPremChat
  priority: 10

- path: models.SmallChat
  name: reviews

Its pyproject.toml is the same with catalog-llm / catalog_llm as the names and dependencies = ["llm-platform"].

The application imports the interface only, and lets configuration pick a name:

# describe_product.py
import os

from llm_platform.chat import ChatModel
from pyspokes import get_spoke

model = get_spoke(ChatModel, name=os.getenv("CHAT_MODEL"), required=True)
print(model.complete("Describe a steel water bottle"))

With only the platform package installed, the hub finds one ChatModel:

$ pip install ./platform
$ python describe_product.py
[hosted model] Describe a steel water bottle

Install the catalog package and the same script changes behaviour:

$ pip install ./catalog
$ python describe_product.py
[on-prem model] Describe a steel water bottle

$ CHAT_MODEL=reviews python describe_product.py
[small model] Describe a steel water bottle

$ CHAT_MODEL=legacy python describe_product.py
pyspokes.exceptions.SpokeNotFoundError: No spoke found for required type <class 'llm_platform.chat.ChatModel'> named 'legacy'.

priority: 10 beats the default of 1, name narrows the candidates, and required=True turns a typo into an error at startup instead of a silent fallback. More situations like this one are in the examples.

One bucket, three clouds

An application saves reports to a bucket. Depending on the deployment, that bucket is on AWS, Google Cloud or Azure. The application code is the same everywhere: each cloud is one package, and switching means installing a different one.

A core package owns the interface and has no spokes:

# storage_core/store.py
from abc import ABC, abstractmethod


class ObjectStore(ABC):
    """Keep files in a bucket."""

    @abstractmethod
    def put(self, key: str, data: bytes) -> str:
        """Store ``data`` under ``key`` and return where it went."""

Each cloud package implements it with its own SDK and declares one named spoke. The hub builds spokes with no arguments, so each class reads its settings from the environment:

# storage_aws/s3.py
import os

import boto3
from storage_core.store import ObjectStore


class S3Store(ObjectStore):
    def __init__(self) -> None:
        self.bucket = os.environ["REPORTS_BUCKET"]
        self.client = boto3.client("s3")

    def put(self, key: str, data: bytes) -> str:
        self.client.put_object(Bucket=self.bucket, Key=key, Body=data)
        return f"s3://{self.bucket}/{key}"
# storage_gcp/gcs.py
import os

from google.cloud import storage
from storage_core.store import ObjectStore


class GcsStore(ObjectStore):
    def __init__(self) -> None:
        self.bucket = storage.Client().bucket(os.environ["REPORTS_BUCKET"])

    def put(self, key: str, data: bytes) -> str:
        self.bucket.blob(key).upload_from_string(data)
        return f"gs://{self.bucket.name}/{key}"
# storage_azure/blob.py
import os

from azure.storage.blob import BlobServiceClient
from storage_core.store import ObjectStore


class AzureBlobStore(ObjectStore):
    def __init__(self) -> None:
        service = BlobServiceClient.from_connection_string(os.environ["AZURE_STORAGE_CONNECTION_STRING"])
        self.container = service.get_container_client(os.environ["REPORTS_BUCKET"])

    def put(self, key: str, data: bytes) -> str:
        blob = self.container.upload_blob(key, data, overwrite=True)
        return blob.url
# storage_aws/spokes.yaml      # storage_gcp/spokes.yaml      # storage_azure/spokes.yaml
- path: s3.S3Store             - path: gcs.GcsStore           - path: blob.AzureBlobStore
  name: aws                      name: gcp                      name: azure

The application imports no SDK and names no cloud:

# save_report.py
import os

from pyspokes import get_spoke
from storage_core.store import ObjectStore

store = get_spoke(ObjectStore, name=os.getenv("STORAGE_BACKEND"), required=True)
print(store.put("2026/11/sales.csv", b"store,total\nparis,1280\n"))

Switch by installing. Each deployment installs the package for its cloud, and only that cloud's SDK comes with it:

$ pip install ./storage-aws        # the AWS deployment
$ python save_report.py
s3://acme-reports/2026/11/sales.csv

$ pip uninstall storage-aws && pip install ./storage-gcp        # the Google Cloud deployment
$ python save_report.py
gs://acme-reports/2026/11/sales.csv

Switch by configuration. With several of them installed in one image, the name picks the cloud at run time:

$ STORAGE_BACKEND=aws python save_report.py
s3://acme-reports/2026/11/sales.csv

$ STORAGE_BACKEND=gcp python save_report.py
gs://acme-reports/2026/11/sales.csv

$ STORAGE_BACKEND=azure python save_report.py
https://acmereports.blob.core.windows.net/acme-reports/2026/11/sales.csv

When several stores are installed, always give a name (or distinct priorities): the three above share the default priority, so without one the winner depends on discovery order. With none installed, required=True stops the script with a SpokeNotFoundError.

The same split works for a database: an interface such as OrderRepository in the core package, and one package per managed PostgreSQL (Amazon RDS, Cloud SQL, Azure Database for PostgreSQL), each carrying its own driver settings and authentication.

Getting Started

Prerequisites

  • Python 3.13+
  • uv

Install dependencies

uv sync --all-groups

Common tasks

Day-to-day commands are exposed as make tasks (run make help to list them all):

make check-tests     # run the unit tests with pytest
make checkers        # run all the checkers (lock, format, quality, types, coverage)
make formatters      # format the sources and tests with ruff
make badges          # regenerate the test and coverage badges shown above
make documenters     # build the documentation

Build the documentation

The documentation is built with Sphinx and the furo theme, and is deployed to GitHub Pages on every push to main.

make documenters

Contributing

Contributions are welcome! See CONTRIBUTING.md for the development setup, the checks to run before pushing, and the coding conventions.

Metadata

Release files for pyspokes 0.1.0a7

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

Source distribution (sdist)

Source distribution for pyspokes 0.1.0a7
File Size Uploaded Provenance Actions
pyspokes-0.1.0a7.tar.gz 26.1 kB Without provenance Details for pyspokes-0.1.0a7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyspokes 0.1.0a7
File Interpreter ABI Platform Actions
pyspokes-0.1.0a7-py3-none-any.whl Python 3 none any Details for pyspokes-0.1.0a7-py3-none-any.whl

Total release size: 58.0 kB

Release files / pyspokes-0.1.0a7.tar.gz

Download URL pyspokes-0.1.0a7.tar.gz
Size 26.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ba3f0da55ccc00833833e88586f062a934e90ac5ffe245697624f950147146b5
BLAKE2b-256 checksum
How to use checksums
bbd74edb63672b49471f989af2e33816e2f33e83222be9b99b28a8f01075a1b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pyspokes-0.1.0a7-py3-none-any.whl

Download URL pyspokes-0.1.0a7-py3-none-any.whl
Size 31.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
85113471d87720e9d078ab50ed960afdedff9b4e79b69c3d09722790816cd8dc
BLAKE2b-256 checksum
How to use checksums
06154c306fdb77d6c206aa2ac7e8fa83bdb3b9aa710d552ba0bcea422c4fd61c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for pyspokes 0.1.0a7

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