Metadata-Version: 2.1
Name: yapapi
Version: 0.2.0
Summary: Hi-Level API for Golem The Next Milestone
Home-page: https://github.com/prekucki/yapapi
License: LGPL-3.0-or-later
Author: Przemysław K. Rekucki
Author-email: przemyslaw.rekucki@golem.network
Requires-Python: >=3.6.1,<4.0.0
Classifier: Development Status :: 1 - Planning
Classifier: Framework :: AsyncIO
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Topic :: System :: Distributed Computing
Provides-Extra: cli
Requires-Dist: aiohttp (>=3.6,<4.0)
Requires-Dist: async_exit_stack (>=1.0.1,<2.0.0)
Requires-Dist: dataclasses (>=0.7,<0.8); python_version >= "3.6" and python_version < "3.7"
Requires-Dist: fire (>=0.3.1,<0.4.0); extra == "cli"
Requires-Dist: jsonrpc-base (>=1.0.3,<2.0.0)
Requires-Dist: rich (>=2.2.5,<3.0.0); extra == "cli"
Requires-Dist: typing_extensions (>=3.7.4,<4.0.0)
Requires-Dist: urllib3 (>=1.25.9,<2.0.0)
Requires-Dist: ya-aioclient (>=0.1.1,<0.2.0)
Project-URL: Documentation, https://prekucki.github.io/yapapi/
Project-URL: Repository, https://github.com/prekucki/yapapi
Description-Content-Type: text/markdown

# Golem Python API

[![Tests - Status](https://img.shields.io/github/workflow/status/golemfactory/yapapi/Continuous%20integration/master?label=tests)](https://github.com/golemfactory/yapapi/actions?query=workflow%3A%22Continuous+integration%22+branch%3Amaster)
![PyPI - Status](https://img.shields.io/pypi/status/yapapi)
[![PyPI version](https://badge.fury.io/py/yapapi.svg)](https://badge.fury.io/py/yapapi)
[![GitHub license](https://img.shields.io/github/license/golemfactory/yapapi)](https://github.com/golemfactory/yapapi/blob/master/LICENSE)
[![GitHub issues](https://img.shields.io/github/issues/golemfactory/yapapi)](https://github.com/golemfactory/yapapi/issues)

## How to use

Rendering

```python
from yapapi.runner import Engine, Task, vm
from datetime import timedelta


async def main():
    package = await vm.repo(
        image_hash="ef007138617985ebb871e4305bc86fc97073f1ea9ab0ade9ad492ea995c4bc8b",
        min_mem_gib=0.5,
        min_storage_gib=2.0,
    )

    async def worker(ctx, tasks):
        ctx.send_file("./scene.blend", "/golem/resource/scene.blend")
        async for task in tasks:
            frame = task.data
            ctx.begin()
            crops = [
                {
                    "outfilebasename": "out",
                    "borders_x": [0.0, 1.0],
                    "borders_y": [0.0, 1.0],
                }
            ]
            ctx.send_json(
                "/golem/work/params.json",
                {
                    "scene_file": "/golem/resource/scene.blend",
                    "resolution": (800, 600),
                    "use_compositing": False,
                    "crops": crops,
                    "samples": 100,
                    "frames": [frame],
                    "output_format": "PNG",
                    "RESOURCES_DIR": "/golem/resources",
                    "WORK_DIR": "/golem/work",
                    "OUTPUT_DIR": "/golem/output",
                },
            )
            ctx.run("/golem/entrypoints/render_entrypoint.py")
            ctx.download_file("/golem/output/out.png", f"output_{frame}.png")
            yield ctx.commit(task)
            # TODO: Check if job is valid
            # and reject by: task.reject_task(reason = 'invalid file')
            task.accept_task()

        ctx.log("no more frame to render")

    async with Engine(
        package=package,
        max_worker=10,
        budget=10.0,
        timeout=timedelta(minutes=5),
    ) as engine:
        async for progress in engine.map(
            worker, [Task(data=frame) for frame in range(1, 101)]
        ):
            print("progress=", progress)
```

