rule-api-adapters

Enforce standardized API adapter patterns in Python files.

1|1|Updated Mar 31, 2026
One-click install
npx skills add https://github.com/btabaska/simpler-grants-documentation-automation --skill rule-api-adapters
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rule-api-adapters
Source: https://github.com/btabaska/simpler-grants-documentation-automation/tree/main/.claude/skills/rule-api-adapters
Command: npx skills add https://github.com/btabaska/simpler-grants-documentation-automation --skill rule-api-adapters

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It defines and enforces a cohesive set of API adapter design rules to ensure consistent, secure, and maintainable integration code across the repository.

Core Features & Use Cases

  • Config Pattern: Always implement adapter configuration as a class inheriting from PydanticBaseEnvConfig with a standardized environment prefix.
  • Retry Logic: Use tenacity for retries with a uniform decorator, ensuring proper handling of transient errors.
  • Factory Pattern: Instantiate adapters via factory functions/classes when multiple implementations exist.
  • Mock Clients: Provide dedicated mock adapters alongside real ones for deterministic testing.
  • Client Class Structure: Encapsulate external API calls in a dedicated client class with a config object.
  • Session Management: Pass database/session objects through method parameters; avoid storing them on adapters.
  • Error Mapping: Map external errors to internal exceptions and log before re-raising.
  • Adapter Boundaries: Route external calls through adapters; keep service layer free of direct external dependencies.
  • Logging: Initialize module-level loggers and avoid exposing credentials; log outcomes for external calls.
  • Context Enrichment: Use architecture guidance from smaller MCP rules for adapter design decisions.

Quick Start

Review and apply the api adapters rules to ensure code complies with standard patterns across adapters.

Frequently Asked Questions about rule-api-adapters

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

FAQPage Schema
How do I enforce consistent API adapter patterns across a Python codebase?

To enforce API adapter patterns, apply standardized rules for Pydantic config classes, tenacity retry logic, factory creation, and mock clients across your adapters directory. This ensures a consistent, secure, and maintainable architecture for all external integrations.

What is the best way to handle retry logic for external API calls in Python?

The best way to handle retry logic is using the tenacity library with a uniform decorator to properly manage transient errors. This approach standardizes retry strategies across all API adapters to ensure consistent error recovery.

How do I map external API errors to internal exceptions?

To map external API errors to internal exceptions, encapsulate external calls in a dedicated client class, map the external errors to internal exceptions, log the outcome, and then re-raise the mapped exception to keep service layers clean.

Should I store database session objects directly on my API adapter classes?

You should not store database or session objects directly on API adapter classes. Pass session objects through method parameters instead to maintain proper adapter boundaries and keep external dependencies out of the service layer.

How do I manage API adapter configuration using Pydantic?

To manage API adapter configuration with Pydantic, implement adapter configuration as a class inheriting from PydanticBaseEnvConfig with a standardized environment prefix. This standardizes configuration handling across all adapter implementations.