管道实用程序库
项目描述
帕克
Python 管道实用程序库
描述
在 Zendesk 构建机器学习的过程中,我们注意到很多步骤是连续的,后面的步骤依赖于前面步骤的输出。因为 Python 函数只返回一个值(return
多个值作为一个元组返回),所以对于长序列的步骤,解构和跟踪返回值变得乏味,尤其是当输入没有从前一个步骤返回时。
PAKKR 是为解决这些痛点而创建的实用程序;它为用户提供了一种方法来指定如何解释返回值,并且可以选择缓存结果并在以后的步骤中自动注入它们。
从 PyPi 安装
pip install pakkr
从源安装
git clone git@github.com:zendesk/pakkr.git
cd pakkr
python setup.py install
用法
from pakkr import Pipeline, returns
@returns(int, original_num_as_string=str) # this function returns an integer and insert original_num_as_string into the meta cache
def times_two(n):
return n*2, {'original_num_as_string': str(n)}
@returns(int, int) # this functions returns two integers and will be passed on as two arguments
def plus_five_and_three(n):
return n + 5, n + 3
@returns(str)
def summary(a, b, original_num_as_string): # a and b are passed in as positional arguments,
# but original_num_as_string would be injected from the meta cache
return f'Original input was {original_num_as_string} and it became {str(a)} and {str(b)} after processing'
pipeline = Pipeline(times_two, plus_five_and_three, summary, _name='process_int')
print(pipeline(3))
运行上面的代码应该打印:
Original input was 3 and it became 11 and 9 after processing
这是怎么回事?
returns
用于指示应如何解释返回值;@returns(int, str, x=bool)
意味着 theCallable
应该返回类似的东西return 10, 'hello', {'x': True}
,10
and'hello'
将作为两个位置参数传递到下一个Callable
whilex
将被缓存在元空间中,并且如果任何后续Callable
s 需要x
但不作为来自上一个的位置参数给出,则被注入Callable
。
发展
tox
假设所需的 Python 版本可用,此项目用于管理多个 Python 版本的测试。
git clone git@github.com:zendesk/pakkr.git
cd pakkr
pip install tox
tox
(可选)使用pyenv
和pipenv
管理 Python 安装和开发依赖项。
git clone git@github.com:zendesk/pakkr.git
cd pakkr
# Install pyenv, see instructions in https://github.com/pyenv/pyenv
# Install Python versions supported by pakkr if not available locally
# pyenv install 3.6.10
# pyenv install 3.7.6
# pyenv install 3.8.1
# Set available Python verions
pyenv local 3.6.10 3.7.6 3.8.1
# Install pipenv
pip install pipenv
pipenv sync --dev
# Run tests
pipenv run tox
报告错误
请在 GitHub 中提出问题。
贡献
改进总是受欢迎的。请按照以下步骤进行贡献
- 提交包含更改详细说明的拉取请求
- 获得维护者的批准
- 维护者将合并您的更改
执照
使用本软件须遵守LICENSE文件中规定的重要条款和条件。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
pakkr-0.1.0.tar.gz
(14.3 kB
查看哈希)
内置分布
pakkr-0.1.0-py3-none-any.whl
(24.9 kB
查看哈希)