rshare


Namershare JSON
Version 0.1.37 PyPI version JSON
download
home_pageNone
SummaryIt is a toy project for Python and Rust!
upload_time2024-03-16 04:57:37
maintainerNone
docs_urlNone
authorAlbert King
requires_python>=3.8
licenseMIT
keywords python rust data finance
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 项目介绍

![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.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 版本](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
```


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "rshare",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "python,rust,data,finance",
    "author": "Albert King",
    "author_email": "albertandking@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/26/82/0e1645e085a1dce63f363916e794d2e261adaa8f6e4dc151c792ac8c66a3/rshare-0.1.37.tar.gz",
    "platform": null,
    "description": "# \u9879\u76ee\u4ecb\u7ecd\n\n![Logo](./assets/png/rshare.png)\n\n\u8fd9\u662f\u4e00\u4e2a Python \u548c Rust \u6df7\u5408\u7f16\u7a0b\u7684\u9879\u76ee\uff0c\u4e3b\u8981\u76ee\u7684\u662f\u6bd4\u8f83 Rust \u548c Python \u7684\u6027\u80fd\u5dee\u5f02\u3002\u76ee\u524d\u8fd9\u4e2a\u9879\u76ee\u662f [rshare](https://github.com/albertandking/rshare)\uff0c\u6211\u4eec\n\u5728\u9879\u76ee\u4e2d\u901a\u8fc7 PYO3 \u548c Maturin \u6765\u5c06 Rust \u4ee3\u7801\u5305\u88c5\u5230 Python \u4e2d\uff0c\u4ee5\u4f7f\u5f97\u7528\u6237\u53ef\u4ee5\u901a\u8fc7 Python \u4ee3\u7801\u6765\u8c03\u7528 Rust \u5199\u7684\u51fd\u6570\u3002\u5f53\u7136\u5176\u4e2d\u662f\u6709\u6027\u80fd\u635f\u5931\u7684\u3002\n\n\u76ee\u524d\u5728\u6b64\u7248\u672c\u4e2d\u5b9e\u73b0\u5bf9 Rust \u4e2d\u8c03\u7528 Python \u4ee3\u7801\uff0c\u4ee5\u4f7f\u7528\u5229\u7528 Rust \u751f\u6210\u4e8c\u8fdb\u5236\u6587\u4ef6\u7684\u65b9\u5f0f\u5bf9 Python \u4ee3\u7801\u8fdb\u884c\u52a0\u5bc6\u7684\u6548\u679c\uff01\n\n## \u8bf4\u660e\n\n\u76ee\u524d\u5df2\u7ecf\u652f\u6301 64 \u4f4d\u64cd\u4f5c\u7cfb\u7edf\uff0c\u5305\u62ec Windows\uff0cLinux\uff0cmacOS \u548c ARM64 \u67b6\u6784\u7684 Linux \u7cfb\u7edf\u3002\n\n## \u5b89\u88c5\n\n\u901a\u8fc7 `pip install rshare --upgrade -i https://pypi.org/simple` \u6765\u5b89\u88c5 `rshare` \u4f53\u9a8c Rust \u7684\u6781\u81f4\u6027\u80fd\uff01\n\n## \u4f7f\u7528\n\n### \u5b89\u88c5\u4f9d\u8d56\u5e93\n\n\u8bf7\u5148\u786e\u8ba4\u662f\u5426\u5728\u672c\u5730\u5b89\u88c5\u4ee5\u4e0b\u4f9d\u8d56\u5e93\n\n```shell\npip install numpy rshare talib\n```\n\n**\u6ce8\u610f\u5176\u4e2d talib \u7684\u5b89\u88c5\u9700\u8981\u53c2\u8003\uff1a[ta-lib-python](https://github.com/TA-Lib/ta-lib-python)**\n\n### \u8fd0\u884c\u6d4b\u8bd5\u4ee3\u7801\n\n```python\nimport time\n\nimport numpy as np\nimport rshare as rk\nimport talib\n\ndata_num = 100000000  # \u8c03\u6574\u6b64\u6570\u503c\ndata_np = np.random.rand(data_num)\ntimeperiod = 10\n\n# Rust \u548c C \u5bf9\u6bd4\nstart_py = time.time()\nresult_talib = talib.SMA(data_np, timeperiod)\nend_py = time.time()\nprint(f\"\u57fa\u4e8e C \u8bed\u8a00\u7684 TA-Lib \u8017\u65f6: {end_py - start_py} seconds\")\n\nstart_py = time.time()\nresult_np_rs = rk.calculate_moving_average_rs(data=data_np, window_size=timeperiod)\nend_py = time.time()\nprint(f\"\u57fa\u4e8e Rust \u7684\u8017\u65f6: {end_py - start_py} seconds\")\n```\n\n\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574 data_num \u6570\u503c\u6765\u8bbe\u7f6e\u4e0d\u540c\u7684\u6570\u636e\u91cf\uff0c\u4ece\u800c\u6bd4\u8f83\u6027\u80fd\u5dee\u5f02\uff01\n\n## \u6784\u5efa\n\n```shell\nmaturin build  # \u4f1a\u521b\u5efa\u4e00\u4e2a\u53ef\u4ee5\u5206\u53d1\u7684\u8f6e\u5b50\u5305\uff0c\u4f46\u4e0d\u4f1a\u5b89\u88c5\u5b83\u3002\nmaturin build --release  # \u521b\u5efa\u7684\u8f6e\u5b50\u5305\u662f\u4e3a\u53d1\u5e03\u51c6\u5907\u7684\uff0c\u5177\u6709\u66f4\u9ad8\u7684\u6027\u80fd\uff0c\u4f46\u7f16\u8bd1\u65f6\u95f4\u66f4\u957f\u3002\n\nmaturin develop  # \u975e\u4f18\u5316\u63d2\u5165 Python \u73af\u5883\nmaturin develop --release  # \u4f18\u5316\u63d2\u5165 Python \u73af\u5883\n```\n\n## Python \u6d4b\u8bd5\n\n```shell\nimport rshare as rk\n\nrk.get_title(\"https://www.baidu.com\")\n```\n\n## \u7248\u672c\u8bf4\u660e\n\n\u76ee\u524d\u4e3b\u8981\u662f\u8bf4\u660e\u5f00\u53d1\u7684\u8f6f\u4ef6\u7248\u672c\uff1a\n\n1. Python 3.12.1\n2. Rust 1.76\n\n## \u6ce8\u610f\u4e8b\u9879\n\n\u9700\u8981\u91cd\u65b0\u7f16\u8bd1\u90e8\u5206\u5185\u5bb9\n\n## \u66f4\u65b0\n\n1. \u63a8\u9001\u5230 main \u5206\u652f\n2. \u4fee\u6539 `Cargo.toml` \u4e2d\u7684\u7248\u672c\u53f7\n3. \u6253\u6807\u7b7e\uff1a`git tag v0.1.x`\n4. \u901a\u8fc7\u63a8\u9001\u6807\u7b7e\u8fdb\u884c\u5347\u7ea7\uff1a`git push origin tag v0.1.x`\n\n## \u955c\u50cf\u63a8\u9001\n\n1. \u57fa\u4e8e\u539f\u59cb\u955c\u50cf\uff1a`ghcr.io/rust-cross/manylinux2014-cross:aarch64`\n2. `docker build -t jindaxiang/newopen .`\n3. `docker tag local-image:tagname jindaxiang/new-repo:tagname`\n4. `docker push jindaxiang/new-repo:tagname`\n\n## \u67e5\u770b\n\n1. [PyPI \u7248\u672c RShare \u7248\u672c](https://pypi.org/search/?q=rshare)\n\n## \u8d21\u732e\u4ee3\u7801\n\n1. [maturin \u9879\u76ee](https://github.com/PyO3/maturin)\n2. [maturin \u6587\u6863](https://www.maturin.rs)\n3. [PyO3 \u9879\u76ee](https://github.com/PyO3/pyo3)\n4. [PyO3 \u6587\u6863](https://pyo3.rs)\n\n## \u5173\u6ce8 .vscode\n\n\u7528\u4e8e debug \u4ee3\u7801\uff0c\u65b0\u589e .vscode \u6587\u4ef6\u5939\n\n## Python \u73af\u5883\u8bbe\u7f6e\n\n\u5229\u7528 conda \u521b\u5efa\u865a\u62df\u73af\u5883\uff0c\u6b64\u5904\u6ce8\u610f Python \u7684\u7248\u672c\uff0c\u9ed8\u8ba4\u5b89\u88c5 conda \u6e90\u4e2d\u6700\u65b0\u672c\u7684 Python\n\n```shell\nconda create -n rshare python\n```\n\n\u8fdb\u5165\u73af\u5883\n\n```shell\nconda activate rshare\n```\n\n```shell\npip install maturin\npython -m pip install TA-Lib  # \u4ec5\u7528\u4e8e\u6d4b\u8bd5 talib\n```\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "It is a toy project for Python and Rust!",
    "version": "0.1.37",
    "project_urls": {
        "changelog": "https://github.com/albertandking/rshare/blob/master/CHANGELOG.md",
        "documentation": "https://rshare.readthedocs.io/",
        "homepage": "https://github.com/albertandking/rshare",
        "repository": "https://github.com/albertandking/rshare"
    },
    "split_keywords": [
        "python",
        "rust",
        "data",
        "finance"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "174e96ccae6add4a8c3fde6af9b9d6eac04b2d6c9e1caa29a0be6b2d2cb0ea8f",
                "md5": "691f94608955661eb35281cbd7b85cb7",
                "sha256": "d152d3b79c5618fd01b04067fdd0869b1b0365c769b1ae38a05fe31e3f7598cc"
            },
            "downloads": -1,
            "filename": "rshare-0.1.37-cp38-abi3-macosx_10_12_x86_64.whl",
            "has_sig": false,
            "md5_digest": "691f94608955661eb35281cbd7b85cb7",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.8",
            "size": 1887320,
            "upload_time": "2024-03-16T04:57:26",
            "upload_time_iso_8601": "2024-03-16T04:57:26.991458Z",
            "url": "https://files.pythonhosted.org/packages/17/4e/96ccae6add4a8c3fde6af9b9d6eac04b2d6c9e1caa29a0be6b2d2cb0ea8f/rshare-0.1.37-cp38-abi3-macosx_10_12_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "a5b91568ec508395da9b820709634543adfcc6a8331d57e2ba157f4d84be4185",
                "md5": "8b913d412dda511a2788b1a41a207521",
                "sha256": "a405f2f1afe58407226adec75417683b219614263f432a98cf4c3804025c2bb1"
            },
            "downloads": -1,
            "filename": "rshare-0.1.37-cp38-abi3-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "8b913d412dda511a2788b1a41a207521",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.8",
            "size": 1864647,
            "upload_time": "2024-03-16T04:57:29",
            "upload_time_iso_8601": "2024-03-16T04:57:29.526355Z",
            "url": "https://files.pythonhosted.org/packages/a5/b9/1568ec508395da9b820709634543adfcc6a8331d57e2ba157f4d84be4185/rshare-0.1.37-cp38-abi3-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "752e455204c6047a1b9af34a69ee7984f4b9e7cdae0e17b9a894607aeeac5d3a",
                "md5": "48fba3e1c287225850dcceab7b4da668",
                "sha256": "679422a23407abdacf304be38ce70037079d7c71bfb32ad257e8cbd39c2ae690"
            },
            "downloads": -1,
            "filename": "rshare-0.1.37-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "has_sig": false,
            "md5_digest": "48fba3e1c287225850dcceab7b4da668",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.8",
            "size": 5140016,
            "upload_time": "2024-03-16T04:57:31",
            "upload_time_iso_8601": "2024-03-16T04:57:31.843297Z",
            "url": "https://files.pythonhosted.org/packages/75/2e/455204c6047a1b9af34a69ee7984f4b9e7cdae0e17b9a894607aeeac5d3a/rshare-0.1.37-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "c4b1f5b8f03b612f6c156a4cfff0dc7946aebf0b4a4c8fadeaa62f898c532827",
                "md5": "fead405398bcf50be7c15fe81dff30e9",
                "sha256": "9e4739adabc4cfae0f06c62426ded03d468d47f724436cf2e3638e856a4bf329"
            },
            "downloads": -1,
            "filename": "rshare-0.1.37-cp38-abi3-manylinux_2_34_x86_64.whl",
            "has_sig": false,
            "md5_digest": "fead405398bcf50be7c15fe81dff30e9",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.8",
            "size": 4968903,
            "upload_time": "2024-03-16T04:57:33",
            "upload_time_iso_8601": "2024-03-16T04:57:33.600459Z",
            "url": "https://files.pythonhosted.org/packages/c4/b1/f5b8f03b612f6c156a4cfff0dc7946aebf0b4a4c8fadeaa62f898c532827/rshare-0.1.37-cp38-abi3-manylinux_2_34_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "9b60e628e00c2f0ae19d3d36b32409adf656b846b1a1fbaf1b862db209122045",
                "md5": "8403ca09e0e0054dcaad195f802a7215",
                "sha256": "db5f6cdc5ab4ef1cd9de355c58a66f4ae0c35b8e8dee3ddcb37623f623d423f5"
            },
            "downloads": -1,
            "filename": "rshare-0.1.37-cp38-abi3-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "8403ca09e0e0054dcaad195f802a7215",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.8",
            "size": 1628556,
            "upload_time": "2024-03-16T04:57:36",
            "upload_time_iso_8601": "2024-03-16T04:57:36.051968Z",
            "url": "https://files.pythonhosted.org/packages/9b/60/e628e00c2f0ae19d3d36b32409adf656b846b1a1fbaf1b862db209122045/rshare-0.1.37-cp38-abi3-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "26820e1645e085a1dce63f363916e794d2e261adaa8f6e4dc151c792ac8c66a3",
                "md5": "1c351c2db3ec7eb44310de85da19b3de",
                "sha256": "613094143f91780761c93b0ed4b9f4e9bc45fefc00b40debf524bfd84664741c"
            },
            "downloads": -1,
            "filename": "rshare-0.1.37.tar.gz",
            "has_sig": false,
            "md5_digest": "1c351c2db3ec7eb44310de85da19b3de",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 27074,
            "upload_time": "2024-03-16T04:57:37",
            "upload_time_iso_8601": "2024-03-16T04:57:37.997216Z",
            "url": "https://files.pythonhosted.org/packages/26/82/0e1645e085a1dce63f363916e794d2e261adaa8f6e4dc151c792ac8c66a3/rshare-0.1.37.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-16 04:57:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "albertandking",
    "github_project": "rshare",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "rshare"
}
        
Elapsed time: 0.21717s