一个用于与Hive/Steem RPC节点(及其分支)进行异步交互的简单Python库
项目描述
Steem Async
异步Steem库 - 一个用于与Steem RPC节点(及其分支)进行异步交互的简单Python库
官方仓库: https://github.com/privex/steem-async
快速安装/使用
警告:由于使用了现代Python功能,如dataclasses,您必须使用Python 3.7或更高版本。此库与Python 3.6或旧版本不兼容。
pip3 install steem-async
import asyncio
from privex.steem import SteemAsync
async def main():
# All init params are optional, but are included to make you aware of them :)
s = SteemAsync(rpc_nodes=['https://steemd.privex.io'], max_retry=4, retry_delay=3)
# If using a fork based on older Steem, disable appbase to use the classic ``call`` JsonRPC method
s.config_set('use_appbase', False)
# If needed, you can customise the headers used
s.config_set('headers', {'content-type': 'application/json'})
###
# Get accounts
###
accounts = await s.get_accounts('someguy123', 'privex')
print(accounts['someguy123'].balances)
# {'STEEM': <Amount '16759.930 STEEM' precision=3>, 'SBD': <Amount '78.068 SBD' precision=3>,
# 'VESTS': <Amount '277045077.603020 VESTS' precision=6>}
print(accounts['privex'].created)
# '2017-02-04T18:07:21'
###
# Bulk load a range of blocks (uses batch calling, request chunking, and auto retry)
###
blocks = await s.get_blocks(10000, 20000)
print(blocks[100].number)
# 10100
###
# If there isn't a wrapper function for what you need, you can use json_call and api_call directly:
###
# Appbase call
res = await s.json_call('condenser_api.get_block', [123])
block = res['result']
print(block['witness'])
# 'someguy123'
# Non-appbase call
block = await s.api_call('database_api', 'get_block', [123])
print(block['witness'])
# 'someguy123'
asyncio.run(main())
有关完整参数文档,当您尝试使用类时,IDE(如PyCharm)和甚至Visual Studio Code应显示我们的PyDoc注释。
对于PyCharm,按F1键并在键盘光标位于类上时,可以看到完整的函数文档,包括返回类型、参数和一般使用信息。您还可以在方法的大括号内(包括构造函数大括号)按CMD-P键,以查看您可以使用参数。
或者,只需查看privex/steem/
内的文件 - 大多数方法和构造函数都得到了充分的PyDoc注释。
Steem Async CLI工具
您可以使用Steem Async直接从CLI进行RPC调用,并输出格式化的结果:
# Show the CLI help page
python3 -m privex.steem -h
# Get the current block and output it as JSON
python3 -m privex.steem get_block
# Get block 123456 but disable human friendly indentation (but not syntax highlighting)
python3 -m privex.steem -r get_block 123456
# Get block 123456 but disable BOTH human friendly indentation AND syntax highlighting
# This can be important if you're using the output in a script
python3 -m privex.steem -nr -r get_block 123456
# Get block 1234567 - use the custom node list https://hived.privex.io + https://anyx.io
python3 -m privex.steem -n https://hived.privex.io,https://anyx.io get_block 1234567
# Get the current head block number and print it
python3 -m privex.steem get_head_block
# Get the account balances for someguy123 as JSON
python3 -m privex.steem get_balances someguy123
# Get the account balances for someguy123 as JSON, but cast the numbers to floats instead of strings
python3 -m privex.steem -dc float get_balances someguy123
# Make a custom RPC call - calling the method get_ticker with no params
python3 -m privex.steem call get_ticker
# Using '-I' will enable number casting, so that '10' is converted to an integer param instead of a string
python3 -m privex.steem call -I get_order_book 10
# For calls that require nested lists/dicts, you can use '-j' to parse parameters as JSON,
# or use '-c' to parse parameters as CSV (CSV columns are auto-casted from numbers/bools)
python3 -m privex.steem call -j lookup_account_names '["someguy123", true]'
python3 -m privex.steem call -j lookup_account_names call -c lookup_account_names someguy123,true
与Beem和其他库的基准比较
Steem-Async比Beem和其他同步库快得多,因为它完全支持AsyncIO,并使用批量/捆绑调用(将多个调用合并为一个请求) - 尤其是在涉及高度并行的查询的任务中,例如从区块链中检索数千个区块。
请查看基准测试文件夹,以查看我们的基准测试结果,以及如何在您的系统上运行我们的基准测试的信息。
信息
此异步Steem库由@someguy123在Privex Inc.开发,以便能够与Steem RPC节点(以及GOLOS等分支)进行异步交互。
它使用httpx库,而不是requests
,以实现完全的异步支持。
+===================================================+
| © 2019 Privex Inc. |
| https://www.privex.io |
+===================================================+
| |
| Python Async Steem library |
| License: X11/MIT |
| |
| Core Developer(s): |
| |
| (+) Chris (@someguy123) [Privex] |
| |
+===================================================+
Async Steem library - A simple Python library for asynchronous interactions with Steem RPC nodes (and forks)
Copyright (c) 2019 Privex Inc. ( https://www.privex.io )
安装
警告:由于使用了现代Python功能,如dataclasses,您必须使用Python 3.7或更高版本。此库与Python 3.6或旧版本不兼容。
使用pip
从PyPi安装
您可以通过pip安装此包
pip3 install steem-async
(可选)手动从Git安装
如果您不想使用PyPi(例如,对于尚未在PyPi上发布的开发版本),您可以直接从我们的Git仓库安装项目。
除非您有特定的理由手动安装,否则您应像上面所示正常使用pip3安装。
选项1 - 使用pip直接从Github安装
pip3 install git+https://github.com/Privex/steem-async
选项2 - 克隆并手动安装
# Clone the repository from Github
git clone https://github.com/Privex/steem-async
cd steem-async
# RECOMMENDED MANUAL INSTALL METHOD
# Use pip to install the source code
pip3 install .
# ALTERNATIVE INSTALL METHOD
# If you don't have pip, or have issues with installing using it, then you can use setuptools instead.
python3 setup.py install
日志记录
默认情况下,此包将把任何≥WARNING级别的信息记录到控制台。您可以通过调整privex.steem
日志记录实例来覆盖此设置。
我们推荐您查看我们的Python包Python Loghelper,该包可以轻松管理您的日志配置,并将其复制到其他日志实例,例如这个。
# Without LogHelper
import logging
l = logging.getLogger('privex.steem')
l.setLevel(logging.ERROR)
# With LogHelper (pip3 install privex-loghelper)
from privex.loghelper import LogHelper
# Set up logging for **your entire app**. In this case, log only messages >=error
lh = LogHelper('myapp', handler_level=logging.ERROR)
lh.add_file_handler('test.log') # Log messages to the file `test.log` in the current directory
lh.copy_logger('privex.steem') # Easily copy your logging settings to any other module loggers
log = lh.get_logger() # Grab your app's logging instance, or use logging.getLogger('myapp')
log.error('Hello World')
贡献
我们非常高兴接受pull requests,并处理我们报告的任何问题。
以下是一些重要信息
报告问题
- 对于错误报告,您应包括以下信息
- 在测试的
privex-steem
和httpx
版本 - 使用pip3 freeze
- 如果没有通过PyPi发布安装,则包含问题的git修订号 -
git log -n1
- 如果没有通过PyPi发布安装,则包含问题的git修订号 -
- 您的python3版本 -
python3 -V
- 您的操作系统和OS版本(例如,Ubuntu 18.04,Debian 7)
- 在测试的
- 对于功能请求/更改
- 请避免提出需要新依赖的建议。此工具旨在轻量级,不包含外部依赖。
- 清楚地说明您希望添加的功能/更改
- 解释此功能/更改为何对我们或其他工具用户有用
- 请注意,对于难以添加或我们认为对我们工具的使用不必要的功能/更改可能不会添加(但我们可能接受PR)
Pull Requests
- 我们乐于接受仅添加代码注释或README更改的PR
- 在贡献代码时使用4个空格,而不是制表符
- 您可以使用Python 3.4+的功能(我们为项目运行Python 3.7+)
- 需要尚未发布到最新稳定版Ubuntu Server LTS(目前为Ubuntu 18.04 Bionic)的Python版本的特性将不予接受。
- 在标题和描述中清楚地说明您的pull request的目的
- 您做了哪些更改?
- 为什么您要做出这些更改?
- 请确保代码贡献有适当的注释 - 我们不会接受涉及未注释、高度简洁的一行代码的更改。
贡献的法定免责声明
没有人愿意阅读一个充满法律文字的长文档,所以我们在这里总结了重要部分。
如果您向Privex创建或拥有的项目贡献了您创建或拥有的内容,例如代码或文档,那么您可能自动授予我们对其内容的无限使用权限,无论我们的项目适用的开源许可证如何。
如果您不想授予我们对您的内容无限使用的权限,您应确保将您的文件内容单独放置,并确保在文件开头(例如代码注释)或其包含的文件夹内(例如名为LICENSE的文件)清晰地显示您的文件许可协议。
请在您的pull请求或issue中让我们知道,您已包含单独许可的文件,以便我们确保不存在可能导致我们无法接受您的贡献的许可冲突。
如果您想阅读整个法律文本,它应包含在privex_contribution_agreement.txt
中。
许可证
本项目采用X11 / MIT许可协议。有关详细信息,请参阅LICENSE文件。
以下是重要内容
- 如果您修改/分发/复制本项目的一部分或全部,您必须包含/显示许可协议和版权声明(
LICENSE
)。 - 未经我们的许可,您不能使用我们的名称来推广/推荐您的产品。然而,您可以声明您的产品使用本项目的一部分或全部。
感谢阅读!
如果您觉得本项目对您有帮助,请考虑从Privex购买VPS或专用服务器 - 价格从每月仅需US$0.99起(我们接受加密货币!点击这里)
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源代码分发
构建分发
steem_async-2.1.0.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 79e36a7ba796262a2c12b24d32e6bde6e40f8fd4010623af3474b3e78ecab480 |
|
MD5 | c5701cd4458a28e70ff9172d3e7d6557 |
|
BLAKE2b-256 | 78b63c8240f7b7a6527a3e9baf9c2c0c5fef8038ee361ef2172b08f0a3459a9c |
steem_async-2.1.0-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | ddeee9e6648cfab799202d086736368f8477f229656f9e1302adb38812c2f45d |
|
MD5 | cd8fa3d43fd3f671a9d5402f9276b8a5 |
|
BLAKE2b-256 | 587303583bec91828da88d5d9293d6874da3e7131bf63641f106f893759ee7ce |