Skip to main content

JSON-RPC 2.0 worker helper for Elixir PyBridge Ports

Project description

py-bridge

JSON-RPC 2.0 worker helper for PyBridge Elixir Ports.

Installation

pip install elixir-bridge

Usage

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

# 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 for more details.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

elixir_bridge-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

elixir_bridge-0.1.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file elixir_bridge-0.1.0.tar.gz.

File metadata

  • Download URL: elixir_bridge-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.21

File hashes

Hashes for elixir_bridge-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f76d5b201699e026d665cdfafb7ab1643a31b22a34d15ea2a33625c6d2188828
MD5 dc18ae1ce93a6891c14d88840f036ae9
BLAKE2b-256 108289ad5c7c23212303e8783d1690bba450209ef9902cda8f136c4fe714615c

See more details on using hashes here.

File details

Details for the file elixir_bridge-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: elixir_bridge-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.21

File hashes

Hashes for elixir_bridge-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1c3ebe7a8630863437a14b046f81ae551bf178534aaea668f5d2b50ccf6cfae6
MD5 4f8027b2ac43a0f1c84fc10dc9b04a5b
BLAKE2b-256 92ee7bd1dabf1598ec856eaeb0eea65cd526562f56e87d09ddca99d39445910d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page