designing-python-apis

Designs Python library APIs with naming conventions, error handling, deprecation, and evolution patterns.

Updated Aug 28, 2026
One-click install
npx skills add https://github.com/Yash-Awasthi/adapfit --skill designing-python-apis-yash-awasthi
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: designing-python-apis
Source: https://github.com/Yash-Awasthi/adapfit/tree/main/.agents/skills/designing-python-apis
Command: npx skills add https://github.com/Yash-Awasthi/adapfit --skill designing-python-apis-yash-awasthi

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Python library authors often ship APIs that confuse users, break on upgrades, or fail silently. This Skill provides concrete principles and patterns for designing intuitive, consistent, and evolvable Python library APIs. ## Core Features & Use Cases - API Design Principles: Apply simplicity, consistency, least surprise, and discoverability through progressive disclosure, naming conventions, and keyword-only arguments. - Fail-Loud Error Handling: Build exception hierarchies and avoid silent-failure anti-patterns like success sentinels on error paths, swallowed exceptions, and partial mutations. - Evolution & Deprecation: Manage additive versus breaking changes, deprecation lifecycles, backward-compatible signature changes, and feature flags. - Use Case: When designing a new Python library, use this Skill to structure the public API surface, define a custom exception hierarchy, and plan a deprecation path before removing a legacy function. ## Quick Start Review my Python library's public API and suggest improvements for naming, error handling, and backward compatibility.

Frequently Asked Questions about designing-python-apis

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I design a good Python library API?▼

Follow four principles: simplicity, consistency, least surprise, and discoverability. Use progressive disclosure so simple calls work with defaults, apply verb-based naming like encode() and get_user(), and make options keyword-only so call sites stay readable.

How to deprecate a function in Python without breaking users?▼

Follow a three-phase lifecycle: emit a DeprecationWarning naming the replacement in a minor release, document the removal version and migration path, then remove only in a later major release. Use stacklevel=2 so the warning points at the caller's code.

What is the difference between additive and breaking API changes?▼

Additive changes like new functions or keyword-only parameters with defaults keep existing code running and fit minor releases. Breaking changes like removing names, changing return types, or tightening accepted argument types require a major release.

Should I use a dataclass config object or a fluent builder in Python?▼

Prefer a frozen dataclass config object by default since it is easy to construct, compare, and serialize. Use a fluent builder only when construction is genuinely stepwise or conditional, and return a new instance from each step.

Why does my Python API fail silently instead of raising errors?▼

Silent failures come from setting success sentinels in except blocks, swallowing exceptions into generic messages, returning partial results as if complete, or no-op behavior on unexpected input. Catch specific exceptions, validate before mutating, and raise on empty filtered sets.

When should I use typing.Protocol instead of an abstract base class?▼

Use typing.Protocol when you only need to define the shape callers must satisfy, since it type-checks without coupling users to your hierarchy. Reserve abstract base classes for cases where you must share implementation, not merely an interface.