ワンクリックで
setup-python-library
Set up a Python library project with proper structure for PyPI publication.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Set up a Python library project with proper structure for PyPI publication.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
| name | setup-python-library |
| description | Set up a Python library project with proper structure for PyPI publication. |
This guide covers the essential files and structure needed to create a Python library suitable for publication on PyPI. A properly structured project ensures installability, maintainability, and discoverability.
my-library/
├── src/
│ └── my_library/
│ ├── __init__.py
│ └── core.py
├── tests/
│ └── test_basic.py
├── pyproject.toml
├── README.md
├── LICENSE
└── .gitignore
The __init__.py file is required for Python to recognize a directory as a package. Create src/<package_name>/__init__.py with:
"""A short description of your library."""
__version__ = "0.1.0"
# Optionally expose public API
from .core import main_function
Key elements for __init__.py:
__version__ – Defines the package version stringWithout an __init__.py file, Python won't recognize the directory as an importable package.
The modern standard for Python project configuration:
[project]
name = "my-library"
version = "0.1.0"
description = "A short description of your library"
readme = "README.md"
license = "MIT"
requires-python = ">=3.10"
authors = [
{ name = "Your Name", email = "you@example.com" },
]
dependencies = []
[project.optional-dependencies]
dev = ["pytest>=8.0", "ruff>=0.4"]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.hatch.build.targets.wheel]
packages = ["src/my_library"]
Create tests/test_basic.py:
from my_library import __version__
def test_version():
assert __version__ == "0.1.0"
Run tests with:
uv sync --extra dev
uv run pytest
__pycache__/, dist/, *.egg-info/, .venv/, uv.lock# Create a new project (if starting fresh)
uv init my-library --lib
# Or sync an existing project
uv sync
# Sync all dependencies including dev extras
uv sync --extra dev
# Add a new dependency
uv add requests
# Add a dev dependency
uv add --optional dev mypy
# Run tests
uv run pytest
# Run linter
uv run ruff check .
# Run any Python script
uv run python -m my_library
# Build the package
uv build
# Publish to PyPI (requires authentication)
uv publish
__init__.py exists with __version__ definedpyproject.toml has name, version, description, authors, licenseuv run pytestuv.lock is committed to version control for reproducibility__init__.py prevents Python from recognizing the package__version__ in __init__.py__init__.py and pyproject.tomluv sync after modifying dependencies in pyproject.toml