Skip to main content

Appose Python

License PyPI Python Version Build Status

[!TIP] QUICK START: Appose Workshop

Build environments based on community standards (pixi, mamba, uv)
Run scripts in those environments as worker processes
Share memory between processes to avoid copying data

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 appose.service import ResponseType
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

Metadata

Release files for appose 0.12.0

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

Source distribution (sdist)

Source distribution for appose 0.12.0
File Size Uploaded
appose-0.12.0.tar.gz 67.9 kB Details

Built distribution (wheel)

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

Total release size: 143.1 kB

Release files / appose-0.12.0.tar.gz

Download URL appose-0.12.0.tar.gz
Size 67.9 kB
Tags Source
SHA-256 checksum
How to use checksums
2f73eaac3db95f9666ba5d2a2a89600b2605ff45fbf7f05afdbd368503ce2f53
BLAKE2b-256 checksum
How to use checksums
3c8d1203e933693d885f88465d18143346b6b20322ac40c14f98d3b7ea70ef4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / appose-0.12.0-py3-none-any.whl

Download URL appose-0.12.0-py3-none-any.whl
Size 75.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5c36f8293e824b049deb7393c53a46066ad67625f2de8ccb7f662eaa94ef5c80
BLAKE2b-256 checksum
How to use checksums
3312969743e8b7150d13b654756f3bb927c4a916747e16742c0e202e9a5e6a66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

0.12.0 This release

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.4.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

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