pysui.sui package

Subpackages

Submodules

pysui.sui.sui_apidesc module

Sui RPC API Descriptor.

class pysui.sui.sui_apidesc.SuiJsonType

Bases: ABC

Sui Json Type.

class pysui.sui.sui_apidesc.SuiJsonNull(type: str, type_path: list[str])

Bases: DataClassJsonMixin, SuiJsonType

Sui Json Null Value.

type: str
type_path: list[str]
__init__(type: str, type_path: list[str]) None
class pysui.sui.sui_apidesc.SuiJsonValue(type: str, type_path: list[str])

Bases: DataClassJsonMixin, SuiJsonType

Sui Json Value.

type: str
type_path: list[str]
__init__(type: str, type_path: list[str]) None
class pysui.sui.sui_apidesc.SuiJsonString(type: str, type_path: list[str])

Bases: DataClassJsonMixin, SuiJsonType

Sui Json String.

type: str
type_path: list[str]
__init__(type: str, type_path: list[str]) None
class pysui.sui.sui_apidesc.SuiJsonBoolean(type: bool, type_path: list[str])

Bases: DataClassJsonMixin, SuiJsonType

Sui Json Boolean.

type: bool
type_path: list[str]
__init__(type: bool, type_path: list[str]) None
class pysui.sui.sui_apidesc.SuiJsonInteger(type: str, type_path: list[str], format: str, minimum: float)

Bases: DataClassJsonMixin, SuiJsonType

Sui Json Integer.

type: str
type_path: list[str]
format: str
minimum: float
__init__(type: str, type_path: list[str], format: str, minimum: float) None
class pysui.sui.sui_apidesc.SuiJsonArray(type: str, type_path: list[str], items: SuiJsonType)

Bases: DataClassJsonMixin, SuiJsonType

Sui Json Array.

type: str
type_path: list[str]
items: SuiJsonType
__init__(type: str, type_path: list[str], items: SuiJsonType) None
class pysui.sui.sui_apidesc.SuiJsonTuple(type: str, type_path: list[str], items: SuiJsonType, minItems: int | None = None, maxItems: int | None = None)

Bases: DataClassJsonMixin, SuiJsonType

Sui Json Tuple.

type: str
type_path: list[str]
items: SuiJsonType
minItems: int = None
maxItems: int = None
__init__(type: str, type_path: list[str], items: SuiJsonType, minItems: int | None = None, maxItems: int | None = None) None
class pysui.sui.sui_apidesc.SuiJsonEnum(type: str, type_path: list[str], enum: list[str])

Bases: DataClassJsonMixin, SuiJsonType

Sui Json Enum.

type: str
type_path: list[str]
enum: list[str]
__init__(type: str, type_path: list[str], enum: list[str]) None
class pysui.sui.sui_apidesc.SuiJsonObject(type: str, type_path: list[str])

Bases: DataClassJsonMixin, SuiJsonType

Sui Json Enum.

type: str
type_path: list[str]
__init__(type: str, type_path: list[str]) None
class pysui.sui.sui_apidesc.SuiApiParam(name: str, schema: dict | SuiJsonType, required: bool = False, description: str = '')

Bases: object

Sui API Parameter Data Class.

name: str
classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
required: bool = False
description: str = ''
__init__(name: str, schema: dict | SuiJsonType, required: bool = False, description: str = '') None
classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: str | int | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
class pysui.sui.sui_apidesc.SuiApiResult(name: str, schema: dict | SuiJsonType, required: bool | None = False)

Bases: object

Sui API Result Data Class.

name: str
classmethod schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) SchemaF[A]
required: bool | None = False
__init__(name: str, schema: dict | SuiJsonType, required: bool | None = False) None
classmethod from_dict(kvs: dict | list | str | int | float | bool | None, *, infer_missing=False) A
classmethod from_json(s: str | bytes | bytearray, *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) A
to_dict(encode_json=False) Dict[str, dict | list | str | int | float | bool | None]
to_json(*, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: str | int | None = None, separators: Tuple[str, str] | None = None, default: Callable | None = None, sort_keys: bool = False, **kw) str
class pysui.sui.sui_apidesc.SuiApi(name: str, params: list[SuiApiParam], result: SuiApiResult, description: str = '')

Bases: DataClassJsonMixin

Sui API Data Class.

name: str
params: list[SuiApiParam]
result: SuiApiResult
description: str = ''
__init__(name: str, params: list[SuiApiParam], result: SuiApiResult, description: str = '') None
pysui.sui.sui_apidesc.build_api_descriptors(indata: dict) tuple[str, dict, dict]

Build the schema dictionary then API call dictionary.

pysui.sui.sui_bcs module

Sui BCS Conversions [EXPERIMENTAL].

pysui.sui.sui_bcs.get_txkind_from_tx_bytes(tx_bytes: str) bytes

get_txkind_from_tx_bytes extracts the TransactionKind bytes from tx_bytes.

Parameters:

tx_bytes (str) – base64 transaction bytes string

Returns:

Transaction Kind as bytes.

Return type:

bytes

pysui.sui.sui_bcs.get_txkind_from_result_asb64(indata: SuiRpcResult) str | SuiRpcResult

inspect_ready_txkind_from_result Return a serialized TransactionKind as base64 encoded string.

Can be then used to submit to InspectTransaction

Parameters:

indata (SuiRpcResult) – The result of calling a complex transaction prior to signing

Returns:

A base64 encoded serialized TransactionKind

Return type:

str

pysui.sui.sui_bcs.get_txkind_from_result(indata: SuiRpcResult) TransactionKind | Exception

transaction_kind_from_rpcresult converts the transaction bytes into BCS TransactionKind struct.

Parameters:

indata (SuiRpcResult) – The result of calling a complex transaction prior to signing

Raises:

ValueError – If the SuiRpcResult contains error

Returns:

A TransactionKind structure represented in the SuiRpcResult base64 transaciton bytes

Return type:

Union[bcs.TransactionKind, Exception]

pysui.sui.sui_config module

Default Sui Configuration.

class pysui.sui.sui_config.SuiConfig(config_path: str, keystore_file: str, alias_file: str | None = None)

Bases: ClientConfiguration

Sui default configuration class.

rename_alias(*, old_alias: str, new_alias: str) None

rename_alias Renames existing alias.

Parameters:
  • old_alias (str) – Existing alias name

  • new_alias (str) – Replacement name

Raises:

ValueError – Invalid arguments

Returns:

None

Return type:

NoneType

create_new_keypair_and_address(*, scheme: SignatureScheme, word_counts: int | None = 12, derivation_path: str | None = None, make_active: bool | None = False, alias: str | None = None) tuple[str, SuiAddress]

create_new_keypair_and_address Create a new keypair and address identifier and writes to client.yaml.

Parameters:
  • scheme (SignatureScheme) – Identifies whether new key is ed25519, secp256k1 or secp256r1

  • word_counts (int, optional) – count of words to generate mnemonic phrase, defaults to 12

  • derivation_path (str, optional) – The derivation path for key, specific to Signature scheme, defaults to root path of scheme

  • make_active (bool, optional) – Flag to make address from created KeyPair the ‘active_address’, defaults to False

  • alias (Optional[str], optional) – Associates alias string to newly created kp and address,defaults to None If not provide, alias will be generated

Raises:

NotImplementedError – When providing unregognized scheme

Returns:

The input or generated mnemonic string and the new keypair associated SuiAddress

Return type:

tuple[str, SuiAddress]

Changed in version 0.42.0: Changed to require keyword arguments.

Changed in version 0.41.0: Added make_active flag.

Changed in version 0.41.0: Support aliases.

Changed in version 0.33.0: Return mnemonics to caller.

recover_keypair_and_address(scheme: SignatureScheme, mnemonics: str | list[str], derivation_path: str, install: bool = False, make_active: bool | None = False, alias: str | None = None) tuple[str, SuiAddress]

recover_keypair_and_address Recover a keypair from mnemonic string.

Parameters:
  • scheme (SignatureScheme) – Identifies whether new key is ed25519, secp256k1 or secp256r1

  • mnemonics (str) – string of phrases separated by spaces

  • derivation_path (str) – The derivation path for key, specific to Signature scheme

  • install (bool, optional) – Flag indicating to write back to sui.keystore, defaults to False This flag is ignored if config was initiated through ‘user_config()’

  • make_active (bool, optional) – Flag to make address from created KeyPair the ‘active_address’, defaults to False

  • alias (Optional[str], optional) – Associates alias string to newly created kp and address,defaults to None If not provide, alias will be generated

Raises:
  • NotImplementedError – When providing unregognized scheme

  • ValueError – If recovered keypair/address already exists

Returns:

The input mnemonic string and the new keypair associated SuiAddress

Return type:

tuple[str, SuiAddress]

Changed in version 0.41.0: Added make_active flag.

Changed in version 0.41.0: Support aliases.

Changed in version 0.33.0: If install is True, checks if not in ‘user_config’ setup before writing

New in version 0.24.0: Added to recover keypairs

add_keypair_from_keystring(*, keystring: str | dict, install: bool = False, make_active: bool | None = False, alias: str | None = False) SuiAddress

add_keypair_from_keystring Adds a KeyPair from Sui keystring.

Parameters:
  • keystring (Union[str, dict]) –

    Either a valid Sui keystring (flag | private 32 byte seed) in base64 form or a dictionary for conversion from wallet:

    {
        'wallet_key':'0x.....',                 # Wallet exported key hex string
        'key_scheme': SignatureScheme.ED25519   # Must align with wallet_key type
    }
    

  • install (bool, optional) – Flag indicating to write back to sui.keystore, defaults to False This flag is ignored if config was initiated through ‘user_config()’

  • make_active (bool, optional) – Flag to make address from created KeyPair the ‘active_address’, defaults to False

  • alias (Optional[str], optional) – Associates alias string to newly created kp and address,defaults to None If not provide, alias will be generated

Raises:

ValueError – If the derived address is already registered in SuiConfig

Returns:

The derived SuiAddress

Return type:

SuiAddress

Changed in version 0.41.0: Support aliases.

New in version 0.33.0: Allow import from valid Sui keystring or Wallet key export

classmethod default_config() SuiConfig

default_config Loads the configuration created by use of sui binaries sui client

Raises:

SuiFileNotFound – If Sui configuration does not exist

Returns:

Instantiated configuration ready for use

Return type:

SuiConfig

Changed in version 0.41.0: Sui aliases configuration feature added

New in version 0.16.1: New loading of default configuration.

classmethod pysui_config(cfg_path: str) SuiConfig

pysui_config Loads an alternate configuration from specified path.

This behaves as a normal configuration where address and alias adds/changes are persisted

Parameters:

cfg_path (str) – path to folder holding alternate configuration

Raises:

SuiFileNotFound – If path is invalid

Returns:

Instantiated configuration ready for use

Return type:

SuiConfig

New in version 0.51.0: New alternate configuration path loading.

classmethod sui_base_config() SuiConfig

sui_base_config Loads the active configuration set by suibase

Returns:

Instantiated configuration ready for use

Return type:

SuiConfig

New in version 0.16.1: Supporting more flexible non-default configurations

classmethod user_config(*, rpc_url: str, prv_keys: list[str | dict] | None = None, ws_url: str | None = None, gql_url: str | None = None) SuiConfig

user_config Load a user defined configuraiton.

Note: New address/keypairs added in this session are not persisted. Note: publish is not available in this option.

Parameters:
  • rpc_url (str) – he RPC url for RPC API interaction

  • prv_keys (Optional[list[Union[str, dict]]], optional) –

    Optional list containing either valid Sui keystrings (flag | private 32 byte seed) in base64 form and/or dictionaries for conversion from Wallet key exports:

    {
        'wallet_key':'0x.....',                 # Wallet exported key hex string
        'key_scheme': SignatureScheme.ED25519   # Must align with wallet_key type
    }
    

  • ws_url (Optional[str], optional) – Optional wss url for subscriptions, defaults to None

  • gql_url (Optional[str], optional) – Optional GraphQL RPC url, defaults to None

Returns:

An instance of SuiConfig that can be used to initialize a SuiClient

Return type:

SuiConfig

Changed in version 0.34.0: Add support for suibase localnet proxy

Changed in version 0.33.0: Add support for importing Wallet private keys

Changed in version 0.26.0: Relax initialization requirements of prv_keys

New in version 0.25.0: Removes reliance on client.yaml

property rpc_url: str

Return the current URL.

property graphql_url: str

Return the GraphQL RPC URL.

property local_config: bool

Return the mode we are running in.

property faucet_url: str

Return faucet url.

property socket_url: str

Return socket url.

property active_address: SuiAddress

Return the current address.

property environment: str

environment Return the current environment of config in use.

Returns:

The environment name

Return type:

str

set_active_address(address: SuiAddress) SuiAddress

Change the active address to address.

pysui.sui.sui_constants module

Sui Constants.

pysui.sui.sui_constants.PYSUI_EXEC_ENV: str = 'SUI_EXEC'

Holds the fully qualified path to the active sui binary.

pysui.sui.sui_constants.PYSUI_CLIENT_CONFIG_ENV: str = 'SUI_CLIENT_CONFIG'

Holds the fully qualified path to the active client.yaml.

pysui.sui.sui_constants.PYSUI_RPC_VERSION: str = 'SUI_RPC_VERSION'

Holds the RPC version detected at runtime.

pysui.sui.sui_constants.SUI_BASE_ACTIVE: str = '~/suibase/workdirs/active'

sui-base symbolic link to what configuration is active.

pysui.sui.sui_constants.SUI_BASE_EXEC_PATH: str = 'target/debug/sui'

sui-base binary location relative to the active configuration workdir.

pysui.sui.sui_constants.DEFAULT_SUI_BINARY_PATH: str = '~/.cargo/bin/sui'

The default fully qualified sui binary path.

pysui.sui.sui_constants.DEFAULT_ALIAS_PATH_STRING: str = '~/.sui/sui_config/sui.aliases'

Devnet client configuration default.

pysui.sui.sui_constants.DEVNET_ENVIRONMENT_KEY: str = 'devnet'

Devnet client configuration environment alias.

pysui.sui.sui_constants.LOCALNET_ENVIRONMENT_KEY: str = 'localnet'

Localnet client configuration environment alias.

pysui.sui.sui_constants.TESTNET_ENVIRONMENT_KEY: str = 'testnet'

Testnet client configuration environment alias.

pysui.sui.sui_constants.DEVNET_SUI_URL: str = 'https://fullnode.devnet.sui.io:443'

Devnet Sui client url.

pysui.sui.sui_constants.DEVNET_FAUCET_STATUS_URLV1: str = 'https://faucet.devnet.sui.io/v1/status/'

Devnet client faucet url V1.

pysui.sui.sui_constants.DEVNET_SOCKET_URL: str = 'wss://fullnode.devnet.sui.io:443'

Devnet socket url.

pysui.sui.sui_constants.LOCALNET_SUI_URL: str = 'https://127.0.0.1:9000'

Testnet Sui client url.

pysui.sui.sui_constants.LOCALNET_PROXY_SUI_URL: str = 'http://0.0.0.0:44340'

Testnet Sui proxy client url.

pysui.sui.sui_constants.LOCALNET_FAUCET_URL: str = 'http://127.0.0.1:9123/gas'

Localnet client faucet url.

pysui.sui.sui_constants.LOCALNET_SOCKET_URL: str = 'ws://127.0.0.1:9000'

Localnet socket url.

pysui.sui.sui_constants.TESTNET_SUI_URL: str = 'https://fullnode.testnet.sui.io:443'

Testnet Sui client url.

pysui.sui.sui_constants.TESTNET_SOCKET_URL: str = 'wss://fullnode.testnet.sui.io:443'

Testnet socket url.

pysui.sui.sui_constants.MAINNET_SUI_URL: str = 'https://fullnode.mainnet.sui.io:443'

Testnet Sui client url.

pysui.sui.sui_constants.MAINNET_FAUCET_URL: str = ''

Mainnet client faucet url.

pysui.sui.sui_constants.MAINNET_SOCKET_URL: str = 'wss://fullnode.mainnet.sui.io:443'

Testnet socket url.

pysui.sui.sui_constants.EMPEHMERAL_PATH: str = 'ephemeral'

A user memory only configuration path

pysui.sui.sui_constants.EMPEHMERAL_USER: str = 'user'

A user memory only configuration

pysui.sui.sui_constants.SUI_MIN_ALIAS_LEN: int = 3

Minimal length of an alias name string.

pysui.sui.sui_constants.SUI_MAX_ALIAS_LEN: int = 64

Maximum length of an alias name string.

pysui.sui.sui_constants.SUI_HEX_ADDRESS_STRING_LEN: int = 66

Length of valid address string with ‘0x’ prefix.

pysui.sui.sui_constants.SUI_ADDRESS_STRING_LEN: int = 64

Length of valid address string without ‘0x’ prefix.

pysui.sui.sui_constants.SUI_KEYPAIR_LEN: int = 44

Length of valid key string base64 string.

pysui.sui.sui_constants.PRIVATE_KEY_BYTE_LEN: int = 32

Byte length of general private key

pysui.sui.sui_constants.SCHEME_PRIVATE_KEY_BYTE_LEN: int = 33

Byte length of general signature scheme and private key

pysui.sui.sui_constants.ED25519_KEYPAIR_BYTES_LEN: int = 32

Length of ED25519 keypair bytes.

pysui.sui.sui_constants.ED25519_PUBLICKEY_BYTES_LEN: int = 32

Length of ED25519 public key bytes.

pysui.sui.sui_constants.ED25519_PRIVATEKEY_BYTES_LEN: int = 32

Length of ED25519 private key bytes.

pysui.sui.sui_constants.SECP256K1_KEYPAIR_BYTES_LEN: int = 32

Length of SECP256K1 keypair bytes.

pysui.sui.sui_constants.SECP256K1_PUBLICKEY_BYTES_LEN: int = 33

Length of SECP256K1 public key bytes.

pysui.sui.sui_constants.SECP256K1_PRIVATEKEY_BYTES_LEN: int = 32

Length of SECP256K1 private key bytes.

pysui.sui.sui_constants.SECP256R1_KEYPAIR_BYTES_LEN: int = 32

Length of SECP256R1 keypair bytes.

pysui.sui.sui_constants.SECP256R1_PUBLICKEY_BYTES_LEN: int = 33

Length of SECP256R1 public key bytes.

pysui.sui.sui_constants.SECP256R1_PRIVATEKEY_BYTES_LEN: int = 32

Length of SECP256R1 private key bytes.

pysui.sui.sui_crypto module

Sui Crpto Keys and Keypairs.

class pysui.sui.sui_crypto.SuiPublicKey(scheme: SignatureScheme, key_bytes: bytes)

Bases: PublicKey

SuiPublicKey Sui Basic public key.

property pub_key: str

Return self as base64 encoded string.

class pysui.sui.sui_crypto.SuiPrivateKey(scheme: SignatureScheme, key_bytes: bytes)

Bases: PrivateKey

SuiPrivateKey Sui Basic private/signing key.

Changed in version 0.33.0: Converted to use pysui-fastcrypto

sign_secure(tx_data: str) list

sign_secure Sign transaction intent.

Parameters:
  • public_key (SuiPublicKey) – PublicKey from signer/private key

  • tx_data (str) – Transaction bytes being signed

Returns:

Singed transaction as list of u8 bytes

Return type:

list

class pysui.sui.sui_crypto.SuiKeyPair

Bases: KeyPair

SuiKeyPair Sui Basic keypair.

Changed in version 0.33.0: Converted to use pysui-fastcrypto

__init__() None

__init__ Default keypair initializer.

property private_key: SuiPrivateKey | None

Return the Private Key.

property public_key: SuiPublicKey | None

Return the Public Key.

property scheme: SignatureScheme

Get the keys scheme.

new_sign_secure(tx_data: str) SuiSignature

New secure sign with intent.

Changed in version 0.33.0: Changes to SuiPrivateKey

sign_message(message: str) str

Sign arbitrary message, returning it’s base64 raw signature.

Changed in version 0.34.0: Added to sign arbirary messages

verify_signature(message: str, sig: str) bool

Sign arbitrary message, returning it’s base64 raw signature.

Changed in version 0.34.0: Added to verify signature of message

serialize_to_bytes() bytes

serialize_to_bytes Returns a SUI conforming keystring as bytes.

Returns:

Bytes of signature scheme + private key

Return type:

bytes

serialize() str

serialize Returns a SUI conforming keystring.

Returns:

a base64 encoded string of schema and private key bytes

Return type:

str

to_bytes() bytes

Convert keypair to bytes.

classmethod from_bytes(indata: bytes) KeyPair

Convert bytes to keypair.

classmethod from_pfc_bytes(scheme: SignatureScheme, pub_bytes: bytes, prv_bytes: bytes) SuiKeyPair

Convert bytes to keypair.

classmethod from_b64(indata: str) SuiKeyPair

Generate KeyPair from base64 keystring.

class pysui.sui.sui_crypto.BaseMultiSig(sui_pub_keys: list[SuiPublicKey], weights: list[int], threshold: int)

Bases: object

.

__init__(sui_pub_keys: list[SuiPublicKey], weights: list[int], threshold: int)

Validating initialization of components.

property scheme: SignatureScheme

Return the MultiSig signature scheme.

property address: str

Return the address string generated from the initial keys.

Changed in version 0.16.1: Return add as str to align with non MultiSig SuiAddress behavior

property as_sui_address: SuiAddress

Return the address as SuiAddress.

New in version 0.16.1: Provide ability to get MultiSig as SuiAddress

property public_keys: list[SuiPublicKey]

Return a copy of the list of SuiPublicKeys used in this MultiSig.

property weights: list[int]

Return a copy of the list of weights used in this MultiSig.

property threshold: int

Return the threshold amount used in this MultiSig.

validate_signers(pub_keys: list[SuiPublicKey]) list[int] | ValueError

Validate pubkeys part of multisig and have enough weight.

Changed in version 0.21.1: Exposed as public for use by SuiTransaction

signature_from(pub_keys: list[SuiPublicKey], signatures: list[SuiSignature]) SuiSignature

signature_from Creates a multisig signature from signed bytes.

Parameters:
  • pub_keys (list[SuiPublicKey]) – List of public keys associated to keypairs that created signatures

  • signatures (list[SuiSignature]) – Signatures from signed transaction bytes digest

Returns:

A multisig signature

Return type:

SuiSignature

class pysui.sui.sui_crypto.MultiSig(suikeys: list[SuiKeyPair], weights: list[int], threshold: int)

Bases: BaseMultiSig

Multi signature support.

__init__(suikeys: list[SuiKeyPair], weights: list[int], threshold: int)

__init__ Initiate a MultiSig object.

Note that Sui multi-sig accepts up to a maximum of ten (10) individual signer keys.

Parameters:
  • suikeys (list[SuiKeyPair]) – The list of keys participating in the multi-sig signing operations.

  • weights (list[int]) – Corresponding weights for each key. Max value of each weight is 255 (8 bit unsigned)

  • threshold (int) – The threshold criteria for this MultiSig. Max value is 2549 (16 bit unsigned)

property full_keys: list[SuiKeyPair]

.

sign(tx_bytes: str | SuiTxBytes, pub_keys: list[SuiPublicKey]) SuiSignature

sign Signs transaction bytes for operation that changes objects owned by MultiSig address.

Changed in version 0.31.0: Roaring bitmap no longer required in Sui 1.4.x and above.

New in version 0.21.1: Full signature creation without binaries.

serialize() str

serialize Serializes the MultiSig object to base64 string.

Returns:

Base64 string of serialized MultiSig

Return type:

str

classmethod deserialize(ser_str: str) ValueError | MultiSig

deserialize Deserializes a MultSig base64 string to object instance.

Parameters:

ser_str (str) – base64 encoded string

Raises:

ValueError – If invalid base64 or undecodeable ser_str

Returns:

The MultiSig instance

Return type:

MultiSig

pysui.sui.sui_crypto.gen_mnemonic_phrase(word_counts: int) str

gen_mnemonic_phrase Generates a unique string of words of count word_counts.

Parameters:

word_counts (int) – Can be one of 12, 15, 18, 21, 24

Raises:

ValueError – If word count not in set

Returns:

The string of words with space separators

Return type:

str

pysui.sui.sui_crypto.create_new_keypair(scheme: SignatureScheme | None = SignatureScheme.ED25519, word_counts: int | None = 12, derv_path='') tuple[str, KeyPair]

create_new_keypair Generate a new keypair.

Parameters:
  • keytype (SignatureScheme, optional) – One of ED25519, SECP256K1 or SECP256R1 key type, defaults to SignatureScheme.ED25519

  • word_counts (int, optional) – count of words to generate mnemonic phrase, defaults to 12

  • derv_path (str, optional) – derivation path coinciding with key type, defaults to None

Raises:

NotImplementedError – If invalid keytype is provided

Returns:

mnemonic words and new keypair

Return type:

tuple[str, KeyPair]

Changed in version 0.33.0: Requires word count, no longer allows phrase.

pysui.sui.sui_crypto.recover_key_and_address(keytype: SignatureScheme, mnemonics: str | list[str], derv_path: str) tuple[str, KeyPair, SuiAddress]

recover_key_and_address Recover a keypair and address.

Parameters:
  • keytype (SignatureScheme) – One of ED25519 or SECP256K1 key type for the original key

  • mnemonics (Union[str, list[str]]) – mnemonic words used when creating original keypair

  • derv_path (str) – derivation path used when creating original keypair

Returns:

mnemonic words, recovered keypair and derived sui address

Return type:

tuple[str, KeyPair, SuiAddress]

Changed in version 0.33.0: Using pysui-fastcrypto.

pysui.sui.sui_crypto.create_new_address(keytype: SignatureScheme, word_counts: int | None = 12, derv_path=None) tuple[str, KeyPair, SuiAddress]

create_new_address Create a new keypair and address for a key type.

Parameters:
  • keytype (SignatureScheme) – One of ED25519, SECP256K1 or SECP256R1 key type

  • word_counts (int, optional) – count of words to generate mnemonic phrase, defaults to 12

  • derv_path (str, optional) – derivation path coinciding with key type, defaults to None

Returns:

mnemonic words, new keypair and derived sui address

Return type:

tuple[str, KeyPair, SuiAddress]

Changed in version 0.33.0: Requires word count, no longer allows phrase.

pysui.sui.sui_crypto.keypair_from_keystring(keystring: str) SuiKeyPair

keypair_from_keystring Parse keystring to keypair.

Parameters:

keystring (str) – base64 keystring

Raises:
  • SuiInvalidKeystringLength – If invalid keypair string length

  • NotImplementedError – If invalid keytype signature in string

Returns:

keypair derived from keystring

Return type:

KeyPair

Changed in version 0.33.0: Using pysui-fastcrypto.

pysui.sui.sui_crypto.load_keys_and_addresses(keystore_file: str) list[list[dict]] | Exception

load_keys_and_addresses Load keys and addresses.

Parameters:

keystore_file (str) – The current in use keystore file path

Raises:
Returns:

Cross reference matrix [{},{keystring:KeyPair},{publickyestring:keystring},{str:SuiAddress}]

Return type:

Union[list[list[dict]], Exception]

Changed in version 0.41.0: Replace cross-reference matrix instead of individual dicts on return

pysui.sui.sui_crypto.as_keystrings(inputs: list[str | dict]) list[str]

as_keystrings Returns a list of just keystrings from heterogenous list of keystrings or dicts.

Parameters:

inputs (list[Union[str, dict]]) – List of Sui keystrings or Wallet dict for conversion to keystring

Returns:

List of strings in Sui keystring form

Return type:

list[str]

New in version 0.33.0: To support wallet exported keys.

pysui.sui.sui_crypto.emphemeral_keys_and_addresses(keystrings: list[str | dict]) list[list[dict]]

emphemeral_keys_and_addresses Convert list of keystrings from SuiConfig.user_config().

Parameters:

keystrings (list[Union[str, dict]]) – List of Sui keystrings or Wallet dict for conversion to keystring

Returns:

Cross reference matrix [{},{keystring:KeyPair},{publickyestring:keystring},{str:SuiAddress}]

Return type:

Union[list[list[dict]], Exception]

Changed in version 0.41.0: Replace cross-reference matrix instead of individual dicts on return

Changed in version 0.33.0: To support wallet exported keys and/or Sui valid keystrings.

pysui.sui.sui_excepts module

Sui Exceptions.

exception pysui.sui.sui_excepts.SuiException

Bases: Exception

Base Exception.

exception pysui.sui.sui_excepts.SuiFileNotFound

Bases: SuiException

Exception for file missing.

exception pysui.sui.sui_excepts.SuiConfigFileError

Bases: SuiException

Config file errors.

exception pysui.sui.sui_excepts.SuiKeystoreFileError

Bases: SuiException

Keystore file errors.

exception pysui.sui.sui_excepts.SuiInvalidAddress

Bases: SuiException

Invalid Sui address.

exception pysui.sui.sui_excepts.SuiKeystoreAddressError

Bases: SuiException

Keystore file errors.

exception pysui.sui.sui_excepts.SuiInvalidKeystringLength(msg: int)

Bases: SuiException

Invalid Keystring Length Exception.

__init__(msg: int) None

Initiate keystring length error.

exception pysui.sui.sui_excepts.SuiNoKeyPairs

Bases: SuiException

Exception for missing keypairs.

__init__() None

Initialize no keypair exception.

exception pysui.sui.sui_excepts.SuiInvalidKeyPair

Bases: SuiException

Invalid KeyPair Exception.

exception pysui.sui.sui_excepts.SuiNotComplexTransaction(tx_name)

Bases: SuiException

Exception for attempting to sign a simple transaction.

__init__(tx_name) None

Initialize.

exception pysui.sui.sui_excepts.SuiApiDefinitionInvalid

Bases: SuiException

Corrupted Schema Exception.

exception pysui.sui.sui_excepts.SuiParamSchemaInvalid

Bases: SuiException

Corrupted Schema Exception.

exception pysui.sui.sui_excepts.SuiRpcApiNotAvailable

Bases: SuiException

Non active or non-existing RPC API method exception.

exception pysui.sui.sui_excepts.SuiRpcApiMalformed

Bases: SuiException

Sui Method malformed.

exception pysui.sui.sui_excepts.SuiRpcApiInvalidParameter

Bases: SuiException

Sui Method invalid parameter.

exception pysui.sui.sui_excepts.SuiRpcApiError

Bases: SuiException

For RPC error returns.

exception pysui.sui.sui_excepts.SuiPackageBuildFail

Bases: SuiException

For publishing.

exception pysui.sui.sui_excepts.SuiMiisingBuildFolder

Bases: SuiException

For publishing.

exception pysui.sui.sui_excepts.SuiMiisingModuleByteCode

Bases: SuiException

For publishing.

pysui.sui.sui_txn_validator module

Sui Transaction validator.

pysui.sui.sui_txn_validator.validate_api(api_method: SuiApi, builder: Builder) tuple[str, str] | SuiRpcApiInvalidParameter

Validate the API parameters and arguments.

pysui.sui.sui_utils module

Utility functions.

class pysui.sui.sui_utils.CompiledPackage(project_name: str, project_id: str, project_source_digest: bytes, dependencies: list[str], compiled_modules: list[SuiString] | None = None, package_digest: bytes | None = None)

Bases: object

Ease of compilation information dataclass.

Changed in version 0.17.0: Added the package digest that matches chain digest.

project_name: str
project_id: str
project_source_digest: bytes
dependencies: list[str]
compiled_modules: list[SuiString] = None
package_digest: bytes = None
__init__(project_name: str, project_id: str, project_source_digest: bytes, dependencies: list[str], compiled_modules: list[SuiString] | None = None, package_digest: bytes | None = None) None
pysui.sui.sui_utils.publish_build(path_to_package: Path, args_list: list[str]) CompiledPackage | Exception

Build and collect module base64 strings and dependencies ObjectIDs.

Changed in version 0.17.0: Added the package digest that matches chain digest.

pysui.sui.sui_utils.sui_base_get_config() tuple[Path, Path, Path | None]

sui_base_get_config Load a sui-base configuration.

Raises:
  • ValueError – client.yaml not found

  • ValueError – sui binary not found

Returns:

Fully qualified paths to client.yaml and sui binary

Return type:

tuple[Path, Path]

Changed in version 0.41.0: Sui aliases configuration feature added

pysui.sui.sui_utils.partition(ilist: Iterable, chunk_size: int)

Partition a list with max paritiion size.

Lazy generation of list partitions with size <= chunk_size

Parameters:
  • ilist (Iterable) – A flat list to partition

  • chunk_size (int) – Max elements per partition

Yield:

a list of size N where N <= chunk_size

Return type:

list

pysui.sui.sui_utils.hexstring_to_sui_id(indata: str, default_fill_length: int = 64) str

Convert hexstring to valid full length sui address/object id.

pysui.sui.sui_utils.hexstring_to_list(indata: str, default_fill_length: int = 64) list[int]

hexstring_to_list convert a hexstr (e.g. 0x…) into a list of ints.

Parameters:

indata (str) – Data to conver to list of ints

Returns:

converted indata to int list

Return type:

list[int]

Changed in version 0.19.0: Account for > 3 and < 66 size hex string

pysui.sui.sui_utils.b64str_to_list(indata: str) list[int]

b64str_to_list convert a base64 string into a list of ints.

Parameters:

indata (str) – Base64 encoded string

Returns:

converted indata to int list

Return type:

list[int]

pysui.sui.sui_utils.b58str_to_list(indata: str) list[int]

b58str_to_list convert a base58 string into a list of ints.

Parameters:

indata (str) – Base58 encoded string

Returns:

converted indata to int list

Return type:

list[int]

pysui.sui.sui_utils.int_to_listu8(byte_count: int, in_el: int) list[int]

int_to_listu8 converts integer to array of u8 bytes.

Parameters:
  • byte_count (int) – Expected byte count of integer

  • in_el (int) – The integer elements

Raises:

ValueError – If mismatch on expected and actual byte count

Returns:

the integer value converted to list of int (u8)

Return type:

list[int]

pysui.sui.sui_utils.as_sui_address(in_data: Any) SuiAddress | ValueError

as_sui_address coerces in_data to a SuiAddress.

Parameters:

in_data (Any) – Data to attempt coercion with

Raises:
  • ValueError – If the data is not a valid SuiAddress form

  • ValueError – If in_data type is not handled by this utility.

Returns:

A SuiAddress

Return type:

Union[SuiAddress, ValueError]

pysui.sui.sui_utils.as_object_id(in_data: Any) ObjectID | ValueError

as_object_id coerces in_data to an ObjectID.

Parameters:

in_data (Any) – Data to attempt coercion with

Raises:
  • ValueError – if indata type not a suitable subtype of SuiScalarType

  • ValueError – If in_data type is not handled by this utility.

Returns:

An ObjectID

Return type:

Union[ObjectID, Union[ValueError, AttributeError]]

pysui.sui.sui_utils.as_sui_string(in_data: Any) SuiString | ValueError

as_sui_string coerces in_data to a SuiString.

Parameters:

in_data (Any) – Data to attempt coercion with

Raises:

ValueError – If in_data type is not handled by this utility.

Returns:

A SuiString

Return type:

Union[SuiString, ValueError]

pysui.sui.sui_utils.as_sui_integer(in_data: Any) SuiInteger | ValueError

as_sui_integer coerces in_data to a SuiInteger.

Parameters:

in_data (Any) – Data to attempt coercion with

Raises:

ValueError – If in_data type is not handled by this utility.

Returns:

A SuiInteger

Return type:

Union[SuiInteger, ValueError]

pysui.sui.sui_utils.as_sui_array(in_data: Any) SuiArray | ValueError

as_sui_array coerces in_data to a SuiArray.

Parameters:

in_data (Any) – Data to attempt coercion with

Raises:

ValueError – If in_data type is not handled by this utility.

Returns:

A SuiArray

Return type:

Union[SuiArray, ValueError]

pysui.sui.sui_utils.as_sui_map(in_data: Any) SuiMap | ValueError

as_sui_map coerces in_data to a SuiMap.

Parameters:

in_data (Any) – Data to attempt coercion with

Raises:

ValueError – If in_data type is not handled by this utility.

Returns:

A SuiMap

Return type:

Union[SuiMap, ValueError]

pysui.sui.sui_utils.as_sui_boolean(in_data: Any) SuiBoolean | ValueError

as_sui_boolean coerces in_data to a SuiBoolean.

Parameters:

in_data (Any) – Data to attempt coercion with

Raises:

ValueError – If in_data type is not handled by this utility.

Returns:

A SuiBoolean

Return type:

Union[SuiBoolean, ValueError]

pysui.sui.sui_utils.is_base_64(str_or_bytes: str | bytes | bytearray) bool

is_base_64 validate str_or_bytes if valid base64 construct.

Parameters:

str_or_bytes (Union[str, bytes, bytearray]) – In data

Raises:

ValueError – Invalid input type

Returns:

True if is valid base64

Return type:

bool

pysui.sui.sui_utils.to_base_64(in_data: Any, clz: Any) Any | ValueError

to_base_64 Coerce str,bytes or bytearray to base64.

Parameters:
  • in_data (Any) – Data to coerce

  • clz (Any) – Result class that can construct with single argument

Raises:

ValueError – If in_data type not support for coercion

Returns:

clz object instance

Return type:

Union[Any, ValueError]

pysui.sui.sui_utils.as_sui_txbytes(in_data: Any) SuiTxBytes | ValueError

as_sui_txbytes coerces in_data to a SuiTxBytes.

Parameters:

in_data (Any) – Data to attempt coercion with

Raises:

ValueError – If in_data type is not handled by this utility.

Returns:

A SuiTxBytes

Return type:

Union[SuiTxBytes, ValueError]

pysui.sui.sui_utils.as_sui_signature(in_data: Any) SuiSignature | ValueError

as_sui_signature coerces in_data to a SuiSignature.

Parameters:

in_data (Any) – Data to attempt coercion with

Raises:

ValueError – If in_data type is not handled by this utility.

Returns:

A SuiSignature

Return type:

Union[SuiSignature, ValueError]

pysui.sui.sui_utils.as_sui_txdigest(in_data: Any) SuiTransactionDigest | ValueError

as_sui_txdigest coerces in_data to a SuiTransactionDigest.

Parameters:

in_data (Any) – Data to attempt coercion with

Raises:

ValueError – If in_data type is not handled by this utility.

Returns:

A SuiTransactionDigest

Return type:

Union[SuiTransactionDigest, ValueError]

pysui.sui.sui_utils.COERCION_TO_FROM_SETS = {<class 'pysui.sui.sui_types.address.SuiAddress'>: {<class 'pysui.sui.sui_types.scalars.ObjectID'>, <class 'pysui.sui.sui_types.scalars.SuiString'>, <class 'str'>}, <class 'pysui.sui.sui_types.collections.SuiArray'>: {<class 'list'>, <class 'tuple'>}, <class 'pysui.sui.sui_types.collections.SuiMap'>: {<class 'dict'>}, <class 'pysui.sui.sui_types.scalars.ObjectID'>: {<class 'dataclasses_json.api.DataClassJsonMixin'>, <class 'pysui.sui.sui_types.address.SuiAddress'>, <class 'str'>}, <class 'pysui.sui.sui_types.scalars.SuiBoolean'>: {<class 'bool'>, <class 'int'>, <class 'str'>}, <class 'pysui.sui.sui_types.scalars.SuiInteger'>: {<class 'int'>, <class 'str'>}, <class 'pysui.sui.sui_types.scalars.SuiSignature'>: {<class 'bytearray'>, <class 'bytes'>, <class 'str'>}, <class 'pysui.sui.sui_types.scalars.SuiString'>: {<class 'int'>, <class 'pysui.sui.sui_types.address.SuiAddress'>, <class 'pysui.sui.sui_types.scalars.ObjectID'>, <class 'str'>}, <class 'pysui.sui.sui_types.scalars.SuiTransactionDigest'>: {<class 'pysui.sui.sui_types.scalars.SuiString'>, <class 'str'>}, <class 'pysui.sui.sui_types.scalars.SuiTxBytes'>: {<class 'bytearray'>, <class 'bytes'>, <class 'str'>}}

Keys are the end product pysui type and the value (set) are the types it can convert from.

pysui.sui.sui_utils.COERCION_FROM_TO_SETS = {<class 'NoneType'>: {<class 'pysui.sui.sui_types.scalars.SuiNullType'>}, <class 'bool'>: {<class 'pysui.sui.sui_types.scalars.SuiBoolean'>}, <class 'bytearray'>: {<class 'pysui.sui.sui_types.scalars.SuiSignature'>, <class 'pysui.sui.sui_types.scalars.SuiTxBytes'>}, <class 'bytes'>: {<class 'pysui.sui.sui_types.scalars.SuiSignature'>, <class 'pysui.sui.sui_types.scalars.SuiTxBytes'>}, <class 'dict'>: {<class 'pysui.sui.sui_types.collections.SuiMap'>}, <class 'int'>: {<class 'pysui.sui.sui_types.scalars.SuiBoolean'>, <class 'pysui.sui.sui_types.scalars.SuiInteger'>, <class 'pysui.sui.sui_types.scalars.SuiString'>}, <class 'list'>: {<class 'pysui.sui.sui_types.collections.SuiArray'>, pysui.sui.sui_types.collections.SuiArray[pysui.sui.sui_types.address.SuiAddress], pysui.sui.sui_types.collections.SuiArray[pysui.sui.sui_types.collections.BatchParameter], pysui.sui.sui_types.collections.SuiArray[pysui.sui.sui_types.scalars.ObjectID], pysui.sui.sui_types.collections.SuiArray[pysui.sui.sui_types.scalars.SuiInteger], pysui.sui.sui_types.collections.SuiArray[pysui.sui.sui_types.scalars.SuiString]}, <class 'pysui.sui.sui_types.scalars.SuiString'>: {<class 'pysui.sui.sui_types.address.SuiAddress'>, <class 'pysui.sui.sui_types.scalars.ObjectID'>, <class 'pysui.sui.sui_types.scalars.SuiBoolean'>}, <class 'str'>: {<class 'pysui.sui.sui_types.address.SuiAddress'>, <class 'pysui.sui.sui_types.scalars.ObjectID'>, <class 'pysui.sui.sui_types.scalars.SuiBoolean'>, <class 'pysui.sui.sui_types.scalars.SuiInteger'>, <class 'pysui.sui.sui_types.scalars.SuiSignature'>, <class 'pysui.sui.sui_types.scalars.SuiString'>, <class 'pysui.sui.sui_types.scalars.SuiTransactionDigest'>, <class 'pysui.sui.sui_types.scalars.SuiTxBytes'>}, <class 'tuple'>: {<class 'pysui.sui.sui_types.collections.SuiArray'>}}

Keys are the inbound types that can be represented in SUI types in the value (set).

pysui.sui.sui_utils.COERCION_FN_MAP = {<class 'NoneType'>: <function <lambda>>, <class 'pysui.sui.sui_types.address.SuiAddress'>: <function as_sui_address>, <class 'pysui.sui.sui_types.collections.SuiArray'>: <function as_sui_array>, <class 'pysui.sui.sui_types.collections.SuiMap'>: <function as_sui_map>, <class 'pysui.sui.sui_types.scalars.ObjectID'>: <function as_object_id>, <class 'pysui.sui.sui_types.scalars.SuiBoolean'>: <function as_sui_boolean>, <class 'pysui.sui.sui_types.scalars.SuiInteger'>: <function as_sui_integer>, <class 'pysui.sui.sui_types.scalars.SuiSignature'>: <function as_sui_signature>, <class 'pysui.sui.sui_types.scalars.SuiString'>: <function as_sui_string>, <class 'pysui.sui.sui_types.scalars.SuiTransactionDigest'>: <function as_sui_txdigest>, <class 'pysui.sui.sui_types.scalars.SuiTxBytes'>: <function as_sui_txbytes>, pysui.sui.sui_types.collections.SuiArray[pysui.sui.sui_types.address.SuiAddress]: <function as_sui_array>, pysui.sui.sui_types.collections.SuiArray[pysui.sui.sui_types.collections.BatchParameter]: <function as_sui_array>, pysui.sui.sui_types.collections.SuiArray[pysui.sui.sui_types.scalars.ObjectID]: <function as_sui_array>, pysui.sui.sui_types.collections.SuiArray[pysui.sui.sui_types.scalars.SuiInteger]: <function as_sui_array>, pysui.sui.sui_types.collections.SuiArray[pysui.sui.sui_types.scalars.SuiString]: <function as_sui_array>, typing.Any: <function <lambda>>}

Keys are the types and value is the converter function.

Module contents

Main pysui package. Contains imports of various module types.