Metadata-Version: 2.1
Name: rshare
Version: 0.1.35
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Rust
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Quality Assurance
Requires-Dist: akshare
Requires-Dist: requests
Requires-Dist: beautifulsoup4
Summary: It is a toy project for Python and Rust!
Keywords: python,rust,data,finance
Author: Albert King
Author-email: albertandking@gmail.com
License: MIT
Requires-Python: >=3.8
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: homepage, https://github.com/albertandking/rshare
Project-URL: documentation, https://rshare.readthedocs.io/
Project-URL: repository, https://github.com/albertandking/rshare
Project-URL: changelog, https://github.com/albertandking/rshare/blob/master/CHANGELOG.md

# 项目介绍

![Logo](./assets/png/rshare.png)

这是一个 Python 和 Rust 混合编程的项目，主要目的是比较 Rust 和 Python 的性能差异。目前这个项目是 [rshare](https://github.com/albertandking/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 的极致性能！

## 使用

### 安装依赖库

请先确认是否在本地安装以下依赖库

```shell
pip install numpy rshare talib
```

**注意其中 talib 的安装需要参考：[ta-lib-python](https://github.com/TA-Lib/ta-lib-python)**

### 运行测试代码

```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 数值来设置不同的数据量，从而比较性能差异！

## 构建

```shell
maturin build  # 会创建一个可以分发的轮子包，但不会安装它。
maturin build --release  # 创建的轮子包是为发布准备的，具有更高的性能，但编译时间更长。

maturin develop # 非优化插入 Python 环境
maturin develop --release  # 优化插入 Python 环境
```

## Python 测试

```shell
import rshare as rk
rk.fetch_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 版本](https://pypi.org/search/?q=rshare)

## 贡献代码

1. [maturin 项目](https://github.com/PyO3/maturin)
2. [maturin 文档](https://www.maturin.rs)
3. [PyO3 项目](https://github.com/PyO3/pyo3)
4. [PyO3 文档](https://pyo3.rs)

## 关注 .vscode

用于 debug 代码，新增 .vscode 文件夹

## Python 环境设置

利用 conda 创建虚拟环境，此处注意 Python 的版本，默认安装 conda 源中最新本的 Python

```shell
conda create -n rshare python
```

进入环境

```shell
conda activate rshare
```

```shell
pip install maturin
python -m pip install TA-Lib  # 仅用于测试 talib
```

