Skip to main content

Rust-backed Python package for AnyServe

Project description

anyserve Python Bindings

This package is a Rust-exported Python binding layer built with PyO3 and maturin. Its transport implementation comes from crates/anyserve-client; the public Python 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 Rust extension locally, so they require a working Rust toolchain on PATH. Inside this repository, mise exec -- ... provides the expected Python and Rust 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.3.0.tar.gz (41.1 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.3.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.3.0.tar.gz.

File metadata

  • Download URL: anyserve_runtime-0.3.0.tar.gz
  • Upload date:
  • Size: 41.1 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.3.0.tar.gz
Algorithm Hash digest
SHA256 211bcb01738f075cf8db2e315d61be5005d1689dafac1587821167bbaa69cf11
MD5 4107ddaa3fcea74f79f9ad5ca4db552e
BLAKE2b-256 439bfbb711c51b2509f7ff6921e5ee5ddc492364df03e72021142eb198b0b47b

See more details on using hashes here.

Provenance

The following attestation bundles were made for anyserve_runtime-0.3.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.3.0-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for anyserve_runtime-0.3.0-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4656b0e923bb8c2402b0f33915421f11db4c46b1c3e529c438a22a189b88004b
MD5 61a7f94e58272425f1395a5f2518b916
BLAKE2b-256 e67e519cfe3e3cc671887d8b3e17d727969f1853b1dbb09e9a5a690a612adb2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for anyserve_runtime-0.3.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