Skip to main content

项目介绍

Logo

这是一个 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")

版本说明

目前主要是说明开发的软件版本:

  1. Python 3.12.1
  2. Rust 1.76

注意事项

需要重新编译部分内容

更新

  1. 推送到 main 分支
  2. 修改 Cargo.toml 中的版本号
  3. 打标签:git tag v0.1.x
  4. 通过推送标签进行升级:git push origin tag v0.1.x

镜像推送

  1. 基于原始镜像:ghcr.io/rust-cross/manylinux2014-cross:aarch64
  2. docker build -t jindaxiang/newopen .
  3. docker tag local-image:tagname jindaxiang/new-repo:tagname
  4. docker push jindaxiang/new-repo:tagname

查看

  1. PyPI 版本 RShare 版本

贡献代码

  1. maturin 项目
  2. maturin 文档
  3. PyO3 项目
  4. 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

Metadata

Release files for rshare 0.1.37

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rshare 0.1.37
File Size Uploaded Provenance
rshare-0.1.37.tar.gz 27.1 kB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for rshare 0.1.37
File
rshare-0.1.37-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details
rshare-0.1.37-cp38-abi3-manylinux_2_34_x86_64.whl CPython 3.8 abi3 Linux glibc 2.34+ x86-64 Details
rshare-0.1.37-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.8 abi3 Linux glibc 2.17+ ARM64 Details
rshare-0.1.37-cp38-abi3-macosx_11_0_arm64.whl CPython 3.8 abi3 macOS 11.0+ ARM64 Details
rshare-0.1.37-cp38-abi3-macosx_10_12_x86_64.whl CPython 3.8 abi3 macOS 10.12+ x86-64 Details

Total release size: 15.5 MB

Release files / rshare-0.1.37.tar.gz

Download URL rshare-0.1.37.tar.gz
Size 27.1 kB
Tags Source
SHA-256 checksum
How to use checksums
613094143f91780761c93b0ed4b9f4e9bc45fefc00b40debf524bfd84664741c
BLAKE2b-256 checksum
How to use checksums
26820e1645e085a1dce63f363916e794d2e261adaa8f6e4dc151c792ac8c66a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.5.0

Release files / rshare-0.1.37-cp38-abi3-win_amd64.whl

Download URL rshare-0.1.37-cp38-abi3-win_amd64.whl
Size 1.6 MB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
db5f6cdc5ab4ef1cd9de355c58a66f4ae0c35b8e8dee3ddcb37623f623d423f5
BLAKE2b-256 checksum
How to use checksums
9b60e628e00c2f0ae19d3d36b32409adf656b846b1a1fbaf1b862db209122045
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.5.0

Release files / rshare-0.1.37-cp38-abi3-manylinux_2_34_x86_64.whl

Download URL rshare-0.1.37-cp38-abi3-manylinux_2_34_x86_64.whl
Size 5.0 MB
Tags CPython 3.8 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
9e4739adabc4cfae0f06c62426ded03d468d47f724436cf2e3638e856a4bf329
BLAKE2b-256 checksum
How to use checksums
c4b1f5b8f03b612f6c156a4cfff0dc7946aebf0b4a4c8fadeaa62f898c532827
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.5.0

Release files / rshare-0.1.37-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL rshare-0.1.37-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 5.1 MB
Tags CPython 3.8 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
679422a23407abdacf304be38ce70037079d7c71bfb32ad257e8cbd39c2ae690
BLAKE2b-256 checksum
How to use checksums
752e455204c6047a1b9af34a69ee7984f4b9e7cdae0e17b9a894607aeeac5d3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.5.0

Release files / rshare-0.1.37-cp38-abi3-macosx_11_0_arm64.whl

Download URL rshare-0.1.37-cp38-abi3-macosx_11_0_arm64.whl
Size 1.9 MB
Tags CPython 3.8 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a405f2f1afe58407226adec75417683b219614263f432a98cf4c3804025c2bb1
BLAKE2b-256 checksum
How to use checksums
a5b91568ec508395da9b820709634543adfcc6a8331d57e2ba157f4d84be4185
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.5.0

Release files / rshare-0.1.37-cp38-abi3-macosx_10_12_x86_64.whl

Download URL rshare-0.1.37-cp38-abi3-macosx_10_12_x86_64.whl
Size 1.9 MB
Tags CPython 3.8 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
d152d3b79c5618fd01b04067fdd0869b1b0365c769b1ae38a05fe31e3f7598cc
BLAKE2b-256 checksum
How to use checksums
174e96ccae6add4a8c3fde6af9b9d6eac04b2d6c9e1caa29a0be6b2d2cb0ea8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.5.0

Security for rshare 0.1.37

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.37 This release

6 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page