Python SDK for Free TON

ton-client-p的Python项目详细描述


吨客户机

tonsdk客户端库Python绑定。 适用于Python 3.6+

{1}$ TonClient MacOS Latest
PyPI - Python VersionPyPIPyPI - Downloads
Chat on Telegram RUChat on Telegram EN

安装

检查是否安装了Python3.6+

MacOS/Linux
# Using pipenv
pipenv install ton-client-py

# Using pip  
pip install ton-client-py
Windows
^{pr2}$

测试

  • 克隆存储库
# Clone repository 
git clone https://github.com/move-ton/ton-client-py.git

# Go to repo directory
cd ton-client-py
  • 安装开发依赖项
MacOS/Linux
# Using pipenv
pipenv install --dev

# Using pip
pip install pytest
Windows
# Using pipenv
py -m pipenv install --dev

# Using pip
py -m pip install pytest
  • 运行测试
MacOS/Linux
# Using pipenv
pipenv run pytest  # Display only module name while testing
pipenv run pytest -v  # Display module and method while testing
pipenv run pytest -v -s --log-cli-level=INFO  # Display methods logging while testing

# Without pipenv
python -m pytest
python -m pytest -v
python -m pytest -v -s --log-cli-level=INFO
Windows
# Using pipenv
py -m pipenv run pytest  # Display only module name while testing
py -m pipenv run pytest -v  # Display module and method while testing
py -m pipenv run pytest -v -s --log-cli-level=INFO  # Display methods logging while testing

# Without pipenv
py -m pytest
py -m pytest -v
py -m pytest -v -s --log-cli-level=INFO
  • 备选运行测试
    如果您在安装pytest包时遇到问题,您可以简单地运行
# For MacOS/Linux
python -m unittest -v

# For Windows
py -m unittest -v

客户

核心客户端库有同步和异步请求模式。一些核心方法仅在异步请求模式下可用,并且 这种模式更易于预处理,因此python客户机在默认情况下是使用异步核心请求创建的。在

创建客户端

fromtonclient.clientimportTonClientclient=TonClient()# If you need sync core requests for some reasonclient_sync_core=TonClient(is_core_async=False)

客户端是用默认配置创建的

CLIENT_DEFAULT_SETUP={'network':{'server_address':'http://localhost','network_retries_count':5,'message_retries_count':5,'message_processing_timeout':40000,'wait_for_timeout':40000,'out_of_sync_threshold':15000,'access_key':''},'crypto':{'mnemonic_dictionary':1,'mnemonic_word_count':12,'hdkey_derivation_path':"m/44'/396'/0'/0/0"},'abi':{'workchain':0,'message_expiration_timeout':40000,'message_expiration_timeout_grow_factor':1.5}}

您可以在创建客户机时重写初始配置

fromtonclient.clientimportTonClient,DEVNET_BASE_URLclient=TonClient(network={'server_address':DEVNET_BASE_URL},abi={'message_expiration_timeout':30000})version=client.version()

客户端包含所有核心模块及其方法。您可以在此处获得完整的模块和方法列表: https://github.com/tonlabs/TON-SDK/blob/master/docs/modules.md
Module方法由模板client.[module].[method]调用

fromtonclient.clientimportTonClient,DEVNET_BASE_URLclient=TonClient(network={'server_address':DEVNET_BASE_URL})# Generate random signing keyskeypair=client.crypto.generate_random_sign_keys()# Parse accountparsed=client.boc.parse_account(boc='Account base64 BOC')

始终可以在方法docstring中获取有关方法及其参数的信息。在

Net模块和图形查询

要为net模块方法创建GraphQL查询,请使用内置工厂。
collection和{}是所有查询所必需的,其他过滤器是可选的。在

fromtonclient.netimportTonQLQuery# Create query collectionquery=TonQLQuery(collection='messages')# Set filter# `set_filter` methods accepts any number of kwargs for filtering data.# kwarg name contains field name and condition separated by __.# E.g. field__gt=111 is equal to GraphQL {'field': {'gt': 111}}query=query.set_filter(field__gt=111,field__eq='0:')# Set resultquery=query.set_result('id boc')# or you can set result fields as separate argsquery=query.set_result('id','boc')# or you can combine all of thisquery=query.set_result('id boc','field')# Set order (you can pass arguments in the same way as for `set_result`)query=query.set_order('created_at')# ASC sortingquery=query.set_order('-created_at')# DESC sorting# Set limitquery=query.set_limit(5)

事件

一些库方法net.subscribe_collectionproccessing.send_messageprocessing.wait_for_transactionprocessing.process_message可能返回结果或生成器。在

  • net.subscribe_collection始终返回生成器
  • proccessing.send_messageprocessing.wait_for_transactionprocessing.process_message仅当send_events参数设置为True时返回生成器

请深入tonclient/test/test_net.pytonclient/test/test_processing.py来获得如何使用的示例 发电机。在

客户端和异步

fromtonclient.clientimportTonClient,DEVNET_BASE_URL# Create client with `is_async=True` argument.client=TonClient(network={'server_address':DEVNET_BASE_URL},is_async=True)# Get version (simple method with result)version=awaitclient.version()# Generatorsgenerator=client.net.subscribe_collection(query=TonQLQuery)asyncforeventingenerator:# Work with eventpass

请深入tonclient/test/test_async.py获取更多信息。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java为什么这个循环打印1020之间的所有值?我想让它打印出可以被5整除的值   java如何在JTable中集中单元格   java无法通过一个键从hashmap获取对象,该键具有相同的hashcode,并且两个键等于()   不兼容的类型?JAVA   将字符串开头与空格匹配时java replaceAll的正则表达式混淆结果   java为非java应用程序创建jar文件。类文件   java无法从另一个普通Http Servlet访问筛选器Servlet的会话属性   java Ejb,第二个方法中的错误回滚第一个方法   swing java操作侦听器在菜单上,而不是在菜单项上   分析文件时出错:分析文件时出错:无法在Java的XSSF中分析excel文件   java将实体注入到ViewScope Bean中   java如何关闭终端而不终止正在运行的jar文件进程   爪哇力下传   java不能隐式地将[T]强制转换为AT,其中[T]扩展为AT   java Spring项目在jsp页面中显示mysql表数据   java在创建新实例SQLITE时出错