Skip to main content

API and CLI for Soroban contracts in Python

Project description

API and CLI for Soroban contracts in Python

This package provide tools to interact with Soroban contracts in Python. The goal is to provide a simple feature set while not depending on the Rust SDK. This can be useful in environment where Rust and the SDK might be more difficult to get working (like a Raspberry Pi).

Getting started

pip install soroban

This provides a simple way to call contracts without needing to install the Rust SDK and is a higher level interface compared to using the Python SDK.

import soroban

soroban.invoke(contract_id="AAAA...", function_name="increment")

Identity and Network configurations are automatically pulled from the local configuration or the current working directory. See bellow.

It also provides a CLI

soroban invoke C... version --source-account=...

Usage

The main feature is to be able to call a Soroban contract function: soroban.invoke.

import soroban

soroban.invoke(contract_id="AAAA...", function_name="increment")

It also supports passing arguments as a list of stellar_sdk.SCVal. This list can be easily generated

import json
import soroban

args = json.load(...)
args = soroban.Parameters(args=args)
soroban.invoke(contract_id="AAAA...", function_name="init", args=args)

The following JSON syntax is supported. Note that vectors are also supported:

[
  {
    "name": "issuer",
    "type": "address",
    "value": "C..."
  },
  {
    "name": "distributor",
    "type": "int128",
    "value": 10
  },
  {
    "name": "claimants",
    "type": "vec",
    "value": [
      {
        "type": "uint32",
        "value": 12
      },
      {
        "type": "int64",
        "value": 20
      }
    ]
  }
]

A few helper functions are also provided:

  • soroban.create_account: create and fund an account from a source account;
  • soroban.create_asset: create an asset using the classical issuer/distributor model.

Configuration

The source account and the network to use are set by instantiating soroban.Identity and soroban.NetworkConfig, respectively:

import soroban

identity = soroban.Identity()
network = soroban.NetworkConfig()

In both cases, the configuration can be set by either adjusting init arguments, setting up environment variables or using configuration files in toml.

The default path for soroban.Identity is identity.toml and for soroban.NetworkConfig it is testnet.toml. Here are examples of these files:

secret_key = "S..."
horizon_url = "https://horizon-testnet.stellar.org"
rpc_url = "https://soroban-testnet.stellar.org"
network_passphrase = "Test SDF Network ; September 2015"

Any of these fields can be set as an environment variable.

Acknowledgements

This repository has no affiliation with the Stellar Developer Foundation. The official CLI can be found here https://github.com/stellar/soroban-cli Should this become useful, I am happy to transfer it as well to the SDF org!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

soroban-0.9.1.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

soroban-0.9.1-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file soroban-0.9.1.tar.gz.

File metadata

  • Download URL: soroban-0.9.1.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for soroban-0.9.1.tar.gz
Algorithm Hash digest
SHA256 b5c7c3b73ac0706967f2b9bd17e7e05c6c28dd285dcca0ebee57a4a36d41e7a1
MD5 826de88e98e68b2ec6c89e7e31f871b6
BLAKE2b-256 9e2d8c9c3f3f465e4ac647bd66096290bedf0a5631ee762ee3c59662e57439d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for soroban-0.9.1.tar.gz:

Publisher: release.yaml on tupui/soroban-cli-python

Attestations:

File details

Details for the file soroban-0.9.1-py3-none-any.whl.

File metadata

  • Download URL: soroban-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for soroban-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1a9aa2535603942486bbadf19aca95816af400221cc808575c68cb48b4c2e621
MD5 6add22b70e4e52e5c6818bfcc6df247b
BLAKE2b-256 722e5fa9600340773d516c3a88831a1fa414bfbca5404fb524aefbb19bb71144

See more details on using hashes here.

Provenance

The following attestation bundles were made for soroban-0.9.1-py3-none-any.whl:

Publisher: release.yaml on tupui/soroban-cli-python

Attestations:

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page