Skip to main content

Sunray

uv Ruff Tests Ty codecov GitHub License PyPI - Python Version PyPI - Version Static Badge

Ray is a unified framework for scaling AI and Python applications. However, it falls short in offering friendly type hints, particularly when it comes to working with the Actor.

To address this shortfall, sunray provides enhanced and more robust type hints.

install

pip install sunray

Let's vs.

Round 1: Build an actor

sunray ray
  • sunray returns Actor[Demo], but ray returns ObjectRef[Demo]
  • ray mypy raise error Type[Demo] has no attribute "remote"

Round 2: Get actor remote methods

sunray ray
  • sunray list all remote methods
  • ray list nothing

Round 3: Actor remote method call

sunray ray
  • sunray correctly provided parameter hints.
  • ray ...

Round 4: Annotate with Actor

sunray ray
  • with sunray, just annotate it with Actor[Demo].
  • with ray, I don't known.

Round 5: Stream

sunray ray
  • sunray correctly identified that stream returns a generator.
  • ray still returns ObjectRef.

Round 6: Unpack result

sunray ray
  • sunray will auto unpack tuple result if options specify unpack=True.
  • ray need to specify how many return numbers, so you need to count it.
  • ray mypy raise error 'RemoteFunctionNoArgs has no attribute "options"'.

Round 7: Get actor

sunray ray
  • sunray get_actor will return ActorHandle, and return Actor[Demo] if you specify with generic type.
  • ray just return Any.

Round 8: Call self remote method

sunray ray
  • sunray maintains a consistent calling convention, whether it's from internal or external functions.
  • ray, you need to first obtain the current actor from the running context, and then call through the actor.

Round 9: Lazy Computation

sunray ray
  • sunray can successfully track the input parameter types and output types.
  • ray does not have this capability.

API

sunray re-export all apis from ray.core with friendly type hints. In addition, sunray provides ActorMixin which is used to help creating more robust actors.

ActorMixin

ActorMixin is a mixin, and provides a classmethod new_actor

import sunray


class Demo(
                       # Here to specify default actor options
    sunray.ActorMixin, name="DemoActor", num_cpus=1, concurrency_groups={"g1": 1}
):
    def __init__(self, init_v: int):
        self.init_v = init_v

    # annotate `add` is a remote_method
    @sunray.remote_method
    def add(self, v: int) -> int:
        return self.init_v + v

    # support directly call remote_method
    @sunray.remote_method
    def calculate(self, v: int) -> int:
        return self.add(v)

    # support specify remote method options
    @sunray.remote_method(concurrency_group="g1")
    async def sleep(self): ...


# construct the actor
actor = Demo.new_actor().remote(1)

# call remote method
ref = actor.methods.add.remote(1)
print(sunray.get(ref))

Metadata

Release files for sunray 0.14.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for sunray 0.14.0
File Interpreter ABI Platform Actions
sunray-0.14.0-py3-none-any.whl Python 3 none any Details for sunray-0.14.0-py3-none-any.whl

Release files / sunray-0.14.0-py3-none-any.whl

Download URL sunray-0.14.0-py3-none-any.whl
Size 25.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
19cfaa67114b2f192994cde5741fa45f447baf42d23f71de85e8073941bcfd4a
BLAKE2b-256 checksum
How to use checksums
ebac35551e83e7c9edd299c3996d83755ca6781b533c9be6f26f5d42a669ad9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for sunray 0.14.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page