一个示例 Python 包,用于演示 PyPI 发布
Project description
Example Python Package
一个示例 Python 包,用于演示如何创建和发布到 PyPI。
功能特性
- 实用工具函数: 提供常用的工具函数
- 命令行接口: 提供简单的命令行工具
- 配置管理: 支持配置文件管理
- 网络请求: 封装常用的网络请求功能
安装
从 PyPI 安装
pip install example-python-package
从源代码安装
git clone https://github.com/example/example-python-package.git
cd example-python-package
pip install -e .
快速开始
使用 Python API
from example_package.utils import greet, calculate_sum
from example_package.config import ConfigManager
# 使用工具函数
print(greet("World")) # 输出: Hello, World!
print(calculate_sum([1, 2, 3, 4, 5])) # 输出: 15
# 使用配置管理
config = ConfigManager("config.yaml")
value = config.get("key", "default")
使用命令行工具
# 显示帮助信息
example-cli --help
# 执行命令
example-cli greet --name "World"
example-cli calculate --numbers 1 2 3 4 5
开发指南
设置开发环境
-
克隆仓库:
git clone https://github.com/example/example-python-package.git cd example-python-package
-
创建虚拟环境:
python -m venv venv source venv/bin/activate # Linux/Mac # 或 venv\Scripts\activate # Windows
-
安装开发依赖:
pip install -e ".[dev]"
运行测试
# 运行所有测试
pytest
# 运行测试并生成覆盖率报告
pytest --cov=example_package
# 运行特定测试
pytest tests/test_utils.py
代码质量检查
# 代码格式化
black src tests
# 代码检查
flake8 src tests
# 类型检查
mypy src
构建包
# 构建 wheel 和 sdist
python -m build
# 检查包质量
twine check dist/*
发布到 PyPI
测试发布到 TestPyPI
# 构建包
python -m build
# 上传到 TestPyPI
twine upload --repository testpypi dist/*
正式发布到 PyPI
# 构建包
python -m build
# 上传到 PyPI
twine upload dist/*
项目结构
example-python-package/
├── src/
│ └── example_package/
│ ├── __init__.py
│ ├── utils.py
│ ├── config.py
│ ├── api.py
│ └── cli.py
├── tests/
│ ├── __init__.py
│ ├── test_utils.py
│ ├── test_config.py
│ └── test_api.py
├── docs/
│ ├── index.md
│ └── api.md
├── pyproject.toml
├── README.md
├── LICENSE
└── .github/
└── workflows/
└── publish.yml
许可证
本项目采用 MIT 许可证。详见 LICENSE 文件。
贡献指南
欢迎贡献!请阅读 CONTRIBUTING.md 了解如何参与项目开发。
支持
- 问题报告: GitHub Issues
- 讨论: GitHub Discussions
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file example_python_package_my-0.1.0.tar.gz.
File metadata
- Download URL: example_python_package_my-0.1.0.tar.gz
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30763acc411ba741465d41d484aa0fc40ab6abc62e10f7afa1dab617b7fb47a6
|
|
| MD5 |
56e3a70cc8a43a1948c44c18b47c7245
|
|
| BLAKE2b-256 |
f76e47c9077f9cc820f0d4a44e5701a1d2bd99f29777ea628fb13bb78fdd105d
|
File details
Details for the file example_python_package_my-0.1.0-py3-none-any.whl.
File metadata
- Download URL: example_python_package_my-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de7230434422ada5ddb886c8e0bc9fa4d6f393cfca054edc3a8bd73c1c053360
|
|
| MD5 |
22c453892640484da684c9568ead16da
|
|
| BLAKE2b-256 |
83d25b01ebb6a2890c0dd2a652c07bdcf7c524265110d55112d63ffa63c5a7f5
|