Metadata-Version: 2.4
Name: pyspokes
Version: 0.1.0a4
Summary: Type-based spoke discovery and resolution for Python applications
Keywords: plugin,plugins,plugin-system,discovery,dependency-injection,hub,spokes
Author: AI Helpers
Author-email: AI Helpers <vasseur.corentin@gmail.com>
License-Expression: MIT
License-File: LICENSE.txt
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Dist: pyyaml>=6.0.1,<7
Requires-Dist: typer>=0.20.0,<0.21 ; extra == 'cli'
Requires-Dist: rich>=13.0.0,<16 ; extra == 'cli'
Requires-Python: >=3.13
Project-URL: Homepage, https://github.com/ai-helpers/pyspokes
Project-URL: Documentation, https://ai-helpers.github.io/pyspokes
Project-URL: Repository, https://github.com/ai-helpers/pyspokes
Project-URL: Issues, https://github.com/ai-helpers/pyspokes/issues
Project-URL: Changelog, https://github.com/ai-helpers/pyspokes/blob/main/CHANGELOG.md
Provides-Extra: cli
Description-Content-Type: text/markdown

![Tests](docs/_static/badges/test-badge.svg)
![Coverage](docs/_static/badges/coverage-badge.svg)

# 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)

- [pyspokes](#pyspokes)
  - [Table of Contents (ToC)](#table-of-contents-toc)
  - [Usage](#usage)
  - [Getting Started](#getting-started)
    - [Prerequisites](#prerequisites)
    - [Install dependencies](#install-dependencies)
    - [Common tasks](#common-tasks)
    - [Build the documentation](#build-the-documentation)
  - [Contributing](#contributing)

## Usage

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

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

- path: channels.SlackNotifier
  name: slack
  priority: 5
```

```python
# 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:

```python
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](https://ai-helpers.github.io/pyspokes/quickstart.html) walks through the
whole example.

## Getting Started

### Prerequisites

- Python 3.13+
- [uv](https://docs.astral.sh/uv/)

### Install dependencies

```bash
uv sync --all-groups
```

### Common tasks

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

```bash
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](https://www.sphinx-doc.org/) and the
[furo](https://github.com/pradyunsg/furo) theme, and is deployed to GitHub Pages
on every push to `main`.

```bash
make documenters
```

## Contributing

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