An open API service indexing awesome lists of open source software.

https://github.com/golemcloud/golem-py

A library that helps with writing Golem components in Python
https://github.com/golemcloud/golem-py

Last synced: 5 months ago
JSON representation

A library that helps with writing Golem components in Python

Awesome Lists containing this project

README

          

# golem-cloud
A library that helps with writing [Golem](https://www.golem.cloud/) components in Python

## Usage

golem-cloud is built on top of [componentize-py](https://github.com/bytecodealliance/componentize-py) and relies on bindings generated by it to work.
To set up a project begin by creating a wit directory and defining a world that your component will implement:

```wit
package demo-namespace:demo-package;

interface demo-api {
run: func();
}

world demo-world {
import wasi:http/types@0.2.0;
import wasi:http/outgoing-handler@0.2.0;
import golem:api/host@1.1.6;

export demo-api;
}
```

To enable usage of golem-cloud with your project you need to tell it about your world and where the bindings will be generated by componentize-py. To do this include
the following code snippet at the top of your python code. Make sure to place it before any other uses of the golem-cloud library.

```python
import golem_py_bindings
golem_py_bindings.register_bindings("demo_world") # Put the name of your world here
```

You can now use golem-cloud in your project:
```python
from golem_py.durability import Durability, DurableFunctionType
from demo_world.imports.oplog import WrappedFunctionType_ReadLocal

durability = Durability("custom", "random-number-generator", WrappedFunctionType_ReadLocal)
```

Note:
golem-cloud is using bindings that are generated by componentize-py for your world. You can only use the modules in golem-cloud for which you have all necessary bindings (by having the appropriate imports and exports in your world). Trying
to use a module for which your don't have all required bindings will fail with an import error (even if the initial register_bindings was successful). Every module in golem-cloud documents which bindings are required for it to work, so please consult the module documentation.