Metadata-Version: 2.4
Name: ethernity-cloud-sdk-py
Version: 1.9.0
Summary: Ethernity Cloud SDK Python
Home-page: https://github.com/ethernity-cloud/ethernity-cloud-sdk-py
Author: Ethernity Cloud Team
Author-email: contact@ethernity.cloud
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests
Requires-Dist: python-dotenv
Requires-Dist: tqdm
Requires-Dist: pyopenssl
Requires-Dist: requests_toolbelt
Requires-Dist: cryptography
Requires-Dist: typing-extensions
Requires-Dist: ethernity-cloud-runner-py<2.0.0,>=1.9.0
Requires-Dist: pyyaml
Dynamic: author
Dynamic: author-email
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-dist
Dynamic: summary


<p align="center">
  <a href="https://ethernity.cloud" title="Ethernity Cloud">
    <img src="https://ethernity.cloud/images/dark_gradient_logo.svg" alt="Ethernity Cloud logo" width="244" />
  </a>
</p>

<h3 align="center">The Python implementation of the Ethernity CLOUD SDK protocol</h3>

# Ethernity Cloud SDK PY

This project provides a set of tools and scripts to work with the Ethernity Cloud SDK in a python environment.

## Table of Contents

- [Pre-requisites](#pre-requisites)
- [Installation](#installation)
- [Usage](#usage)
  - [Scripts](#scripts)
- [Project Structure](#project-structure)
- [Contributing](#contributing)
- [License](#license)

## Pre-requisites
Linux:
- build-essentials
- Python 3.10+
- docker 
- docker-compose

Windows:
- Python 3.13
- Docker Desktop

## Installation

To install the package and its dependencies, run:

```sh
python -m venv venv

source venv/bin/activate # for MacOS and Linux
venv\Scripts\activate # for Windows

pip install ethernity-cloud-sdk-py
```

## Usage

After installation, you can use the provided scripts to build, publish, and initialize your project.

## Operating System compatibility
The sdk has been tested on the following operating systems:
- Windows 10
- linux (Ubuntu 20.04)

## Blockchain compatibility
- Bloxberg:
    - Testnet - tested and working. CAS-attested: the securelock is
      provisioned by the ethernity-cas validator set exactly as on mainnet.
      `ecld-publish` registers the image in the ImageRegistry
      (ECImageRegistryV3, `0xa372a6e1...`) before anything discloses its
      name, which makes the name the publishing wallet's; then registers the
      securelock session on-chain in the SessionRegistry (`0x78f0c5E9...`),
      which takes it only from that wallet, resolves a CAS from the
      ValidatorRegistry (`0xc346BfFC...`, or `ECLD_CAS_ADDR=host:port`) for
      the compose and the certificate harvest, and links the session to the
      published image. `ecld-build` signs the securelock `--production`.
      The certificate is harvested on an SGX host or, without one,
      extracted by publickey.ethernity.cloud, which fetches the image from
      the publish's IPFS node and attests it through a CAS member it
      resolves from the ValidatorRegistry. `tests/e2e_testnet_cas.sh` runs the whole
      path -- init, build, publish, one task, and the CAS validators'
      verdict on it. Amoy, IoTeX and Sepolia have no ethernity-cas
      deployment: their enclaves are debug-signed and sign their own
      certificates from their measurement, and `ecld-publish` registers no
      CAS session for them.
    - Testnet unsafe (no CAS) - the unsafe network beside the testnet (see
      "The testnets and their unsafe networks").
    - Testnet PoX 1.0 - a copy of the mainnet's PoX 1.0 contracts on the
      same chain (see "The testnet PoX 1.0 networks").
    - Mainnet - to be provided during the following updates
- LitVM:
    - LiteForge - CAS-attested the same way, by LitVM's own ethernity-cas
      validator set (SessionRegistry `0xfA70B5Df...`, ValidatorRegistry
      `0xbE3759f3...`, ECImageRegistryV3 `0xAf8Ce291...`).
    - LiteForge unsafe (no CAS) - the unsafe network beside LiteForge.
- Polyhon:
    - Amoy Testnet - to be provided during the following updates
    - Amoy PoX 1.0 - a copy of Polygon mainnet's PoX 1.0 contracts on Amoy
      (see "The testnet PoX 1.0 networks").
    - Mainnet - to be provided during the following updates

### Scripts

- **Initialize**: To initialize the project, run:
  ```sh
  ecld-init
  ```
  at this step, all the initial configurations will be set up and the project will be ready to be built, published and run.

- **Build**: To build the project, run:
  ```sh
  ecld-build
  ```
    the project will be built and the docker repository output will be stored in the `registry/` directory. This is the stage where the backend functions are added to the secure images.

- **Publish**: To publish the project, run:
  ```sh
  ecld-publish
  ```
  Required after build, to build and integrate the secure certificates that will be used during executions and to register the project to the Ethernity Cloud Image Register.

  What the publish measures: `ecld-build` records the securelock it pushed in
  `.config.json` (`SECURELOCK_IMAGE_DIGEST`, the digest of the pushed
  manifest, and `MRENCLAVE_SECURELOCK_SIGNED`, the MRENCLAVE it was signed
  with). The publish serves the build's own image tree (`build/registry`)
  from a registry container of the project's own, `ecld-registry-<project>`,
  on the loopback interface at a port free there, pulls and measures the
  enclave from there, and refuses to publish when that tree serves another
  digest or the measurement is not the recorded signed MRENCLAVE: a build of
  another project on the same machine in between does not reach the session.
  The shipped compose keeps `localhost:5000`, where a node's registry
  answers. The registry container is removed when the publish ends, on
  success and on failure alike; the publish's IPFS node is removed too,
  unless the publish ends between the image's registration and its
  certificate, when it stays running as the registered image's source (see
  "How the image reaches the network"). A project built by an SDK older than
  these records is refused with a message to run `ecld-build` with the
  current SDK.
  `DEVELOPER_FEE` in `.config.json` is your fee as the image's publisher, in
  percent of each task's base price (the node's price): the network adds it to
  what the dApp user pays and pays it to the image's reward address when the
  task is validated. Default 0; the registry accepts up to 15, and the fee is
  fixed once the image is registered. The reward address is the publishing
  wallet unless `REWARD_ADDRESS` names another one; the image's owner can
  change it later with the registry's `changeImageRewardAddress`.

  How the image reaches the network: unless `.config.json` names an IPFS API
  of your own (`IPFS_ENDPOINT`, or `ECLD_IPFS_ENDPOINT` in the environment),
  the publish runs its own IPFS node in docker (`ipfs/kubo`), adds the image
  and its compose there and peers it with the network's bootnode, which pins
  every registered image. An endpoint naming `ipfs.ethernity.cloud` counts as
  no endpoint (configs written by earlier versions of `ecld-init`): the
  publish runs its own node. For an API of your own that requires one,
  `IPFS_TOKEN` (or `ECLD_IPFS_TOKEN`) is sent verbatim as the `Authorization`
  header, on the image upload and on the session body's add alike; your own
  node needs none. On a network whose image registry records images
  before their certificate (the bloxberg testnet), the publish registers the
  image from your wallet first (`registerImage`, with your node's address),
  has the certificate extracted (on your SGX host, or by
  publickey.ethernity.cloud, which fetches the image from your node or the
  bootnode and reports its progress) and writes it from the same wallet
  (`setImageCert`). Keep the publish running until it prints the registration:
  your node is the image's first source, named on chain by its peer id. A
  publish that ends in between (an extraction that failed, an interrupt)
  leaves its node running, the docker container `ecld-kubo-<project>`, so
  the registered image stays fetchable from the peer id on chain; the next
  publish of the project takes that node over ("IPFS node of the previous
  publish kept", starting it again when a restart of docker stopped it),
  finds the image already registered and continues to the certificate, and
  keeps the node in turn should it end before the certificate.
  `docker rm -f ecld-kubo-<project>` stops it; a node started afresh has
  another peer id, which matches nothing on chain, and the image must then be
  rebuilt. `ECLD_KUBO_SWARM_PORT` (default 4001) is the port
  your node publishes when it is free; when another container holds it, the
  node runs without a published swarm port and is reached over the connection
  it opens to the bootnode, as a node behind NAT is. `ECLD_IPFS_PEERS`
  (comma-separated multiaddrs, default the bootnode) are the peers it keeps
  connected to, and `ECLD_KUBO_IMAGE` (default `ipfs/kubo:release`) the
  docker image it runs. On such a registry the publish waits up to three
  minutes for the service to queue the image from the chain event before
  posting the hash itself. On a network whose image registry records an
  image only with its certificate (the registry's first generation: bloxberg
  mainnet, Polygon mainnet and the two testnet PoX 1.0 networks) nothing is
  on chain for the bootnode to pin before the certificate exists, so a
  publish that runs its own node pins
  the compose and the image on the public IPFS API (`ipfs.ethernity.cloud`)
  before the certificate is extracted. That API takes a pin only with a
  writer token, `IPFS_TOKEN` (or `ECLD_IPFS_TOKEN`); without one the publish
  stops there, before anything is on chain. Each pin is asked with its
  progress (`pin/add` with `progress=true`), so the API answers with a line
  every half second while it fetches the blocks from your node and with one
  that names the CID once the pin is complete. When an answer ends without
  that line, breaks, stays silent for two minutes or is an error, the
  publish asks the API whether it holds the pin (`pin/ls`), and when it does
  not it asks for the pin again ten seconds later; a pin is asked five times
  at most, and not again once an hour has passed since the first. A pin that
  took more than one attempt says how many. A token the API refuses (a 401
  or 403) ends the pin at once, and a pin that fails ends the publish with
  what its last attempt ended with: the status and the start of the API's
  answer, its error message, how the connection failed, that the answer
  ended without the pin, or that the pin's time ran out.

  The fee per gas: on a network that sends EIP-1559 transactions (Polygon
  mainnet and Amoy, Ethereum Sepolia, LitVM LiteForge, the IoTeX testnet)
  every transaction of the publish offers the latest block's base fee plus a
  tenth, plus the network's priority fee (32 gwei on Polygon), as its
  `maxFeePerGas`, and none is sent above a ceiling. The default ceiling is
  the network's: 500 gwei on Polygon mainnet and on Amoy (its unsafe and its
  PoX 1.0 network included), which admits a base fee up to 425.4 gwei, 15 on
  Sepolia, 2 on LitVM LiteForge and 1500 on the IoTeX testnet.
  `ECLD_MAX_FEE_PER_GAS` in the environment, a positive whole number of gwei,
  is the ceiling instead, on whichever of those networks the publish runs:
  ```sh
  ECLD_MAX_FEE_PER_GAS=600 ecld-publish
  ```
  On Windows, in PowerShell and in cmd.exe, where it stays set for the rest
  of the session:
  ```powershell
  $env:ECLD_MAX_FEE_PER_GAS = "600"; ecld-publish
  ```
  ```bat
  set "ECLD_MAX_FEE_PER_GAS=600" && ecld-publish
  ```
  The quotes of the cmd.exe form keep the space before `&&` out of the
  value: `set ECLD_MAX_FEE_PER_GAS=600 && ecld-publish` stores `600` with a
  space after it, which is refused.
  `ecld-publish` checks the fee right after the gas balance, before it posts
  a session, pins the image or sends a transaction, and again at each send,
  from the base fee of the block that is the latest then. Above the ceiling
  it stops with exit code 1 and a message that states the base fee, the fee,
  the ceiling and what set it (`Polygon Mainnet: a base fee of 426 gwei puts
  the fee per gas at 500.6 gwei, above the network's default ceiling of 500
  gwei (ECLD_MAX_FEE_PER_GAS sets another, in whole gwei)`). A value of the
  variable that is not a positive whole number in up to 30 digits alone
  (`500 gwei`, `1.5`, `0`, a number with spaces around it) stops it the same
  way, with the variable and the value named; an empty one leaves the
  network's default. A network that sends legacy transactions (bloxberg)
  pays its fixed gas price and does not read the variable.
  `ecld-run` and the dApp's `src/ethernity_task.py` send through the runner
  (ethernity-cloud-runner-py), which bounds the fee of its own transactions:
  500 gwei on Polygon mainnet and on Amoy by default, and the same variable
  for another ceiling. This package requires runner 1.9.0 or a later 1.x
  (`ethernity-cloud-runner-py>=1.9.0,<2.0.0`), which holds the testnet PoX
  1.0 networks and that default on Amoy; the PoX 2.0 runners are 2.x.

- **Test (local, no chain)**: To run your backend locally with the enclave's own
  executor â€” no SGX, no gas, instant â€” run:
  ```sh
  ecld-test 'hello("World")'
  ecld-test --file payload.py
  ecld-test --input data.json 'process(___etny_data_set___)'
  ```
  This validates the *call* (function names, arguments, result wiring) before a
  single on-chain request is paid for. If your dApp uses ESR (Enclave State
  Registry), state is emulated locally and **on by default**: `StateRegistry`
  get/commit, ownership/ACL, and `task_caller()` all work in-process against an
  in-memory registry, and persist between runs in `.ecld-esr-local.*.json`. The
  task caller defaults to your developer address; override it with `--caller`.
  `ecld-test serve` starts a local API so the runner's LOCAL mode drives your
  real integration end to end. Exit code 0 on `SUCCESS`, 1 otherwise.

- **Run (on the network)**: To submit a payload to the network and print the
  decrypted result, run:
  ```sh
  ecld-run 'hello("World")'
  ecld-run --file payload.py
  ecld-run --input data.json 'process(___etny_data_set___)'
  ecld-run --json 'esr_increment()'
  ```
  This is the network-side sibling of `ecld-test`: instead of executing locally
  it drives the runner end to end â€” encrypt â†’ on-chain request â†’ payload intake
  â†’ wait for a node â†’ download and decrypt the result. The task's artefacts go
  through the bootnode's payload intake; `--ipfs <url>` uploads and reads them
  through a Kubo RPC API of your own instead (e.g. `http://127.0.0.1:5001`;
  `/api/v0` is appended when the URL does not end in it), with `--ipfs-token`
  (or `ECLD_IPFS_TOKEN`) sent verbatim as its `Authorization` header when that
  API requires one. It **costs gas and needs a funded
  key**. Network and enclaves come from `.config.json` (`BLOCKCHAIN_NETWORK`,
  `PROJECT_NAME`, `TRUSTED_ZONE_IMAGE`), overridable with
  `--network`/`--securelock`/`--trustedzone`; the signing key is
  `ECLD_PRIVATE_KEY` (plaintext) or the encrypted `ENC_PRIVATE_KEY` unlocked with
  `ECLD_KEY_PASSWORD` (or an interactive prompt). Resources are tunable with
  `--task-price`/`--cpu`/`--memory`/`--storage`/`--bandwidth`/`--validators`;
  `--task-price` takes a fractional price in tokens (`2.5`), passed as given;
  no runner-py up to 1.9.0 can encode a fractional price into its request
  (`uint8 _maxPrice`): on a network with an ERC-20 token it sends the
  `approve` transaction first and fails at the request, so use whole tokens
  until a runner that takes a fractional price is released.
  The execution object (below) comes from `.config.json`, the `EXEC_*`
  variables over it, and the flags `--mode`, `--duration-hours` (`--duration`),
  `--parallelism`, `--max-gflops`, `--headroom`, `--expected-inputs`,
  `--keep-open` / `--no-keep-open`, `--renew` / `--no-renew`,
  `--max-renewals`, `--expected-commits` over both;
  `--relays-per-hour` replaces its computed default. An unknown option is a
  usage error.
  `--input <file>` / `--input-text <string>` send the task's input dataset, read
  as `___etny_data_set___` (`ecld.input`); it travels encrypted, and the
  trustedzone checks it against the sha256 the request carries.
  Exit code 0 on a `SUCCESS` task result, 1 otherwise; a task that raised in the
  enclave prints its task code (e.g. `4 (BASE_EXCEPTION)`) and the traceback as
  its result. (`python src/ethernity_task.py`
  remains available as a scriptable template if you prefer driving the runner yourself.)
  `--unsafe` runs the network's `-unsafe` variant (see below).

- **Execution (how an order runs)**: `ecld-init` writes an `EXECUTION` block to
  `.config.json` with every key of the execution object
  (`tests/spec/execution-spec.json`, shared with the runners and the JS SDK):
  ```json
  "EXECUTION": {
    "mode": "task",
    "durationHours": 1,
    "parallelism": 1,
    "maxGflops": 0,
    "headroomPercent": 25,
    "session": { "expectedInputs": 1, "keepOpen": false, "renew": false, "maxRenewals": 0 },
    "esr": { "expectedCommits": 0 }
  }
  ```
  `mode` is `task` (one payload run per order) or `session` (the order stays
  open for inputs); `durationHours` the order duration, 1-65535;
  `parallelism` the orders opened at once, each its own enclave; `maxGflops`
  the largest node paid for, in GFLOPS (one CU is 100 GFLOPS), 0 = any node;
  `headroomPercent` the margin over the quoted price, 0-100;
  `session.expectedInputs` the inputs the dApp expects to send, 1-256;
  `session.keepOpen` keeps the session open until the dApp closes it;
  `session.renew` opens a new order on another node when the session expires
  with inputs pending, `session.maxRenewals` (>= 1 when renewing) bounding
  the renewals; `esr.expectedCommits` the state commits the dApp expects to
  relay per order, 0-100. Unattended, each key is `ECLD_EXEC_<KEY>` (`ECLD_EXEC_MODE`,
  `ECLD_EXEC_DURATION_HOURS`, `ECLD_EXEC_SESSION_EXPECTED_INPUTS`, ... the
  `EXEC_*` names below with the `ECLD_` prefix); interactively the step asks
  for the mode and the duration, the session keys in mode `session` and
  `esr.expectedCommits` with ESR enabled. A missing key takes its default;
  strings are parsed into numbers and booleans before the check; an unknown
  key, or a value outside its bounds, is refused with the schema's message
  (`execution.durationHours must be an integer between 1 and 65535`), and so
  is an `EXEC_*` (unattended `ECLD_EXEC_*`) variable that is not one of the
  execution variables below. The session block is accepted in both modes and
  applied in mode `session`.
  `ecld-publish` exports the block to `src/.env` as `EXEC_MODE`,
  `EXEC_DURATION_HOURS`, `EXEC_PARALLELISM`, `EXEC_MAX_GFLOPS`,
  `EXEC_HEADROOM_PERCENT`, `EXEC_SESSION_EXPECTED_INPUTS`,
  `EXEC_SESSION_KEEP_OPEN`, `EXEC_SESSION_RENEW`, `EXEC_SESSION_MAX_RENEWALS`
  and `EXEC_ESR_EXPECTED_COMMITS`, and drops any other `EXEC_*` line of that
  file; `src/ethernity_task.py` reads them back
  (`execution.from_env(os.environ)`) and passes the object nested as
  `resources["execution"]`, with `durationHours` also as the flat `duration`
  a runner without the PoX 2.0 execution object reads. The relays an order
  needs per hour of its duration default to `1 + expectedInputs` rows, plus
  10 commits with ESR enabled (`execution.relays_per_hour`);
  `ecld-info execution` prints the block and that number, and
  `ecld-run --relays-per-hour N` replaces it. The
  runner takes the nested object and the relay rate once it carries the
  PoX 2.0 execution object; until then they are inert for `runner.run`.

- **The testnets and their unsafe networks**: `Bloxberg Testnet` (`BLOXBERG_TESTNET`),
  `LitVM LiteForge` (`LITVM_LITEFORGE`) and `Ethereum Sepolia` (`ETHEREUM_SEPOLIA`)
  run your securelock in an enclave
  attested through that chain's Ethernity CAS validator set, on nodes whose
  platform the CAS can attest (DCAP). Each has an unsafe network beside it,
  `Bloxberg Testnet unsafe (no CAS)` (`BLOXBERG_TESTNET_UNSAFE`), `LitVM
  LiteForge unsafe (no CAS)` (`LITVM_LITEFORGE_UNSAFE`) and `Ethereum Sepolia
  unsafe (no CAS)` (`ETHEREUM_SEPOLIA_UNSAFE`): the same chain and
  contracts, for hardware SGX platforms the CAS cannot attest (EPID-only,
  SGX1). No CAS: enclaves are debug-signed and self-signed from their
  measurement, so a result proves which image ran but not that an enclave ran
  it. You choose an unsafe network by name, and the runner runs an `-unsafe`
  trustedzone on nothing else, so a dApp that runs without a CAS always says
  so in the network it names. A dApp publishes one securelock per network from
  two project directories with the same project name: the unsafe one is
  registered as `<project>-unsafe` and runs on the `etny-pynithy-testnet-unsafe`
  (`ecld-pynithy-litvm-testnet-unsafe`) trustedzone. Mainnet has no unsafe
  network.

- **The testnet PoX 1.0 networks**: `Bloxberg Testnet PoX 1.0`
  (`BLOXBERG_TESTNET_POX10`, the network `bloxberg_testnet_pox10`) and
  `Polygon Amoy PoX 1.0` (`POLYGON_AMOY_POX10`, `polygon_amoy_pox10`) are
  copies of the bloxberg mainnet's and of Polygon mainnet's PoX 1.0
  contracts, on the bloxberg chain (8995) and on Polygon Amoy (80002), beside
  the PoX 2.0 networks `BLOXBERG_TESTNET` and `POLYGON_AMOY`. `ecld-init`
  lists them after the other networks, and `ECLD_BLOCKCHAIN_NETWORK` takes
  the member name or the display name of either. A dApp is built and
  published for one as for the mainnet it copies:

  | | `BLOXBERG_TESTNET_POX10` | `POLYGON_AMOY_POX10` |
  |---|---|---|
  | PoX | `0x69A7bEB5Da2d3dA711d52E491D71e51296b08745`, also its token tE10 | `0x9Aad82557c84c11C4031382d8Bf2cacF8f256a02`, token tECLD `0x9927809B61122B2af3f3b3A3303875e0687b8eE3` |
  | Image registry (first generation) | `0x7dBC1b591cc3b7136D863bc7430C6Db50E929665` | `0xa2EE2a9118d0011AF05a6196c862D37d8c29F8eC` |
  | RPC | `https://bloxberg.ethernity.cloud` | `https://polygon-amoy-bor-rpc.publicnode.com` |
  | Trustedzone, and its SDK registry tag | `etny-pynithy-testnet-pox10`, `bloxberg_testnet_pox10` | `ecld-pynithy-amoy-pox10`, `polygon_amoy_pox10` |
  | Securelock session | `<project>_SECURELOCK_V3_bloxberg_testnet_pox10_<version>` | `<project>_SECURELOCK_V3_polygon_amoy_pox10_<version>` |
  | ESR | `0x0Ea1728EAE108FD3B9340ae91451348E2Cc6b4E4`, the bloxberg testnet's | none: `ecld-build` refuses an ESR-enabled enclave unless the project names a registry of its own |
  | Runner network | `("BLOXBERG", "TESTNET_POX10")` | `("POLYGON", "AMOY_POX10")` |

  `ecld-build` signs the securelock `--production`, and `ecld-publish` posts
  its session to Scontain's CAS, which also provisions the network's
  trustedzone, and registers the image with its certificate (`addImage`); a
  publish that runs its own IPFS node pins the image on the public IPFS API
  first, which takes `IPFS_TOKEN` (see "How the image reaches the network").
  Neither network has a SessionRegistry, a ValidatorRegistry or an unsafe
  network. The bootnode's payload intake does not serve them: `ecld-run`
  takes `--ipfs <url>` (with `--ipfs-token` for an API that requires one),
  and `src/ethernity_task.py` calls `runner.set_storage_ipfs(url, token)` in
  place of `runner.set_public_intake()`. The token of
  `BLOXBERG_TESTNET_POX10`, tE10, has no faucet: the wallet that pays for an
  order receives it by a transfer, and the runner refuses a request from a
  wallet that holds less than its escrow, before any transaction. On
  `POLYGON_AMOY_POX10` a wallet that holds less than the request's escrow
  draws tECLD from the token's faucet only while it holds less than 100
  tECLD, the balance below which that faucet gives; from 100 tECLD the
  runner refuses the request before any transaction, with the amount of
  tECLD a transfer has to bring. runner-py 1.9.0 applies the same rule on
  `POLYGON_AMOY` and `POLYGON_AMOY_UNSAFE`, whose token is the same tECLD.

- **Inspect (read-only)**: To read enclave and on-chain diagnostics â€” network,
  trustedzone/securelock registration, and ESR state â€” without spending gas, run:
  ```sh
  ecld-info
  ecld-info esr state <key>
  ```

## Usage

To use the SDK:
- after installation, run `ecld-init` to initialize the project
- in you workspace, you will find the `scr/serverless` directory, this contains a `backend.py` file. This file will be imported in the dApp images to provide the backend functions for calling from the frontend of your application, eg.:
```py
def hello(msg='World'):
    return "Hello "+msg
```
From your py application, using the ethernity cloud runner library, you will be calling the function as seen in the below example, where we pass `hello("World")` to be executed on the backend which will run in the Blockchain:
```py
import os
import time
from getpass import getpass
from dotenv import load_dotenv

load_dotenv()

from ethernity_cloud_runner_py.runner import EthernityCloudRunner  # type: ignore
from ethernity_cloud_sdk_py.commands import execution
from ethernity_cloud_sdk_py.commands.private_key import PrivateKeyManager


def execute_task() -> None:
    code = 'hello("Hello, Python World!")'

    # The funded 0x key that pays for the order. ecld-publish exports it to
    # src/.env as ENC_PRIVATE_KEY, encrypted with your key password (as a
    # plaintext PRIVATE_KEY only when told not to encrypt it).
    private_key = PrivateKeyManager(getpass("Private key password: ")).decrypt_private_key(
        os.getenv("ENC_PRIVATE_KEY")
    )

    runner = EthernityCloudRunner(os.getenv("NETWORK_NAME"), os.getenv("NETWORK_TYPE"))
    runner.set_private_key(private_key)
    # The task's artefacts go through the bootnode's payload intake; a Kubo RPC
    # API of your own goes in runner.set_storage_ipfs(url, token) instead.
    runner.set_public_intake()
    runner.connect()

    # The execution object from the EXEC_* variables ecld-publish exported
    # (ethernity_cloud_sdk_py.commands.execution; see "Execution" above):
    # nested, and its durationHours as the flat duration a runner without
    # the PoX 2.0 execution object reads. Such a runner takes whole tokens
    # only as taskPrice: no runner-py up to 1.9.0 encodes a fractional
    # price (2.5).
    execution_config = execution.validate(execution.from_env(os.environ))
    resources = {
        "taskPrice": 8,
        "cpu": 1,
        "memory": 1,
        "storage": 1,
        "bandwidth": 1,
        "duration": execution_config["durationHours"],
        "validators": 1,
        "execution": execution_config,
    }
    # run(resources, securelock, protocol version, code, node, trustedzone):
    # the version is the protocol's, "v3", under which the image registry keys
    # the securelock; an empty node lets any node take the order. run()
    # returns at once and the task proceeds on a thread of the runner's own.
    runner.run(
        resources,
        os.getenv("PROJECT_NAME"),
        "v3",
        code,
        "",
        os.getenv("TRUSTED_ZONE_IMAGE", ""),
    )

    # Wait for the task, printing each step it reaches, then its result or
    # its error.
    seen = None
    while runner.is_running():
        state = runner.get_state()
        if state["progress"] != seen:
            seen = state["progress"]
            print(f"[{seen}] {state['status']}")
        time.sleep(0.5)
    state = runner.get_state()
    if state["status"] == "SUCCESS":
        print(runner.get_result()["value"])
    else:
        print(f"Error: {state['last_error']}")


if __name__ == "__main__":
    execute_task()

```
- you are able to define the functions needed to be used in the backend, while making sure that the function that is script is compilable and that it exports the function that will be called from the frontend, in the above example, the `hello` function.

## Contributing

Contributions are welcome! Please open an issue or submit a pull request.

## License

This project is licensed under the AGPL-3.0 License. See the LICENSE file for details.
