Python plugin/extra 用于将数据文件从外部源(例如 AWS S3)加载到本地目录
项目描述
数据加载器插件 - Python
目录 (ToC)
<small>使用 markdown-toc 生成的目录</small>
概述
数据加载器
插件,旨在在从AWS S3等云服务下载数据时
支持正在运行的程序(例如,API 服务后端) 。它提供了一个基础 Python 库,即提供了一些从 AWS S3 下载数据文件的方法。data-loader-plugin
参考
Python 模块
-
GitHub: https ://github.com/cloud-helpers/python-plugin-data-loader/tree/master/data_loader_plugin
-
阅读文档 (RTD): https ://readthedocs.org/projects/data-loader-plugin/
Python 虚拟环境
- Pyenv 和 pipenv:http: //github.com/machine-learning-helpers/induction-python/tree/master/installation/virtual-env
安装
克隆这个 Git 存储库
$ mkdir -p ~/dev/infra && \
git clone git@github.com:cloud-helpers/python-plugin-data-loader.git ~/dev/infra/python-plugin-data-loader
$ cd ~/dev/infra/python-plugin-data-loader
Python环境
- 如果尚未安装,请安装
pyenvPython 3.9 和,pip以及pipenv- PyEnv:
$ git clone https://github.com/pyenv/pyenv.git ${HOME}/.pyenv
$ cat >> ~/.profile2 << _EOF
# Python
eval "\$(pyenv init --path)"
_EOF
$ cat >> ~/.bashrc << _EOF
# Python
export PYENV_ROOT="\${HOME}/.pyenv"
export PATH="\${PYENV_ROOT}/bin:\${PATH}"
. ~/.profile2
if command -v pyenv 1>/dev/null 2>&1
then
eval "\$(pyenv init -)"
fi
if command -v pipenv 1>/dev/null 2>&1
then
eval "\$(pipenv --completion)"
fi
_EOF
$ . ~/.bashrc
- 蟒蛇 3.9:
$ pyenv install 3.9.8 && pyenv local 3.9.8
pip:
$ python -mpip install -U pip
pipenv:
$ python -mpip install -U pipenv
用法
安装data-loader-plugin模块
-
至少有两种安装
data-loader-plugin模块的方法,在 Python 用户空间pip中使用pipenv.- 两个选项可以并行安装
- Python 用户空间(通常
/usr/local/opt/python@3.9在 MacOS 或~/.pyenv/versions/3.9.8Linux 上)可能已经安装了许多其他模块,寄生了对每个 Python 依赖项的版本的细粒度控制。如果所有版本都兼容,那么该选项很方便,因为它可以从整个用户空间使用,而不仅仅是从这个子目录
-
在该“使用”部分的其余部分中,将假定
data-loader-plugin模块已安装并且可以从环境中轻松使用,无论该环境是否为虚拟环境。换句话说,要根据使用情况调整文档pipenv,只需pipenv run在每个与 Python 相关的命令前添加即可。
在 Python 用户空间安装
data-loader-plugin在用户空间安装和使用模块(带pip):
$ python -mpip uninstall data-loader-plugin
$ python -mpip install -U data-loader-plugin
在专用 Python 虚拟环境中安装
data-loader-plugin在虚拟环境中安装和使用模块:
$ pipenv shell
(python-...-JwpAHotb) ✔ python -mpip install -U data-loader-plugin
(python-...-JwpAHotb) ✔ python -mpip install -U data-loader-plugin
(python-...-JwpAHotb) ✔ exit
用作data-loader-plugin另一个 Python 程序的模块
- 使用 AWS 命令行 (CLI) 检查数据文件:
$ aws s3 ls --human s3://nyc-tlc/trip\ data/yellow_tripdata_2021-07.csv --no-sign-request
2021-10-29 20:44:34 249.3 MiB yellow_tripdata_2021-07.csv
- 模块导入语句:
>>> import importlib
>>> from types import ModuleType
>>> from data_loader_plugin.base import DataLoaderBase
- 创建 DataLoaderBase Python 类的实例:
>>> plugin: ModuleType = importlib.import_module("data_loader_plugin.copyfile")
>>> data_loader: DataLoaderBase = plugin.DataLoader(
local_path='/tmp/yellow_tripdata_2021-07.csv',
external_url='s3://nyc-tlc/trip\ data/yellow_tripdata_2021-07.csv',
)
>>> data_load_success, message = data_loader.load()
开发/贡献
- 构建源代码分发和 Python 工件(轮子):
$ rm -rf _skbuild/ build/ dist/ .tox/ __pycache__/ .pytest_cache/ MANIFEST *.egg-info/
$ pipenv run python setup.py sdist bdist_wheel
- 上传到测试 PyPi(PyPi 上不能上传 Linux 二进制轮):
$ PYPIURL="https://test.pypi.org"
$ pipenv run twine upload -u __token__ --repository-url ${PYPIURL}/legacy/ dist/*
Uploading distributions to https://test.pypi.org/legacy/
Uploading data_loader_plugin-0.0.1-py3-none-any.whl
100%|███████████████████████████████████████| 23.1k/23.1k [00:02<00:00, 5.84kB/s]
Uploading data-loader-plugin-0.0.1.tar.gz
100%|███████████████████████████████████████| 23.0k/23.0k [00:01<00:00, 15.8kB/s]
View at:
https://test.pypi.org/project/data-loader-plugin/0.0.1/
- 将 Python 包上传/发布到
PyPi 存储库:
- 注册身份验证令牌以访问 PyPi:
$ PYPIURL="https://upload.pypi.org"
$ pipenv run keyring set ${PYPIURL}/ __token__
Password for '__token__' in '${PYPIURL}/':
- 注册身份验证令牌以访问 PyPi:
$ pipenv run twine upload -u __token__ --repository-url ${PYPIURL}/legacy/ dist/*
Uploading distributions to https://upload.pypi.org/legacy/
Uploading data_loader_plugin-0.0.1-py3-none-any.whl
100%|███████████████████████████████████████| 23.1k/23.1k [00:02<00:00, 5.84kB/s]
Uploading data-loader-plugin-0.0.1.tar.gz
100%|███████████████████████████████████████| 23.0k/23.0k [00:01<00:00, 15.8kB/s]
View at:
https://pypi.org/project/data-loader-plugin/0.0.1/
-
请注意,文档是由 ReadTheDocs (RTD) 自动构建的
-
手动构建文档(使用Sphinx):
$ pipenv run python setup.py build_sphinx
running build_sphinx
Running Sphinx v4.3.0
[autosummary] generating autosummary for: README.md
myst v0.15.2: ..., words_per_minute=200)
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 1 source files that are out of date
updating environment: [new config] 1 added, 0 changed, 0 removed
reading sources... [100%] README
...
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] README
...
build succeeded.
The HTML pages are in build/sphinx/html.
- 为 CI/CD 管道(当前为 Travis CI)重新生成 Python 依赖文件 (
requirements.txt):
$ pipenv --rm; rm -f Pipfile.lock; pipenv install; pipenv install --dev
$ git add Pipfile.lock
$ pipenv lock -r > ci/requirements.txt
$ pipenv lock --dev -r > ci/requirements-dev.txt
$ git add ci/requirements.txt ci/requirements-dev.txt
$ git commit -m "[CI] Upgraded the Python dependencies for the Travis CI pipeline"
测试数据加载器插件 Python 模块
- 进入
pipenv外壳:
$ pipenv shell
(python-...-iVzKEypY) ✔ python -V
Python 3.9.8
- 卸载任何以前安装的
data-loader-plugin模块/库:
(python-...-iVzKEypY) ✔ python -mpip uninstall data-loader-plugin
- 启动一个简单的测试
pytest
(python-iVzKEypY) ✔ python -mpytest tests
=================== test session starts ==================
platform darwin -- Python 3.9.8, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: ~/dev/infra/python-plugin-data-loader
plugins: cov-3.0.0
collected 3 items
tests/test_copyfile.py . [ 33%]
tests/test_s3.py .. [100%]
====================== 3 passed in 1.22s ==================
- 退出
pipenv外壳:
(python-...-iVzKEypY) ✔ exit
项目详情
关
data_loader_plugin -0.0.1.post1-py3-none-any.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 1bc9c05162eaaf7a22a541c11502eb4dfe7bcd6495ed31b49cba37f77bb3c995 |
|
| MD5 | 8e86e8d6cc3e20f87d43ee354da0d5c7 |
|
| 布莱克2-256 | ff9a4ffa880c6d5da734670641250b202f4f88a4d9f2dac0389fac6cc62e6bc5 |