Pyper 项目使用教程

Pyper 项目使用教程

pyper Concurrent Python made simple pyper 项目地址: https://gitcode.com/gh_mirrors/pype/pyper

1. 项目目录结构及介绍

Pyper 是一个基于 Python 的并发和并行数据处理框架,采用函数式编程模式。以下是 Pyper 项目的目录结构及其文件的简要介绍:

pyper/
├── .github/              # GitHub 相关的配置文件
├── docs/                 # 文档资料
├── examples/             # 示例项目
├── src/                  # 源代码目录
│   └── pyper/            # Pyper 库的核心代码
├── tests/                # 单元测试
├── .coveragerc           # 测试覆盖率配置文件
├── .gitignore            # Git 忽略文件
├── CONTRIBUTING.md       # 贡献指南
├── LICENSE               # 许可证文件
├── README.md             # 项目说明文件
├── pyproject.toml        # 项目元数据文件
└── tox.ini               # tox 测试配置文件

2. 项目的启动文件介绍

在 Pyper 项目中,启动文件通常是 main.pymain_async.py。这些文件包含了创建和运行 Pyper 数据处理管道的示例代码。以下是一个简单的异步启动文件示例:

import asyncio
from pyper import task

async def get_data(limit: int):
    for i in range(limit):
        yield i

async def step1(data: int):
    await asyncio.sleep(1)
    print("Finished async wait", data)
    return data

def step2(data: int):
    time.sleep(1)
    print("Finished sync wait", data)
    return data

def step3(data: int):
    for i in range(10_000_000):
        _ = i * i
    print("Finished heavy computation", data)
    return data

async def main():
    pipeline = (
        task(get_data, branch=True) |
        task(step1, workers=20) |
        task(step2, workers=20) |
        task(step3, workers=20, multiprocess=True)
    )

    total = 0
    async for output in pipeline(limit=20):
        total += output
    print("Total:", total)

if __name__ == "__main__":
    asyncio.run(main())

3. 项目的配置文件介绍

在 Pyper 项目中,主要的配置文件是 pyproject.toml。这个文件定义了项目的元数据,包括项目名称、版本、作者、依赖项等。以下是一个 pyproject.toml 文件的示例:

[tool.poetry]
name = "pyper"
version = "0.1.0"
description = "Concurrent Python made simple"
authors = ["Your Name <you@example.com>"]

[tool.poetry.dependencies]
python = "^3.8"

[tool.poetry.dev-dependencies]
pytest = "^6.2"

此配置文件告诉 Pyper 的用户如何安装项目及其依赖项。在项目开发过程中,还可以使用 tox.ini 文件来配置测试环境和运行测试。

以上就是 Pyper 项目的使用教程,希望能够帮助您更好地理解和运用 Pyper 框架。

pyper Concurrent Python made simple pyper 项目地址: https://gitcode.com/gh_mirrors/pype/pyper

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

洪赫逊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值