Skip to main content

一个示例 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

开发指南

设置开发环境

  1. 克隆仓库:

    git clone https://github.com/example/example-python-package.git
    cd example-python-package
    
  2. 创建虚拟环境:

    python -m venv venv
    source venv/bin/activate  # Linux/Mac
    # 或
    venv\Scripts\activate  # Windows
    
  3. 安装开发依赖:

    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 了解如何参与项目开发。

支持

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

example_python_package_my-0.1.1.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

example_python_package_my-0.1.1-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file example_python_package_my-0.1.1.tar.gz.

File metadata

File hashes

Hashes for example_python_package_my-0.1.1.tar.gz
Algorithm Hash digest
SHA256 af12f4a4120ddc51b274558a09f0d843fae14bdb811be48a492c3d06c683bc83
MD5 6faf8947e4e04b6b4043064af5b105c1
BLAKE2b-256 3bad81f07e33529a05b70b396e1f747f42ca7fc342e01dfd6f524f9f8bdc3e9d

See more details on using hashes here.

File details

Details for the file example_python_package_my-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for example_python_package_my-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f47b0cc810500880a21c2c5d2b93c7c365dfc6ce78faa6e3741a0ab66a5538c0
MD5 dc7241ee0682ed8b59c2dce4e6cbf6bd
BLAKE2b-256 2c7fff0504f136780c53e4d7159573818883d3b1fc073243365c0f02cbd218c9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page