Metadata-Version: 2.4
Name: elixir-bridge
Version: 0.1.0
Summary: JSON-RPC 2.0 worker helper for Elixir PyBridge Ports
License-Expression: MIT
Project-URL: Homepage, https://github.com/dan1d/py_bridge
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# py-bridge

JSON-RPC 2.0 worker helper for [PyBridge](https://github.com/dan1d/py_bridge) Elixir Ports.

## Installation

```bash
pip install elixir-bridge
```

## Usage

```python
from py_bridge import worker

@worker.register
def predict(features: list[float]) -> dict:
    return {"prediction": sum(features) / len(features)}

@worker.register
def add(a: int, b: int) -> dict:
    return {"sum": a + b}

if __name__ == "__main__":
    worker.run()
```

This creates a Python script that communicates with an Elixir `PyBridge.Worker` GenServer over stdin/stdout using JSON-RPC 2.0.

## How It Works

- `@worker.register` exposes a function as a callable JSON-RPC method
- `worker.run()` starts the stdin/stdout event loop
- Requests and responses are newline-delimited JSON
- Exceptions are caught and returned as JSON-RPC error objects with tracebacks

## Elixir Side

```elixir
# Add py_bridge to your mix.exs deps, then:
{:ok, _} = PyBridge.Worker.start_link(
  name: :my_worker,
  python: "python3",
  script: "path/to/worker.py"
)

{:ok, %{"prediction" => 0.5}} =
  PyBridge.call(:my_worker, "predict", %{features: [1.0, 2.0, 3.0]})
```

See the [full documentation](https://github.com/dan1d/py_bridge) for more details.

## License

MIT
