Project description
项目介绍
这是一个 Python 和 Rust 混合编程的项目,主要目的是比较 Rust 和 Python 的性能差异。目前这个项目是 rshare,我们
在项目中通过 PYO3 和 Maturin 来将 Rust 代码包装到 Python 中,以使得用户可以通过 Python 代码来调用 Rust 写的函数。当然其中是有性能损失的。
目前在此版本中实现对 Rust 中调用 Python 代码,以使用利用 Rust 生成二进制文件的方式对 Python 代码进行加密的效果!
说明
目前已经支持 64 位操作系统,包括 Windows,Linux,macOS 和 ARM64 架构的 Linux 系统。
安装
通过 pip install rshare --upgrade -i https://pypi.org/simple
来安装 rshare
体验 Rust 的极致性能!
使用
安装依赖库
请先确认是否在本地安装以下依赖库
pip install numpy rshare talib
注意其中 talib 的安装需要参考:ta-lib-python
运行测试代码
import time
import numpy as np
import rshare as rk
import talib
data_num = 100000000 # 调整此数值
data_np = np.random.rand(data_num)
timeperiod = 10
# Rust 和 C 对比
start_py = time.time()
result_talib = talib.SMA(data_np, timeperiod)
end_py = time.time()
print(f"基于 C 语言的 TA-Lib 耗时: {end_py - start_py} seconds")
start_py = time.time()
result_np_rs = rk.calculate_moving_average_rs(data=data_np, window_size=timeperiod)
end_py = time.time()
print(f"基于 Rust 的耗时: {end_py - start_py} seconds")
可以通过调整 data_num 数值来设置不同的数据量,从而比较性能差异!
构建
maturin build # 会创建一个可以分发的轮子包,但不会安装它。
maturin build --release # 创建的轮子包是为发布准备的,具有更高的性能,但编译时间更长。
maturin develop # 非优化插入 Python 环境
maturin develop --release # 优化插入 Python 环境
Python 测试
import rshare as rk
rk.get_title("https://www.baidu.com")
版本说明
目前主要是说明开发的软件版本:
- Python 3.12.1
- Rust 1.76
注意事项
需要重新编译部分内容
更新
- 推送到 main 分支
- 修改
Cargo.toml
中的版本号
- 打标签:
git tag v0.1.x
- 通过推送标签进行升级:
git push origin tag v0.1.x
镜像推送
- 基于原始镜像:
ghcr.io/rust-cross/manylinux2014-cross:aarch64
docker build -t jindaxiang/newopen .
docker tag local-image:tagname jindaxiang/new-repo:tagname
docker push jindaxiang/new-repo:tagname
查看
- PyPI 版本 RShare 版本
贡献代码
- maturin 项目
- maturin 文档
- PyO3 项目
- PyO3 文档
关注 .vscode
用于 debug 代码,新增 .vscode 文件夹
Python 环境设置
利用 conda 创建虚拟环境,此处注意 Python 的版本,默认安装 conda 源中最新本的 Python
conda create -n rshare python
进入环境
conda activate rshare
pip install maturin
python -m pip install TA-Lib # 仅用于测试 talib
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file rshare-0.1.37.tar.gz
.
File metadata
-
Download URL:
rshare-0.1.37.tar.gz
- Upload date:
- Size: 27.1 kB
- Tags: Source
-
Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.5.0
File hashes
Hashes for rshare-0.1.37.tar.gz
Algorithm |
Hash digest |
|
SHA256 |
613094143f91780761c93b0ed4b9f4e9bc45fefc00b40debf524bfd84664741c |
|
MD5 |
1c351c2db3ec7eb44310de85da19b3de |
|
BLAKE2b-256 |
26820e1645e085a1dce63f363916e794d2e261adaa8f6e4dc151c792ac8c66a3 |
|
See more details on using hashes here.
File details
Details for the file rshare-0.1.37-cp38-abi3-win_amd64.whl
.
File metadata
-
Download URL:
rshare-0.1.37-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 1.6 MB
- Tags: CPython 3.8+, Windows x86-64
-
Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.5.0
File hashes
Hashes for rshare-0.1.37-cp38-abi3-win_amd64.whl
Algorithm |
Hash digest |
|
SHA256 |
db5f6cdc5ab4ef1cd9de355c58a66f4ae0c35b8e8dee3ddcb37623f623d423f5 |
|
MD5 |
8403ca09e0e0054dcaad195f802a7215 |
|
BLAKE2b-256 |
9b60e628e00c2f0ae19d3d36b32409adf656b846b1a1fbaf1b862db209122045 |
|
See more details on using hashes here.
File details
Details for the file rshare-0.1.37-cp38-abi3-manylinux_2_34_x86_64.whl
.
File metadata
File hashes
Hashes for rshare-0.1.37-cp38-abi3-manylinux_2_34_x86_64.whl
Algorithm |
Hash digest |
|
SHA256 |
9e4739adabc4cfae0f06c62426ded03d468d47f724436cf2e3638e856a4bf329 |
|
MD5 |
fead405398bcf50be7c15fe81dff30e9 |
|
BLAKE2b-256 |
c4b1f5b8f03b612f6c156a4cfff0dc7946aebf0b4a4c8fadeaa62f898c532827 |
|
See more details on using hashes here.
File details
Details for the file rshare-0.1.37-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
File hashes
Hashes for rshare-0.1.37-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm |
Hash digest |
|
SHA256 |
679422a23407abdacf304be38ce70037079d7c71bfb32ad257e8cbd39c2ae690 |
|
MD5 |
48fba3e1c287225850dcceab7b4da668 |
|
BLAKE2b-256 |
752e455204c6047a1b9af34a69ee7984f4b9e7cdae0e17b9a894607aeeac5d3a |
|
See more details on using hashes here.
File details
Details for the file rshare-0.1.37-cp38-abi3-macosx_11_0_arm64.whl
.
File metadata
File hashes
Hashes for rshare-0.1.37-cp38-abi3-macosx_11_0_arm64.whl
Algorithm |
Hash digest |
|
SHA256 |
a405f2f1afe58407226adec75417683b219614263f432a98cf4c3804025c2bb1 |
|
MD5 |
8b913d412dda511a2788b1a41a207521 |
|
BLAKE2b-256 |
a5b91568ec508395da9b820709634543adfcc6a8331d57e2ba157f4d84be4185 |
|
See more details on using hashes here.
File details
Details for the file rshare-0.1.37-cp38-abi3-macosx_10_12_x86_64.whl
.
File metadata
File hashes
Hashes for rshare-0.1.37-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm |
Hash digest |
|
SHA256 |
d152d3b79c5618fd01b04067fdd0869b1b0365c769b1ae38a05fe31e3f7598cc |
|
MD5 |
691f94608955661eb35281cbd7b85cb7 |
|
BLAKE2b-256 |
174e96ccae6add4a8c3fde6af9b9d6eac04b2d6c9e1caa29a0be6b2d2cb0ea8f |
|
See more details on using hashes here.