Metadata-Version: 2.4
Name: objectspell
Version: 0.1.0
Summary: A library for building asynchronous messaging topologies using declarative implicit wiring.
Keywords: asyncio,event-driven,messaging,signals,pubsub
Author: Max Sukhorukov
Author-email: Max Sukhorukov <signaldetect@gmail.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Typing :: Typed
Requires-Python: >=3.12
Project-URL: Homepage, https://github.com/invertedpoint/objectspell-py
Project-URL: Issues, https://github.com/invertedpoint/objectspell-py/issues
Description-Content-Type: text/markdown

# ObjectSpell

A small asyncio framework for wiring components together with signals, without registries,
decorators, or callback lists. You declare what a component sends and what it listens to;
ObjectSpell connects them by name.

Zero dependencies. Python 3.12+.

## Install

```bash
pip install objectspell   # or: uv add objectspell
```

## Quick start

Each component lives in its own module. Here `X` sends a message, `Y` prints it, and the
program stops once `Y` is done.

**`x.py`** — sends `something_happened`

```python
from objectspell import struct


class Emitter(struct.Emitter):
    async def something_happened(self, message: str) -> None:
        pass  # a declaration, not an implementation


class X(struct.State, Emitter):
    async def action(self) -> None:
        await self.something_happened(message="OK Computer")


class Connector(struct.Receiver, X):
    async def connected(self) -> None:
        await self.action()

    async def disconnected(self) -> None:
        pass
```

**`y.py`** — listens to `X`, then reports it is done

```python
from objectspell import struct


class Emitter(struct.Emitter):
    async def completed(self) -> None:
        pass


class Y(struct.State, Emitter):
    async def show(self, message: str) -> None:
        print("Y received:", message)
        await self.completed()


class X(struct.Receiver, Y):
    async def something_happened(self, message: str) -> None:
        await self.show(message)
```

**`connector.py`** — stops everything when `Y` is done

```python
from objectspell import struct
from objectspell.struct import Connector


class Y(struct.Receiver, Connector):
    async def completed(self) -> None:
        await self.disconnect()
```

**`main.py`**

```python
import asyncio

from connector import Connector
from x import X
from y import Y


async def main() -> None:
    await Connector().connect([X(), Y()])


if __name__ == "__main__":
    asyncio.run(main())
```

```console
$ python main.py
Y received: OK Computer
```

Notice that `X` and `Y` never import each other. The only thing linking them is the class
name: `y.py` declares `class X(struct.Receiver, Y)`, which means "on `Y`, handle signals
from `X`".

## The four pieces

- **Emitter** — declares the signals a component can send. The method bodies are never run;
  ObjectSpell replaces them with senders.
- **State** — a component. It owns a queue and handles one signal at a time.
- **Receiver** — a handler group attached to a State, **named after the State it listens to**.
- **Connector** — starts and stops the whole topology.

## Documentation

- [Concepts](https://github.com/invertedpoint/objectspell-py/blob/main/docs/concepts.md) — the four pieces and how a signal travels
- [Wiring](https://github.com/invertedpoint/objectspell-py/blob/main/docs/wiring.md) — the naming rule, and why each component gets its own module
- [Lifecycle](https://github.com/invertedpoint/objectspell-py/blob/main/docs/lifecycle.md) — starting up, shutting down, and message order
- [Limitations](https://github.com/invertedpoint/objectspell-py/blob/main/docs/limitations.md) — what this library does not do

Runnable examples live in [`examples/`](https://github.com/invertedpoint/objectspell-py/tree/main/examples).

## License

MIT — see [LICENSE](https://github.com/invertedpoint/objectspell-py/blob/main/LICENSE).
