# 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`.
### Conda/Mamba
To use [the conda-forge package](https://anaconda.org/conda-forge/appose),
add `appose` to your `environment.yml`'s `dependencies` section:
```yaml
dependencies:
- appose
```
### PyPI/Pip
To use [the PyPI package](https://pypi.org/project/appose),
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](https://packaging.python.org/en/latest/tutorials/packaging-projects/#creating-pyproject-toml)):
```toml
dependencies = [
"appose"
]
```
## Examples
Here is a minimal example for calling into Java from Python:
```python
import appose
env = appose.java(vendor="zulu", version="17").build()
with env.groovy() as groovy:
task = groovy.task("5 + 6")
task.waitFor()
result = task.outputs.get("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:
```python
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.
Raw data
{
"_id": null,
"home_page": "",
"name": "appose",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": "",
"keywords": "java,javascript,python,cross-language,interprocess",
"author": "Appose developers",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/cb/ea/9af571ed3b38b4f89f0bd33e05656e0462da6933b70043151218c227861b/appose-0.1.0.tar.gz",
"platform": null,
"description": "# Appose Python\n\n***WARNING: Appose is currently in incubation.\nNot all features described below are functional.\nThis document has some aspirational aspects!***\n\n## What is Appose?\n\nAppose is a library for interprocess cooperation with shared memory.\nThe guiding principles are *simplicity* and *efficiency*.\n\nAppose was written to enable **easy execution of Python-based deep learning\nfrom Java without copying tensors**, but its utility extends beyond that.\nThe steps for using Appose are:\n\n* Build an Environment with the dependencies you need.\n* Create a Service linked to a *worker*, which runs in its own process.\n* Execute scripts on the worker by launching Tasks.\n* Receive status updates from the task asynchronously via callbacks.\n\nFor more about Appose as a whole, see https://apposed.org.\n\n## What is this project?\n\nThis is the **Python implementation of Appose**.\n\n## How do I use it?\n\nThe name of the package is `appose`.\n\n### Conda/Mamba\n\nTo use [the conda-forge package](https://anaconda.org/conda-forge/appose),\nadd `appose` to your `environment.yml`'s `dependencies` section:\n\n```yaml\ndependencies:\n - appose\n```\n\n### PyPI/Pip\n\nTo use [the PyPI package](https://pypi.org/project/appose),\nadd `appose` to your project dependencies.\n\nDepending on how your project is set up, this might entail editing\n`requirements.txt`, `setup.py`, `setup.cfg`, and/or `pyproject.toml`.\n\nIf you are just starting out, we recommend using `pyproject.toml` (see\n[this guide](https://packaging.python.org/en/latest/tutorials/packaging-projects/#creating-pyproject-toml)):\n\n```toml\ndependencies = [\n \"appose\"\n]\n```\n\n## Examples\n\nHere is a minimal example for calling into Java from Python:\n\n```python\nimport appose\nenv = appose.java(vendor=\"zulu\", version=\"17\").build()\nwith env.groovy() as groovy:\n task = groovy.task(\"5 + 6\")\n task.waitFor()\n result = task.outputs.get(\"result\")\n assert 11 == result\n```\n\n*Note: The `Appose.java` builder is planned, but not yet implemented.*\n\nHere is an example using a few more of Appose's features:\n\n```python\nimport appose\nfrom time import sleep\n\ngolden_ratio_in_groovy = \"\"\"\n// Approximate the golden ratio using the Fibonacci sequence.\nprevious = 0\ncurrent = 1\nfor (i=0; i<iterations; i++) {\n if (task.cancelRequested) {\n task.cancel()\n break\n }\n task.update(null, i, iterations)\n v = current\n current += previous\n previous = v\n}\ntask.outputs[\"numer\"] = current\ntask.outputs[\"denom\"] = previous\n\"\"\"\n\nenv = appose.java(vendor=\"zulu\", version=\"17\").build()\nwith env.groovy() as groovy:\n task = groovy.task(golden_ratio_in_groovy)\n\n def task_listener(event):\n match event.responseType:\n case ResponseType.UPDATE:\n print(f\"Progress {task.current}/{task.maximum}\")\n case ResponseType.COMPLETION:\n numer = task.outputs[\"numer\"]\n denom = task.outputs[\"denom\"]\n ratio = numer / denom\n print(f\"Task complete. Result: {numer}/{denom} =~ {ratio}\");\n case ResponseType.CANCELATION:\n print(\"Task canceled\")\n case ResponseType.FAILURE:\n print(f\"Task failed: {task.error}\")\n\n task.listen(task_listener)\n\n task.start()\n sleep(1)\n if not task.status.is_finished():\n # Task is taking too long; request a cancelation.\n task.cancel()\n\n task.wait_for()\n```\n\nOf course, the above examples could have been done all in one language. But\nhopefully they hint at the possibilities of easy cross-language integration.\n",
"bugtrack_url": null,
"license": "Simplified BSD License",
"summary": "Appose: multi-language interprocess cooperation with shared memory.",
"version": "0.1.0",
"project_urls": {
"documentation": "https://github.com/apposed/appose-python/blob/main/README.md",
"download": "https://pypi.org/project/appose-python",
"homepage": "https://github.com/apposed/appose-python",
"source": "https://github.com/apposed/appose-python",
"tracker": "https://github.com/apposed/appose-python/issues"
},
"split_keywords": [
"java",
"javascript",
"python",
"cross-language",
"interprocess"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9148897fa7a6f9b0282ccdc694010f501dc858402d847554ce52e0876c85e800",
"md5": "a27d9c8bdaab44731cf927239feb338d",
"sha256": "536439fe3620e7f2b5dad169bb39818d586983f29ef70d8ab1900d93a5fc867b"
},
"downloads": -1,
"filename": "appose-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a27d9c8bdaab44731cf927239feb338d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 17853,
"upload_time": "2023-06-23T02:56:26",
"upload_time_iso_8601": "2023-06-23T02:56:26.393223Z",
"url": "https://files.pythonhosted.org/packages/91/48/897fa7a6f9b0282ccdc694010f501dc858402d847554ce52e0876c85e800/appose-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "cbea9af571ed3b38b4f89f0bd33e05656e0462da6933b70043151218c227861b",
"md5": "268f7a57b775cc49c12322c5d1190acf",
"sha256": "0a06cc32d225634b2a68ed7d900e515c3d4027cde8f8bf205414412b9083978e"
},
"downloads": -1,
"filename": "appose-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "268f7a57b775cc49c12322c5d1190acf",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 14291,
"upload_time": "2023-06-23T02:56:27",
"upload_time_iso_8601": "2023-06-23T02:56:27.988663Z",
"url": "https://files.pythonhosted.org/packages/cb/ea/9af571ed3b38b4f89f0bd33e05656e0462da6933b70043151218c227861b/appose-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-23 02:56:27",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "apposed",
"github_project": "appose-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "appose"
}