python atn客户端

pyatn-client的Python项目详细描述


Pyatn客户端

pyatn client是python atn client,用于通过支付渠道轻松调用dbot的api

安装

python atn客户端依赖于python3.6+,只需使用pip3进行安装,有关详细信息,请参见Installation

pip3 install pyatn-client

用法

  1. 使用命令pyatn创建一个帐户,如果以前没有帐户,则获取一些atn。
pyatn create-account
pyatn get-atn --address <Address of Account>
  1. 有各种dbot在我们的AI Market上提供ai api。下面是一个例子,使用AI poetry来写诗。
frompyatn_clientimportAtnDBOTADDRESS='0xfd4F504F373f0af5Ff36D9fbe1050E6300699230'# address of the DBot you want to test, use 'AI poetry' as exampleURI='/reg'# uri of the DBot's API endpoint which you want to callMETHOD='POST'# method of the DBot's API endpoint which you want to callrequests_kwargs={"data":{"theme":"中秋月更圆"}}# init Atnatn=Atn(pk_file='<path to key file>',pw_file='<path to password file>')# Call a DBot API 12 timesforiinrange(12):response=atn.call_dbot_api(dbot_address=DBOTADDRESS,uri=URI,method=METHOD,**requests_kwargs)print('Call {}:\n{}'.format(i+1,response.text))# close the channel only when you do not need it any more,# the remain balance in the channel will be returned to your accountatn.close_channel(DBOTADDRESS)

在上面的示例中,如果您的帐户和dbot之间没有人,则会自动创建频道,如果频道中的剩余余额不够,则会加满频道。

存款值由deposit_strategy确定,该函数是一个可调用的函数,以端点价格作为输入参数。默认存款值是端点价格的10倍。

此行为可以更改,您可以在in it类Atn时传入deposit_strategy,或者使用set_deposit_strategy方法更改它。可以将None设置为禁用自动创建或加满频道,然后在调用call_dbot_api方法之前,您应该自己创建或加满频道。这是一个例子。

frompyatn_clientimportAtnDBOTADDRESS='0xfd4F504F373f0af5Ff36D9fbe1050E6300699230'# address of the DBot you want to testURI='/reg'# uri of the DBot's API endpoint which you want to callMETHOD='POST'# method of the DBot's API endpoint which you want to callrequests_kwargs={"data":{"theme":"中秋月更圆"}}# init Atn with deposit_strategy=None, it will disable auto create or topup channel.atn=Atn(pk_file='<path to keystore file>',pw_file='<path to password file>',deposit_strategy=None,# disable auto create or topup channel)# get price of the endpoint to be calledprice=atn.get_price(DBOTADDRESS,URI,METHOD)# open channel with the DBot, only one opened channel is allowed between two address# it will return the channel if one existed.channel=atn.open_channel(DBOTADDRESS,10*price)# wait DBot server sync channel info with the blockchainatn.wait_dbot_sync(DBOTADDRESS)ifchannel.deposit-channel.balance<price:atn.topup_channel(DBOTADDRESS,10*price)# wait DBot server sync channel info with the blockchainatn.wait_dbot_sync(DBOTADDRESS)# call DBot API 12 timesforiinrange(12)print('Call {}:'.format(call_count))# AtnException will raise when eleventh call for insufficient balance, catch it in a production environmentresponse=atn.call_dbot_api(dbot_address=DBOTADDRESS,uri=URI,method=METHOD,**requests_kwargs)print('Call {}:\n{}'.format(i+1,response.text))

API文档

API Documentation

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

推荐PyPI第三方库


热门话题
使用Java将JSON转换为哈希映射   java如何通过使用MapStruct从源对象复制值来填充目标对象内部的映射?   注入泛型类型为@InjectGuice的类时发生java错误   字符串如何在JavaIDE中导入基本符号   在Java中将JSON转换为List<List<String>>   java Java9 HttpClient SSLHandshakeException   java jOOQ代码生成器   java如何调整图标(图像按钮),使其不会放大?   java我可以在使用Eclipse时安装2个或更多Android SDK吗   sqlite Java实现DAO   如何解决此错误?“java.lang.NoSuchFieldError:org.apache.http.conn.ssl.SSLConnectionSocketFactory上的实例。<clinit>。”   java Maven:将基于OSP的zip文件解压缩到WEBINF/lib   java如何在每次调用函数时获取当前gps位置?