The Python implementation of the Ethernity CLOUD SDK protocol
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
Linux:
- build-essentials
- Python 3.10+
- docker
- docker-compose
Windows:
- Python 3.13
- Docker Desktop
Installation
To install the package and its dependencies, run:
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-publishregisters 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..., orECLD_CAS_ADDR=host:port) for the compose and the certificate harvest, and links the session to the published image.ecld-buildsigns 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.shruns 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, andecld-publishregisters no CAS session for them. - Testnet unsafe (no CAS) - the unsafe network beside the testnet (see "The testnets and their unsafe networks").
- Mainnet - to be provided during the following updates
- Testnet - tested and working. CAS-attested: the securelock is
provisioned by the ethernity-cas validator set exactly as on mainnet.
- LitVM:
- LiteForge - CAS-attested the same way, by LitVM's own ethernity-cas
validator set (SessionRegistry
0xfA70B5Df..., ValidatorRegistry0xbE3759f3..., ECImageRegistryV30xAf8Ce291...). - LiteForge unsafe (no CAS) - the unsafe network beside LiteForge.
- LiteForge - CAS-attested the same way, by LitVM's own ethernity-cas
validator set (SessionRegistry
- Polyhon:
- Amoy Testnet - to be provided during the following updates
- Mainnet - to be provided during the following updates
Scripts
-
Initialize: To initialize the project, run:
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:
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:
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-buildrecords the securelock it pushed in.config.json(SECURELOCK_IMAGE_DIGEST, the digest of the pushed manifest, andMRENCLAVE_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 keepslocalhost: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 runecld-buildwith the current SDK.DEVELOPER_FEEin.config.jsonis 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 unlessREWARD_ADDRESSnames another one; the image's owner can change it later with the registry'schangeImageRewardAddress.How the image reaches the network: unless
.config.jsonnames an IPFS API of your own (IPFS_ENDPOINT, orECLD_IPFS_ENDPOINTin 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 namingipfs.ethernity.cloudcounts as no endpoint (configs written by earlier versions ofecld-init): the publish runs its own node. For an API of your own that requires one,IPFS_TOKEN(orECLD_IPFS_TOKEN) is sent verbatim as theAuthorizationheader, 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 containerecld-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, andECLD_KUBO_IMAGE(defaultipfs/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. -
Test (local, no chain): To run your backend locally with the enclave's own executor — no SGX, no gas, instant — run:
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:
StateRegistryget/commit, ownership/ACL, andtask_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 servestarts a local API so the runner's LOCAL mode drives your real integration end to end. Exit code 0 onSUCCESS, 1 otherwise. -
Run (on the network): To submit a payload to the network and print the decrypted result, run:
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/v0is appended when the URL does not end in it), with--ipfs-token(orECLD_IPFS_TOKEN) sent verbatim as itsAuthorizationheader 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 isECLD_PRIVATE_KEY(plaintext) or the encryptedENC_PRIVATE_KEYunlocked withECLD_KEY_PASSWORD(or an interactive prompt). Resources are tunable with--task-price/--cpu/--memory/--storage/--bandwidth/--validators;--task-pricetakes a fractional price in tokens (2.5), passed as given; it needs a PoX 1.2 runner: runner-py 0.5.29 cannot encode a fractional price into its request (uint256 taskPrice), and on a network with an ERC-20 token it sends theapprovetransaction first and fails at the request, so until that runner use whole tokens. The execution object (below) comes from.config.json, theEXEC_*variables over it, and the flags--mode,--duration-hours(--duration),--parallelism,--max-cu,--headroom,--expected-inputs,--keep-open/--no-keep-open,--renew/--no-renew,--max-renewals,--expected-commitsover both;--relays-per-hourreplaces its computed default.--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 aSUCCESStask 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.pyremains available as a scriptable template if you prefer driving the runner yourself.)--unsaferuns the network's-unsafevariant (see below). -
Execution (how an order runs):
ecld-initwrites anEXECUTIONblock to.config.jsonwith every key of the execution object (tests/spec/execution-spec.json, shared with the runners and the JS SDK):"EXECUTION": { "mode": "task", "durationHours": 1, "parallelism": 1, "maxCu": 0, "headroomPercent": 25, "session": { "expectedInputs": 1, "keepOpen": false, "renew": false, "maxRenewals": 0 }, "esr": { "expectedCommits": 0 } }
modeistask(one payload run per order) orsession(the order stays open for inputs);durationHoursthe order duration, 1-65535;parallelismthe orders opened at once, each its own enclave;maxCuthe largest node paid for, in thousandths of a CU, 0 = any node;headroomPercentthe margin over the quoted price, 0-100;session.expectedInputsthe inputs the dApp expects to send, 1-256;session.keepOpenkeeps the session open until the dApp closes it;session.renewopens a new order on another node when the session expires with inputs pending,session.maxRenewals(>= 1 when renewing) bounding the renewals;esr.expectedCommitsthe state commits the dApp expects to relay per order, 0-100. Unattended, each key isECLD_EXEC_<KEY>(ECLD_EXEC_MODE,ECLD_EXEC_DURATION_HOURS,ECLD_EXEC_SESSION_EXPECTED_INPUTS, ... theEXEC_*names below with theECLD_prefix); interactively the step asks for the mode and the duration, the session keys in modesessionandesr.expectedCommitswith 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). The session block is accepted in both modes and applied in modesession.ecld-publishexports the block tosrc/.envasEXEC_MODE,EXEC_DURATION_HOURS,EXEC_PARALLELISM,EXEC_MAX_CU,EXEC_HEADROOM_PERCENT,EXEC_SESSION_EXPECTED_INPUTS,EXEC_SESSION_KEEP_OPEN,EXEC_SESSION_RENEW,EXEC_SESSION_MAX_RENEWALSandEXEC_ESR_EXPECTED_COMMITS, whichsrc/ethernity_task.pyreads back (execution.from_env(os.environ)) and passes nested asresources["execution"], withdurationHoursalso as the flatdurationa runner before PoX 1.2 reads. The relays an order needs per hour of its duration default to1 + expectedInputsrows, plus 10 commits with ESR enabled (execution.relays_per_hour);ecld-info executionprints the block and that number, andecld-run --relays-per-hour Nreplaces it. The runner takes the nested object and the relay rate once it carries the PoX 1.2 execution object; until then they are inert forrunner.run. -
The testnets and their unsafe networks:
Bloxberg Testnet(BLOXBERG_TESTNET),LitVM LiteForge(LITVM_LITEFORGE) andEthereum 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) andEthereum 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-unsafetrustedzone 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>-unsafeand runs on theetny-pynithy-testnet-unsafe(ecld-pynithy-litvm-testnet-unsafe) trustedzone. Mainnet has no unsafe network. -
Inspect (read-only): To read enclave and on-chain diagnostics — network, trustedzone/securelock registration, and ESR state — without spending gas, run:
ecld-info ecld-info esr state <key>
Usage
To use the SDK:
- after installation, run
ecld-initto initialize the project - in you workspace, you will find the
scr/serverlessdirectory, this contains abackend.pyfile. This file will be imported in the dApp images to provide the backend functions for calling from the frontend of your application, eg.:
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:
import os
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 before
# PoX 1.2 reads. A runner before PoX 1.2 takes whole tokens only as
# taskPrice; a fractional price (2.5) needs a PoX 1.2 runner.
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.
runner.run(
resources,
os.getenv("PROJECT_NAME"),
"v3",
code,
"",
os.getenv("TRUSTED_ZONE_IMAGE", ""),
)
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
hellofunction.
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.
Metadata
Release files for ethernity-cloud-sdk-py 0.10.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ethernity_cloud_sdk_py-0.10.4.tar.gz | 273.3 kB | Without provenance | Details for ethernity_cloud_sdk_py-0.10.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ethernity_cloud_sdk_py-0.10.4-py3-none-any.whl | Python 3 | none | any | Details for ethernity_cloud_sdk_py-0.10.4-py3-none-any.whl |
Total release size: 581.0 kB
Release files / ethernity_cloud_sdk_py-0.10.4.tar.gz
| Download URL | ethernity_cloud_sdk_py-0.10.4.tar.gz |
|---|---|
| Size | 273.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8bde3890b57a56177361aa3c9c44893beafe7aaa1ce39939351dc69c5dcdc66f
|
|
BLAKE2b-256 checksum How to use checksums |
0f43130d1928104809e08f2dcebbdcce6bbec8b7f5f37b11c5852e849250c2a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.5
|
Release files / ethernity_cloud_sdk_py-0.10.4-py3-none-any.whl
| Download URL | ethernity_cloud_sdk_py-0.10.4-py3-none-any.whl |
|---|---|
| Size | 307.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
62c9bdb332d428b6ea050077aee33d8d4e2bbab9687b90b34e61d2fc016dc606
|
|
BLAKE2b-256 checksum How to use checksums |
fc2373f90170e5444431857b651678402234d90a64063272fbae37a2fc3cfe9e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.5
|
Security for ethernity-cloud-sdk-py 0.10.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.