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正在运行。jar heapdump错误   java如何在安卓画布中弯曲文本区域?   java如何在Gdx 安卓游戏编程中获得矩形的真实触碰位置?   找不到java Spring MVC控制器   在Java中使用双重检查锁定单例扩展类   java在高效的时间和内存中动态执行insert(索引、数据)、delete(索引)、getAt(索引)操作。   java 安卓 Toast和视图帮助   java协议缓冲区:从文件中读取所有序列化消息   java如何在Jackson中为参数化接口类型执行通用自定义反序列化程序   与简单的空检查相比,使用(平面)映射的java优势是什么?   异步方法seam中的java Get contextparam   jar使用相同的java运行时运行另一个java程序   java访问Spring批处理中的作业参数   java给定字符串为空或null   在h2数据库1.4中找不到java类“org.h2.fulltext.FullTextLucene”。*不适用于Lucene Core 4*   java Spring Boot在使用@enableSync时不响应任何请求   java错误:在bash上找不到或加载主类pj2   “返回对象”和“返回(对象)”之间的Java差异   java Android开发:如何使用onKeyUp?