pysui.sui.sui_clients package

Submodules

pysui.sui.sui_clients.async_client module

Sui Asynchronous RPC Client module.

class pysui.sui.sui_clients.async_client.SuiClient(config: SuiConfig, request_type: SuiRequestType = SuiRequestType.WAITFORLOCALEXECUTION)

Bases: ClientMixin

Sui Asyncrhonous Client.

__init__(config: SuiConfig, request_type: SuiRequestType = SuiRequestType.WAITFORLOCALEXECUTION) None

Client initializer.

Changed in version 0.28.0: Added logging

property is_synchronous: bool

Return whether client is syncrhonous (True) or not (False).

async execute(builder: SuiBaseBuilder, additional_signatures: SuiArray[SuiAddress] | None = None) SuiRpcResult | Exception

Execute the builder construct.

async execute_no_sign(builder: SuiBaseBuilder) SuiRpcResult | Exception

Submit transaction and returns the signer and transaction bytes in the result_data as tuple.

async execute_with_multisig(builder: SuiBaseBuilder, multi_sig: MultiSig, pub_keys: list[SuiPublicKey], signers: SuiArray[SuiAddress] | None = None) SuiRpcResult | Exception

execute_with_multisig Executes a transaction, signing with MultiSig.

Changed in version 0.16.1: Support sponsored transaction signing.

async sign_and_submit(signer: SuiAddress, tx_bytes: SuiTxBytes, additional_signatures: SuiArray[SuiAddress] | None = None) SuiRpcResult | Exception

sign_and_submit Signs the transaction bytes from previous submission, signs and executes.

Parameters:
  • signer (SuiAddress) – Signer for transaction. Should be the same from original transaction

  • tx_bytes (SuiTxBytes) – Transaction bytes from previous submission

  • additional_signatures (SuiArray[SuiAddress], optional) – Array of additional signatures to sign with, defaults to None

Returns:

Result of execution

Return type:

Union[SuiRpcResult, Exception]

async dry_run(builder: SuiBaseBuilder) SuiRpcResult | Exception

Submit transaction than sui_dryRunTransaction only.

async close()

Closes the httpx transport connection.

Does not usually need to be called but put in place as part of commingling with websocket activity.

Added in version 0.26.1: Implement closing underlying httpx transport.

async get_gas(address: SuiAddress | None = None, fetch_all: bool | None = False) SuiRpcResult

get_gas Retrieves SUI gas coin objects for address.

Parameters:
  • address (SuiAddress, optional) – If None, active_address will be used, defaults to None

  • fetch_all (Optional[bool], optional) – Flag indicating to fetch all coins, defaults to False Max is set by RPC Provider (currently 50 for Sui MystenLab providers)

Returns:

If successful, result contains an array of SUI gas objects found

Return type:

SuiRpcResult

Deprecated since version 0.53.0: Transition to GraphQL QueryNode

async get_coin(coin_type: SuiString, address: SuiAddress | None = None, fetch_all: bool | None = False) SuiRpcResult

get_coin Retrieves objects of coin_type for address.

Parameters:
  • coin_type (SuiString) – Fully qualified type names for the coin (e.g., 0x168da5bf1f48dafc111b0a488fa454aca95e0b5e::usdc::USDC)

  • address (SuiAddress, optional) – If None, active_address will be used, defaults to None

  • fetch_all (Optional[bool], optional) – Flag indicating to fetch all coins, defaults to False Max is set by RPC Provider (currently 50 for Sui MystenLab providers)

Returns:

If successful, result contains an array of coins objects of coin_type found

Return type:

SuiRpcResult

Deprecated since version 0.53.0: Transition to GraphQL QueryNode

async get_gas_from_faucet(for_address: SuiAddress | None = None) Any

get_gas_from_faucet Gets gas from SUI faucet.

Note: This is only for devnet, testnet and local usage. :param for_address: Address to transfer faucet gas to, defaults to None :type for_address: SuiAddress, optional :return: _description_ :rtype: Any

Changed in version 0.34.0: Added faucet check. Will fail gracefull setting SuiRpcResult

async get_objects(address: SuiAddress | None = None, fetch_all: bool | None = False) SuiRpcResult | Exception

get_objects Returns all objects owned by address.

Parameters:
  • address (SuiAddress, optional) – Address to object ownership, defaults to None

  • fetch_all (Optional[bool], optional) – Flag indicating to fetch all objects, defaults to False Max objects are set by RPC Provider (currently 50 for Sui MystenLab providers)

Returns:

list of owned objects

Return type:

Union[SuiRpcResult,Exception]

Deprecated since version 0.53.0: Transition to GraphQL QueryNode

async get_object(identifier: ObjectID, version: SuiInteger | None = None) SuiRpcResult | Exception

get_object Get specific object by it’s identifier and version if provided.

Parameters:
  • identifier (ObjectID) – The object identifier of object to fetch

  • version (SuiInteger, optional) – The objects version sequence number, defaults to None

Returns:

The objeect’s ObjectRead data

Return type:

Union[SuiRpcResult, Exception]

Deprecated since version 0.53.0: Transition to GraphQL QueryNode

async get_objects_for(identifiers: list[ObjectID]) SuiRpcResult | Exception

get_objects_for Get objects for the list of identifiers.

Parameters:

identifiers (list) – The list of ObjectID’s being queried.

Raises:

SuiException: if returned from self.execute

Returns:

A list of object data

Return type:

SuiRpcResult

Deprecated since version 0.53.0: Transition to GraphQL QueryNode

async get_package(package_id: ObjectID) SuiRpcResult | Exception

get_package Get details of Sui package.

Parameters:

package_id (ObjectID) – The ObjectID of object being queried.

Raises:

SuiException: if returned from self.execute

Returns:

The package detail data

Return type:

SuiRpcResult

Deprecated since version 0.53.0: Transition to GraphQL QueryNode

async get_events(*, query: SuiMap, cursor: str = '', limit: int = 50, descending_order: bool = True) SuiRpcResult

get_events sui_getEvents API.

Parameters:
  • query (SuiMap) – The event query type map.

  • cursor (str) – _description_

  • limit (int) – _description_

  • descending_order (bool) – _description_

Returns:

API call result

Return type:

SuiRpcResult

Deprecated since version 0.53.0: Transition to GraphQL QueryNode

pysui.sui.sui_clients.common module

Sui Client common classes module.

class pysui.sui.sui_clients.common.SuiRpcResult(result_status: bool, result_string: str, result_data: Any | None = None)

Bases: RpcResult

Sui RpcResult.

Captures information returned from simple and complex RPC API calls

__init__(result_status: bool, result_string: str, result_data: Any | None = None) None

__init__ SuiRpcResult constructor.

Parameters:
  • result_status (bool) – bool indicating success (True) or not (False)

  • result_string (str) – Any string, typically to capture a failure of a call

  • result_data (Any, optional) – If success, contains data realized by RPC result, defaults to None

is_ok() bool

Ease of use status.

is_err() bool

Ease of use status.

property result_data: Any

Get result data.

property result_string: str

Get result string.

class pysui.sui.sui_clients.common.PreExecutionResult(authority_address: SuiAddress, pre_transaction_result: TransactionBytes)

Bases: object

Results of pre-execution transaction submission.

authority_address: SuiAddress
pre_transaction_result: TransactionBytes
property tx_bytes: SuiTxBytes

tx_bytes return the tx_byte string as a SuiTxBytes.

Returns:

tx_bytes in TransactionBytes as SuiTxBytes

Return type:

SuiSignature

__init__(authority_address: SuiAddress, pre_transaction_result: TransactionBytes) None
pysui.sui.sui_clients.common.pysui_default_handler(result: SuiRpcResult) Any

pysui_default_handler Out of box SuiRpcResult error handler.

Exits the application!!!

Parameters:

result (SuiRpcResult) – The result from calling Sui RPC API

Returns:

The data from call if valid

Return type:

Any

pysui.sui.sui_clients.common.handle_result(from_cmd: ~pysui.sui.sui_clients.common.SuiRpcResult, handler=<function pysui_default_handler>) Any

handle_result Returns value from invoking handler.

Parameters:
  • from_cmd (SuiRpcResult) – The result from calling Sui RPC API

  • handler (Function, optional) – The result handler function, defaults to pysui_default_handler

Returns:

Result from handler

Return type:

Any

class pysui.sui.sui_clients.common.ClientMixin(config: SuiConfig, request_type: SuiRequestType = SuiRequestType.WAITFORLOCALEXECUTION)

Bases: Provider

Abstract Mix-in.

Inherited by both Synch and Async clients to ensure constructor consistency as well as utility functions

__init__(config: SuiConfig, request_type: SuiRequestType = SuiRequestType.WAITFORLOCALEXECUTION) None

Client initializer.

Changed in version 0.28.0: Added ProtcolConfig pre-fetch.

Changed in version 0.26.1: Added bool flag indicating state of underlying transport

property transport_open: bool

Returns true/false on state of transport.

Added in version 0.26.1: Added to support transport state information.

abstract property is_synchronous: bool

Return whether client is syncrhonous (True) or not (False).

property current_gas_price: int

Returns session gas price.

property rpc_version: str

Return the version string.

property request_type: SuiRequestType

Return the transaction execution request type.

property set_request_type: SuiRequestType

Return the transaction execution request type.

property rpc_api: dict

Return entire dictionary of RPC API methods.

property rpc_api_names: list[str]

Return names of RPC API methods.

api_exists(api_name: str) bool

Check if API supported in RPC host.

abstract close() None

Abstract method to close transport.

Added in version 0.26.1: Support closing underlying client transport.

rpc_version_support() None

rpc_version_support Validates minimal version supported.

Raises:

RuntimeError – If RPC API version less than minimal support

version_at_least(majver: int, minver: int, bldver: int) bool

Check if minor version is greater than or equal to.

sign_for_execution(tx_bytes: SuiTxBytes, builder: _MoveCallTransactionBuilder, signers: SuiArray[SuiAddress] | None = None) ExecuteTransaction | SuiException | ValueError

sign_for_execution Sets up a TransactioBlock Execution builder.

Parameters:
  • tx_bytes (SuiTxBytes) – Transaction bytes from transaction method submission.

  • builder (_MoveCallTransactionBuilder) – The builder reflecting the transaction method called.

  • signers (Optional[SuiArray[SuiAddress]], optional) – Additional signers, defaults to None

Raises:

SuiNotComplexTransaction – If builder is simple type

Returns:

An ExecuteTransaction builder

Return type:

Union[ExecuteTransaction, SuiException, ValueError]

property protocol: ProtocolConfig

Return the raw protocol config in place for the connection.

Added in version 0.28.0: Connection specific ProtcolConfig.

property max_gets: int

Return maximum getXXX values (either cursored types or multiget types).

Added in version 0.29.0: Added constraint for RPC sfetches.

pysui.sui.sui_clients.subscribe module

Sui Asynchronous subscription module.

class pysui.sui.sui_clients.subscribe.EventData(tx_name: str)

Bases: object

Container for subscription data returned from subscription handler.

__init__(tx_name: str)

Initialie container.

add_entry(event_index: int, data: Any) None

Add a data entry to container.

property collected: dict[int, Any]

Get the data collection dictionary.

property name: str

Get the name of the task associated to this container and it’s content.

class pysui.sui.sui_clients.subscribe.SuiClient(config: SuiConfig)

Bases: Provider

A provider for managing subscriptions of Events or Transactions.

__init__(config: SuiConfig)

__init__ Client initializer.

Parameters:

config (SuiConfig) – An instance of SuiConfig

Changed in version 0.20.0: Added transaction subscription management.

async new_event_subscription(sbuilder: SubscribeEvent, handler: Callable[[SubscribedEvent, int, int], Any], task_name: str | None = None, continue_on_close: bool | None = False) SuiRpcResult

new_event_subscription Initiate and run a move event subscription feed.

Parameters:
  • sbuilder (SubscribeEvent) – The subscription builder submitted for creating the event subscription filter.

  • handler (Callable[[SubscribedEvent, int], Any]) – The function called for each received move event.

  • task_name (str, optional) – A name to assign to the listener task, defaults to None

Returns:

Result of subscribed move event handling

Return type:

SuiRpcResult

async new_transaction_subscription(sbuilder: SubscribeTransaction, handler: Callable[[SubscribedTransaction, int, int], Any], task_name: str | None = None, continue_on_close: bool | None = False) SuiRpcResult

new_event_subscription Initiate and run a move event subscription feed.

Parameters:
  • sbuilder (SubscribeTransaction) – The subscription builder submitted for creating the transaction subscription filter.

  • handler (Callable[[SubscribedTransaction, int], Any]) – The function called for each received transaction event.

  • task_name (str, optional) – A name to assign to the listener task, defaults to None

Returns:

Result of subscribed transaction event handling

Return type:

SuiRpcResult

Added in version 0.20.0: Transaction Effects Subscription

async wait_shutdown() list

wait_shutdown Waits until all subscription tasks complete and gathers the results.

Returns:

A list of Event type events results received

Return type:

list

async kill_shutdown(wait_seconds: int | None = None) list

kill_shutdown Iterates through any event subscription types, cancelling those still active.

Parameters:

wait_seconds (int, optional) – Delay, if any, to perform second cancelation on tasks, defaults to None

Returns:

A list of Event type events results from wait_shutdown

Return type:

list

pysui.sui.sui_clients.sync_client module

Sui Synchronous RPC Client module.

class pysui.sui.sui_clients.sync_client.SuiClient(config: SuiConfig, request_type: SuiRequestType = SuiRequestType.WAITFORLOCALEXECUTION)

Bases: ClientMixin

Sui Syncrhonous Client.

__init__(config: SuiConfig, request_type: SuiRequestType = SuiRequestType.WAITFORLOCALEXECUTION) None

Client initializer.

Changed in version 0.28.0: Added logging

property is_synchronous: bool

Return whether client is syncrhonous (True) or not (False).

execute(builder: SuiBaseBuilder, additional_signatures: SuiArray[SuiAddress] | None = None) SuiRpcResult | Exception

Execute the builder construct.

execute_no_sign(builder: SuiBaseBuilder) SuiRpcResult | Exception

Submit transaction and returns the signer and transaction bytes in the result_data as tuple.

execute_with_multisig(builder: SuiBaseBuilder, multi_sig: MultiSig, pub_keys: list[SuiPublicKey], signers: SuiArray[SuiAddress] | None = None) SuiRpcResult | Exception

execute_with_multisig Executes a transaction, signing with MultiSig.

Changed in version 0.16.1: Support sponsored transaction signing.

sign_and_submit(signer: SuiAddress, tx_bytes: SuiTxBytes, additional_signatures: SuiArray[SuiAddress] | None = None) SuiRpcResult | Exception

sign_and_submit Signs the transaction bytes from previous submission, signs and executes.

Parameters:
  • signer (SuiAddress) – Signer for transaction. Should be the same from original transaction

  • tx_bytes (SuiTxBytes) – Transaction bytes from previous submission

  • additional_signatures (SuiArray[SuiAddress], optional) – Array of additional signatures to sign with, defaults to None

Returns:

Result of execution

Return type:

Union[SuiRpcResult, Exception]

dry_run(builder: SuiBaseBuilder) SuiRpcResult | Exception

Submit transaction than sui_dryRunTransaction only.

close()

Closes the httpx transport connection.

Does not usually need to be called but put in place as part of commingling with websocket activity.

Added in version 0.26.1: Implement closing underlying httpx transport.

get_gas(address: SuiAddress | None = None, fetch_all: bool | None = False) SuiRpcResult

get_gas Retrieves SUI gas coin objects for address.

Parameters:
  • address (SuiAddress, optional) – If None, active_address will be used, defaults to None

  • fetch_all (Optional[bool], optional) – Flag indicating to fetch all coins, defaults to False Max coins are set by RPC Provider (currently 50 for Sui MystenLab providers)

Returns:

If successful, result contains an array of SUI gas objects found

Return type:

SuiRpcResult

Deprecated since version 0.53.0: Transition to GraphQL QueryNode

get_coin(coin_type: SuiString, address: SuiAddress | None = None, fetch_all: bool | None = False) SuiRpcResult

get_coin Retrieves objects of coin_type for address.

Parameters:
  • coin_type (SuiString) – Fully qualified type names for the coin (e.g., 0x168da5bf1f48dafc111b0a488fa454aca95e0b5e::usdc::USDC)

  • address (SuiAddress, optional) – If None, active_address will be used, defaults to None

  • fetch_all (Optional[bool], optional) – Flag indicating to fetch all coins, defaults to False Max coins are set by RPC Provider (currently 50 for Sui MystenLab providers)

Returns:

If successful, result contains an array of coins objects of coin_type found

Return type:

SuiRpcResult

Deprecated since version 0.53.0: Transition to GraphQL QueryNode

get_gas_from_faucet(for_address: SuiAddress | None = None) Any

get_gas_from_faucet Gets gas from SUI faucet.

Note: This is only for devnet, testnet and local usage. :param for_address: Address to transfer faucet gas to, defaults to None :type for_address: SuiAddress, optional :return: _description_ :rtype: Any

Changed in version 0.34.0: Added faucet check. Will fail gracefull setting SuiRpcResult

get_object(identifier: ObjectID, version: SuiInteger | None = None) SuiRpcResult | Exception

get_object Get specific object by it’s identifier and version if provided.

Parameters:
  • identifier (ObjectID) – The object identifier of object to fetch

  • version (SuiInteger, optional) – The objects version sequence number, defaults to None

Returns:

The objeect’s ObjectRead data

Return type:

Union[SuiRpcResult, Exception]

Deprecated since version 0.53.0: Transition to GraphQL QueryNode

get_objects(address: SuiAddress | None = None, fetch_all: bool | None = False) SuiRpcResult | Exception

get_objects Returns objects owned by address.

Parameters:
  • address (SuiAddress, optional) – Address to object ownership, defaults to None Will use active-address if None

  • fetch_all (Optional[bool], optional) – Flag indicating to fetch all objects, defaults to False Max objects are set by RPC Provider (currently 50 for Sui MystenLab providers)

Returns:

list of owned objects

Return type:

Union[SuiRpcResult,Exception]

Deprecated since version 0.53.0: Transition to GraphQL QueryNode

get_objects_for(identifiers: list[ObjectID]) SuiRpcResult | Exception

get_objects_for Get objects for the list of identifiers.

Parameters:

identifiers (list) – The list of ObjectID’s being queried.

Raises:

SuiException: if returned from self.execute

Returns:

A list of object data

Return type:

SuiRpcResult

Deprecated since version 0.53.0: Transition to GraphQL QueryNode

get_package(package_id: ObjectID) SuiRpcResult | Exception

get_package Get details of Sui package.

Parameters:

package_id (ObjectID) – The ObjectID of object being queried.

Raises:

SuiException: if returned from self.execute

Returns:

The package detail data

Return type:

SuiRpcResult

Deprecated since version 0.53.0: Transition to GraphQL QueryNode

get_events(*, query: SuiMap, cursor: str = '', limit: int = 50, descending_order: bool = True) SuiRpcResult

get_events sui_getEvents API.

Parameters:
  • query (SuiMap) – The event query type map.

  • cursor (str) – _description_

  • limit (int) – _description_

  • descending_order (bool) – _description_

Returns:

API call result

Return type:

SuiRpcResult

Deprecated since version 0.53.0: Transition to GraphQL QueryNode

Module contents

Sui Client package.