Skip to main content

Appose: multi-language interprocess cooperation with shared memory.

Project description

Appose Python

WARNING: Appose is currently in incubation. Not all features described below are functional. This document has some aspirational aspects!

What is Appose?

Appose is a library for interprocess cooperation with shared memory. The guiding principles are simplicity and efficiency.

Appose was written to enable easy execution of Python-based deep learning from Java without copying tensors, but its utility extends beyond that. The steps for using Appose are:

  • Build an Environment with the dependencies you need.
  • Create a Service linked to a worker, which runs in its own process.
  • Execute scripts on the worker by launching Tasks.
  • Receive status updates from the task asynchronously via callbacks.

For more about Appose as a whole, see https://apposed.org.

What is this project?

This is the Python implementation of Appose.

How do I use it?

The name of the package is appose.

PyPI/Pip

To use the PyPI package, add appose to your project dependencies.

Depending on how your project is set up, this might entail editing requirements.txt, setup.py, setup.cfg, and/or pyproject.toml.

If you are just starting out, we recommend using pyproject.toml (see this guide):

dependencies = [
  "appose"
]

Conda/Mamba

To use the conda-forge package, add appose to your environment.yml's dependencies section:

dependencies:
  - appose

Examples

Here is a minimal example for calling into Java from Python:

import appose
env = appose.java(vendor="zulu", version="17").build()
with env.groovy() as groovy:
    task = groovy.task("5 + 6")
    task.wait_for()
    result = task.outputs["result"]
    assert 11 == result

Note: The appose.java builder is planned, but not yet implemented.

Here is an example using a few more of Appose's features:

import appose
from time import sleep

golden_ratio_in_groovy = """
// Approximate the golden ratio using the Fibonacci sequence.
previous = 0
current = 1
for (i=0; i<iterations; i++) {
    if (task.cancelRequested) {
        task.cancel()
        break
    }
    task.update(null, i, iterations)
    v = current
    current += previous
    previous = v
}
task.outputs["numer"] = current
task.outputs["denom"] = previous
"""

env = appose.java(vendor="zulu", version="17").build()
with env.groovy() as groovy:
    task = groovy.task(golden_ratio_in_groovy)

    def task_listener(event):
        match event.responseType:
            case ResponseType.UPDATE:
                print(f"Progress {task.current}/{task.maximum}")
            case ResponseType.COMPLETION:
                numer = task.outputs["numer"]
                denom = task.outputs["denom"]
                ratio = numer / denom
                print(f"Task complete. Result: {numer}/{denom} =~ {ratio}");
            case ResponseType.CANCELATION:
                print("Task canceled")
            case ResponseType.FAILURE:
                print(f"Task failed: {task.error}")

    task.listen(task_listener)

    task.start()
    sleep(1)
    if not task.status.is_finished():
        # Task is taking too long; request a cancelation.
        task.cancel()

    task.wait_for()

Of course, the above examples could have been done all in one language. But hopefully they hint at the possibilities of easy cross-language integration.

Issue tracker

All implementations of Appose use the same issue tracker:

https://github.com/apposed/appose/issues

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

appose-0.7.2.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

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

appose-0.7.2-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file appose-0.7.2.tar.gz.

File metadata

  • Download URL: appose-0.7.2.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for appose-0.7.2.tar.gz
Algorithm Hash digest
SHA256 e423b513ed0b8796edc8e575580a35f42f72b714b8b3e367546b80f37cef8628
MD5 fe28d85a5c72383c2984f4da8a3a673b
BLAKE2b-256 2e49d5386ed9dd90986e8ad6e53fe09788ab899d98d030801425bc9c17eb46a2

See more details on using hashes here.

File details

Details for the file appose-0.7.2-py3-none-any.whl.

File metadata

  • Download URL: appose-0.7.2-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for appose-0.7.2-py3-none-any.whl
Algorithm Hash digest
SHA256 09051fd4ea9c4d1d1872f82896ca35a8ec40f7f6792addc03077166f8586febf
MD5 3a73606de434cb141885daa80cfb2d70
BLAKE2b-256 f9835a056a5f877335355ae4d5c56131ea3e8bd6cba414fc0716e94597f85dde

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