From python-library-distribution
Designs intuitive Python library APIs following principles of simplicity, consistency, and discoverability. Handles API evolution, deprecation, breaking changes, and error handling.
How this skill is triggered — by the user, by Claude, or both
Slash command
/python-library-distribution:api-designThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
1. **Simplicity**: Simple things simple, complex things possible
# Level 1: Simple functions
from mylib import encode, decode
result = encode(37.7749, -122.4194)
# Level 2: Configurable classes
from mylib import Encoder
encoder = Encoder(precision=15)
# Level 3: Low-level access
from mylib.internals import BitEncoder
# Actions: verbs
encode(), decode(), validate()
# Retrieval: get_*
get_user(), get_config()
# Boolean: is_*, has_*, can_*
is_valid(), has_permission()
# Conversion: to_*, from_*
to_dict(), from_json()
class MyLibError(Exception):
"""Base exception with helpful messages."""
def __init__(self, message: str, *, hint: str = None):
super().__init__(message)
self.hint = hint
# Usage
raise ValidationError(
f"Latitude must be -90 to 90, got {lat}",
hint="Did you swap latitude and longitude?"
)
import warnings
def old_function():
warnings.warn(
"old_function() deprecated, use new_function()",
DeprecationWarning,
stacklevel=2,
)
return new_function()
# Bad: Boolean trap
process(data, True, False, True)
# Good: Keyword arguments
process(data, validate=True, cache=False)
# Bad: Mutable default
def process(items: list = []):
# Good: None default
def process(items: list | None = None):
For detailed patterns, see:
Naming:
- [ ] Clear, self-documenting names
- [ ] Consistent patterns throughout
- [ ] Boolean params read naturally
Parameters:
- [ ] Minimal required parameters
- [ ] Sensible defaults
- [ ] Keyword-only after positional clarity
Errors:
- [ ] Custom exceptions with context
- [ ] Helpful error messages
- [ ] Documented in docstrings
This skill is based on the Ergonomics section of the Guide to Developing High-Quality Python Libraries by Will McGinnis. See these posts for deeper coverage:
npx claudepluginhub wdm0006/python-skills --plugin python-library-completeDesigns public API surfaces for Python libraries: defines __all__, exception hierarchies, async/sync patterns like httpx _BaseClient, pluggy plugins, progressive disclosure, naming, and backward compatibility.
Guides design, architecture, and review of production-grade Python libraries: structure, API design, testing strategy, and implementation trade-offs.
Designs and reviews public APIs, exported function signatures, module boundaries, types/interfaces, and code contracts to make correct usage easy and incorrect usage hard.