跳转到主要内容

一个小型库,用于查询和与Steem/HiveEngine网络(https://steem-engine.com / https://hive-engine.com)交互

项目描述

Python SteemEngine

Documentation Status Build Status Codecov PyPi Version License Button PyPI - Downloads PyPI - Python Version GitHub last commit

一个小型库,用于查询和与SteemEngine网络接口,包括发送和发行代币。

官方仓库: https://github.com/privex/python-steemengine

信息

这个Python SteemEngine库由@someguy123在Privex Inc.开发,旨在SteemEngine网络上进行简单的查询以及交易签名(发送、发行)。

它使用了以下库

  • Python Requests 用于请求SteemEngine历史记录
  • Beem 由@holgern(holger80在Steem)编写,用于Steem查询和交易签名
  • Privex的JsonRPC库 用于与SteemEngine RPC API交互。
+===================================================+
|                 © 2019 Privex Inc.                |
|               https://www.privex.io               |
+===================================================+
|                                                   |
|        Python Steem Engine library                |
|        License: X11/MIT                           |
|                                                   |
|        Core Developer(s):                         |
|                                                   |
|          (+)  Chris (@someguy123) [Privex]        |
|                                                   |
+===================================================+

Python SteemEngine - A small library for querying and interacting with the SteemEngine network (https://steem-engine.com)
Copyright (c) 2019    Privex Inc. ( https://www.privex.io )

快速安装/使用

pip3 install privex-steemengine
from decimal import Decimal
from privex.steemengine import SteemEngineToken

# The default network is "steem"
s = SteemEngineToken()
# For interacting with and broadcasting transactions on HiveEngine, set network="hive"
s = SteemEngineToken(network="hive")

# Get all SteemEngine transactions for @someguy123 
for tx in s.list_transactions('someguy123'):
    print(tx['timestamp'], tx['symbol'], tx['quantity'], tx['memo'])

# Get the amount of ENG that @someguy123 owns, as a Decimal()
print(s.get_token_balance('someguy123', 'ENG'))
# 0.00

# Issue 1.234 SGTK to @someguy123 - automatically detects the issuing account
s.issue_token('SGTK', 'someguy123', Decimal('1.234'))

# Send 10 ENG to @privex from @someguy123 with the memo 'hello memo'
s.send_token('ENG', 'someguy123', 'privex', Decimal('10'), 'hello memo')

有关完整的参数文档,当您尝试使用类时,PyCharm等IDE应显示我们的PyDoc注释。

Screenshot of PyCharm SteemEngine Help

对于PyCharm,按F1键,将键盘光标移至类上,以查看完整的函数文档,包括返回类型、参数和一般使用信息。您还可以在方法的大括号内(包括构造函数的大括号)按CMD-P键,以查看您可以使用的内容。

或者,只需查看privex/steemengine/内的文件 - 大多数方法和构造函数都有足够的PyDoc注释。

文档

Read the Documentation

本项目完整文档见上方(点击Read The Docs图片),包括:

  • 如何安装应用程序及其依赖项
  • 如何使用各种功能和类
  • 模块和类的通用文档,供贡献者参考

构建文档

git clone https://github.com/Privex/python-steemengine
cd python-steemengine/docs
pip3 install -r requirements.txt

# It's recommended to run make clean to ensure old HTML files are removed
# `make html` generates the .html and static files in docs/build for production
make clean && make html

# After the files are built, you can live develop the docs using `make live`
# then browse to http://127.0.0.1:8100/
# If you have issues with content not showing up correctly, try make clean && make html
# then run make live again.
make live

交易签名

进行交易签名,您需要一个Beem钱包,密码作为环境变量UNLOCK指定。在大多数Python网络应用程序中,您可以将它放在应用程序的.env文件中,以便自动加载。

全局安装Beem以使用beempy命令,创建钱包,然后导入您将在SteemEngine上交易使用的Steem账户的活动密钥。

# Install beem globally (not in a virtualenv) for the `beempy` command to manage wallets
pip3 install -U beem
# Create a wallet, keep the password safe, you'll need to pass it to your script
beempy createwallet
# Import any active keys for accounts that you'll be transacting with
beempy addkey

示例Python脚本

#!/usr/bin/env python3
from decimal import Decimal
from beem import Steem
from beem.instance import set_shared_steem_instance

# Create an instance of Steem, and set it as the shared instance, so that it can be used by the library
steem_ins = Steem()
steem_ins.set_password_storage('environment')   # Tell Beem to use the `UNLOCK` env variable to unlock the wallet
set_shared_steem_instance(steem_ins)

from privex.steemengine import SteemEngineToken
s = SteemEngineToken()
# Replace the below parameters as needed. 
# Send 10 ENG to @privex from @someguy123 with the memo 'hello memo'
s.send_token('ENG', 'someguy123', 'privex', Decimal('10'), 'hello memo')

将上述内容保存为app.py

# Make your script executable
chmod +x app.py
# Run the script, passing in your wallet password with the UNLOCK env variable.
UNLOCK="YourWalletPassword" ./app.py

Beem现在将能够自动解锁您的钱包以签名Steem交易,例如发送或发行代币。

我们建议在Python项目中使用类似python-dotenv的工具,以便您可以将密码存储在.env文件中(请确保为.env使用安全文件权限)

安装

由于使用参数和返回类型提示,我们建议使用至少Python 3.4+。

使用pip进行安装

您可以通过pip安装此软件包

pip3 install privex-steemengine

(替代)从Git手动安装

如果您不想通过PyPi安装(例如,对于尚未在PyPi上发布的开发版本),您可以直接从我们的Git仓库安装该项目。

除非您有特殊原因需要手动安装,否则您应该按照上述方式使用pip3正常安装。

选项1 - 使用pip直接从Github安装

pip3 install git+https://github.com/Privex/python-steemengine

选项2 - 克隆并手动安装

# Clone the repository from Github
git clone https://github.com/Privex/python-steemengine
cd python-steemengine

# 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.steemengine日志实例来覆盖此设置。

我们建议检查我们的Python包Python Loghelper,它使管理您的日志配置变得容易,并将其复制到其他日志实例,如这个实例。

# Without LogHelper
import logging
l = logging.getLogger('privex.steemengine')
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.steemengine')   # 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')

单元测试

单元测试在tests.py中可用。我们还为项目设置了Travis CI,以在新的发布导致测试失败时提醒我们。

要手动运行测试,可以直接运行tests.py(或使用python3),或使用pytest

git clone https://github.com/Privex/python-steemengine
pip3 install .
./tests.py
# Verbose mode (shows the name of the test, and the comment under it)
./tests.py -v

# You can also use pytest - which is used by our Travis CI setup.
pip3 install pytest
pytest tests.py
# Verbose mode
pytest tests.py

贡献

我们非常乐意接受pull请求,并处理我们报告的任何问题。

以下是一些重要信息

报告问题

  • 对于错误报告,您应包括以下信息
    • 测试的privex-steemenginebeemrequests的版本 - 使用pip3 freeze
      • 如果没有通过PyPi发布安装,则测试问题时使用的git修订版本号 - git log -n1
    • 您的python3版本 - python3 -V
    • 您的操作系统和OS版本(例如,Ubuntu 18.04,Debian 7)
  • 对于功能请求/更改
    • 请避免提出需要新依赖项的建议。此工具的设计是轻量级,不包含外部依赖项。
    • 清楚地解释您希望添加的功能/更改
    • 解释为什么该功能/更改对我们或工具的其他用户有用
    • 请注意,可能难以添加或我们认为对我们使用工具来说不必要的功能/更改可能不会添加(但我们可以接受PR)

拉取请求

  • 我们乐意接受仅添加代码注释或README更改的PR
  • 在贡献代码时使用4个空格,而不是制表符
  • 您可以使用 Python 3.4+ 的功能(我们项目使用 Python 3.7+)。
    • 对于需要尚未在最新稳定版 Ubuntu Server LTS(目前为 Ubuntu 18.04 Bionic)发布的 Python 版本的功能,将不予接受。
  • 请在标题和描述中清楚地说明您的 pull request 的目的。
    • 您都做了哪些更改?
    • 您为什么要做出这些更改?
  • 请确保代码贡献有适当的注释 - 我们不会接受涉及未注释、高度简短的单行代码的更改。

贡献的法律法规声明

没有人愿意阅读满是法律文字的长文档,所以我们在这里总结了重要部分。

如果您将您自己创建/拥有的内容贡献给 Privex 创建/拥有的项目(如代码或文档),则您可能自动授予我们使用您内容的不受限制的权利,无论我们项目的开源许可证是什么。

如果您不想授予我们使用您内容的不限权,请确保将您的内容放在一个单独的文件中,并确保在文件开始处(例如代码注释)或其包含的文件夹中(例如命名为 LICENSE 的文件)清楚地显示您内容的许可证。

请在您的 pull request 或 issue 中告诉我们,您已包括受单独许可证约束的文件,以便我们可以确保没有可能阻止我们接受您的贡献的许可证冲突。

如果您想阅读整个法律文本,它应包含为 privex_contribution_agreement.txt

许可证

本项目的许可证为 X11 / MIT 许可证。有关详细信息,请参阅文件 LICENSE

以下是重要部分

  • 如果您修改/分发/复制本项目的部分或全部内容,则必须包含/显示许可证和版权声明(LICENSE)。
  • 未经我们许可,您不能使用我们的名称来推广/支持您的产品。然而,您可以声明您的产品使用本项目的某些/全部内容。

感谢阅读!

如果本项目对您有所帮助,请考虑从 Privex 购买 VPS 或专用服务器 - 价格低至每月 8 美元(我们接受加密货币!)

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源分发

privex_steemengine-2.4.0.tar.gz (32.8 kB 查看哈希

上传时间

构建分发

privex_steemengine-2.4.0-py3-none-any.whl (31.8 kB 查看哈希

上传时间 Python 3

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面