Skip to main content

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

支持

Metadata

Release files for example-python-package-my 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for example-python-package-my 0.1.1
File Size Uploaded Provenance Actions
example_python_package_my-0.1.1.tar.gz 20.1 kB Without provenance Details for example_python_package_my-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for example-python-package-my 0.1.1
File Interpreter ABI Platform Actions
example_python_package_my-0.1.1-py3-none-any.whl Python 3 none any Details for example_python_package_my-0.1.1-py3-none-any.whl

Total release size: 35.2 kB

Release files / example_python_package_my-0.1.1.tar.gz

Download URL example_python_package_my-0.1.1.tar.gz
Size 20.1 kB
Tags Source
SHA-256 checksum
How to use checksums
af12f4a4120ddc51b274558a09f0d843fae14bdb811be48a492c3d06c683bc83
BLAKE2b-256 checksum
How to use checksums
3bad81f07e33529a05b70b396e1f747f42ca7fc342e01dfd6f524f9f8bdc3e9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.18

Release files / example_python_package_my-0.1.1-py3-none-any.whl

Download URL example_python_package_my-0.1.1-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f47b0cc810500880a21c2c5d2b93c7c365dfc6ce78faa6e3741a0ab66a5538c0
BLAKE2b-256 checksum
How to use checksums
2c7fff0504f136780c53e4d7159573818883d3b1fc073243365c0f02cbd218c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.18

Security for example-python-package-my 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page