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.0.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.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for example_python_package_my-0.1.0.tar.gz
Algorithm Hash digest
SHA256 30763acc411ba741465d41d484aa0fc40ab6abc62e10f7afa1dab617b7fb47a6
MD5 56e3a70cc8a43a1948c44c18b47c7245
BLAKE2b-256 f76e47c9077f9cc820f0d4a44e5701a1d2bd99f29777ea628fb13bb78fdd105d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for example_python_package_my-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de7230434422ada5ddb886c8e0bc9fa4d6f393cfca054edc3a8bd73c1c053360
MD5 22c453892640484da684c9568ead16da
BLAKE2b-256 83d25b01ebb6a2890c0dd2a652c07bdcf7c524265110d55112d63ffa63c5a7f5

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