Skip to main content

Rust-backed Python package for AnyServe

Project description

anyserve Python Bindings

This package provides high-performance Python bindings for AnyServe. Its transport implementation comes from crates/anyserve-client; the public package adds role-specific facades and higher-level worker helpers on top.

Install

From PyPI:

pip install anyserve-runtime

The published distribution name is anyserve-runtime, while the import package remains:

import anyserve

From a local wheel:

pip install target/wheels/anyserve_runtime-*.whl

From local source:

pip install ./clients/python

Source installs build the native extension locally, so they require a working Rust toolchain on PATH. Inside this repository, mise exec -- ... provides the expected toolchains.

The top-level AnyserveClient exposes the generic control-plane surface and also offers role-specific views through submitter() and worker().

It also includes a high-level worker API for function-style handlers:

from anyserve import serve, worker


@worker(
    interface="demo.echo.v1",
    attributes={"runtime": "python"},
    capacity={"slot": 1},
    codec="bytes",
)
def echo(payload: bytes) -> bytes:
    return payload


serve(echo, endpoint="http://127.0.0.1:50052")

Examples use endpoint strings like http://127.0.0.1:50052 because the bindings connect through a gRPC channel URI. This is not a REST base URL.

API Surface

  • submit_job
  • watch_job
  • list_jobs
  • get_job
  • cancel_job
  • get_attempt
  • list_attempts
  • register_worker
  • heartbeat_worker
  • poll_lease
  • renew_lease
  • report_event
  • complete_lease
  • fail_lease
  • open_stream
  • get_stream
  • list_streams
  • close_stream
  • push_frames
  • pull_frames

watch_job(...) and pull_frames(...) return iterators so the Python API preserves streaming semantics instead of materializing the full stream into a list.

It also includes two convenience constructors:

  • inline_object(...)
  • uri_object(...)

And high-level worker helpers:

  • worker(...)
  • serve(...)
  • get_handler_spec(...)

Local Development

Build and install from local source into the active environment:

pip install ./clients/python

Or install the extension directly into the active environment through maturin:

python3 -m pip install --user maturin
python3 -m maturin develop --manifest-path clients/python/Cargo.toml

Live end-to-end validation:

mise run python-sdk-e2e

PyPI Publishing

The repository is set up to publish the Python package through PyPI Trusted Publishing.

  • PyPI project name: anyserve-runtime
  • GitHub repository: anyserve/anyserve
  • Workflow path: .github/workflows/python-publish.yml
  • GitHub environment: pypi

For the first release, create a pending Trusted Publisher for anyserve-runtime on PyPI, then run the publish workflow or push a v* tag.

Example

High-level worker example:

from anyserve import serve, worker


@worker(
    interface="demo.echo.v1",
    attributes={"runtime": "python"},
    capacity={"slot": 1},
    codec="bytes",
)
def echo(payload: bytes) -> bytes:
    return payload


serve(echo, endpoint="http://127.0.0.1:50052")

Low-level submitter example:

from anyserve import AnyserveClient, FRAME_DATA

client = AnyserveClient("http://127.0.0.1:50052")
# Assumes the control plane and a compatible worker are already running.

job = client.submit_job(
    interface_name="demo.echo.v1",
    required_attributes={"runtime": "demo"},
    required_capacity={"slot": 1},
)

stream = client.open_stream(job["job_id"], "input.default")
client.push_frames(
    stream["stream_id"],
    [(FRAME_DATA, b"hello from python", {})],
)
client.close_stream(stream["stream_id"])

for event in client.watch_job(job["job_id"]):
    print(event["kind"], event["metadata"])

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

anyserve_runtime-0.4.0.tar.gz (47.6 kB view details)

Uploaded Source

Built Distribution

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

anyserve_runtime-0.4.0-cp312-abi3-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

File details

Details for the file anyserve_runtime-0.4.0.tar.gz.

File metadata

  • Download URL: anyserve_runtime-0.4.0.tar.gz
  • Upload date:
  • Size: 47.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for anyserve_runtime-0.4.0.tar.gz
Algorithm Hash digest
SHA256 8c6664a713af7be8cb1e189b81f2f0bcd61958abcfc2f21cf2b062818efece44
MD5 9125b0d44e79c4b9dbefdd4a8d6eb6d2
BLAKE2b-256 d59300dc1263ce721d963bd9cb1ae0e74e81d2eafd9210a3740975dbb62710cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for anyserve_runtime-0.4.0.tar.gz:

Publisher: python-publish.yml on anyserve/anyserve

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file anyserve_runtime-0.4.0-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for anyserve_runtime-0.4.0-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d518b7ef012164b631771ee5a2bc8ba0045f7358b785e85e5369df7f7cc1ab90
MD5 75dd3a288e993a79158f723b32cbc9c8
BLAKE2b-256 406884463aa1a17af5579da3f6b100a8af29aec83e54fbe8346aea25d24b69ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for anyserve_runtime-0.4.0-cp312-abi3-macosx_11_0_arm64.whl:

Publisher: python-publish.yml on anyserve/anyserve

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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