From ftitos-claude-code
Pythonic idioms, PEP 8 standards, type hints, and best practices for building robust, efficient, and maintainable Python applications.
npx claudepluginhub nassimbf/ftitos-claude-codeThis skill uses the workspace's default tool permissions.
Idiomatic Python patterns and best practices for building robust, efficient, and maintainable applications.
Expert guidance for Next.js Cache Components and Partial Prerendering (PPR). **PROACTIVE ACTIVATION**: Use this skill automatically when working in Next.js projects that have `cacheComponents: true` in their next.config.ts/next.config.js. When this config is detected, proactively apply Cache Components patterns and best practices to all React Server Component implementations. **DETECTION**: At the start of a session in a Next.js project, check for `cacheComponents: true` in next.config. If enabled, this skill's patterns should guide all component authoring, data fetching, and caching decisions. **USE CASES**: Implementing 'use cache' directive, configuring cache lifetimes with cacheLife(), tagging cached data with cacheTag(), invalidating caches with updateTag()/revalidateTag(), optimizing static vs dynamic content boundaries, debugging cache issues, and reviewing Cache Component implementations.
Guides building MCP servers enabling LLMs to interact with external services via tools. Covers best practices, TypeScript/Node (MCP SDK), Python (FastMCP).
Share bugs, ideas, or general feedback.
Idiomatic Python patterns and best practices for building robust, efficient, and maintainable applications.
# Good: Clear and readable
def get_active_users(users: list[User]) -> list[User]:
return [user for user in users if user.is_active]
# Bad: Clever but confusing
def get_active_users(u):
return [x for x in u if x.a]
Avoid magic; be clear about what your code does.
# Good: EAFP style
try:
return dictionary[key]
except KeyError:
return default_value
def process_items(items: list[str]) -> dict[str, int]:
return {item: len(item) for item in items}
from typing import Protocol
class Renderable(Protocol):
def render(self) -> str: ...
def render_all(items: list[Renderable]) -> str:
return "\n".join(item.render() for item in items)
def load_config(path: str) -> Config:
try:
with open(path) as f:
return Config.from_json(f.read())
except FileNotFoundError as e:
raise ConfigError(f"Config file not found: {path}") from e
except json.JSONDecodeError as e:
raise ConfigError(f"Invalid JSON in config: {path}") from e
class AppError(Exception):
pass
class ValidationError(AppError):
pass
class NotFoundError(AppError):
pass
from contextlib import contextmanager
@contextmanager
def timer(name: str):
start = time.perf_counter()
yield
elapsed = time.perf_counter() - start
print(f"{name} took {elapsed:.4f} seconds")
from dataclasses import dataclass, field
from datetime import datetime
@dataclass
class User:
id: str
name: str
email: str
created_at: datetime = field(default_factory=datetime.now)
is_active: bool = True
def __post_init__(self):
if "@" not in self.email:
raise ValueError(f"Invalid email: {self.email}")
from concurrent.futures import ThreadPoolExecutor
with ThreadPoolExecutor(max_workers=10) as executor:
results = list(executor.map(fetch_url, urls))
from concurrent.futures import ProcessPoolExecutor
with ProcessPoolExecutor() as executor:
results = list(executor.map(process_data, datasets))
async def fetch_all(urls: list[str]) -> list[str]:
tasks = [fetch_async(url) for url in urls]
return await asyncio.gather(*tasks, return_exceptions=True)
myproject/
+-- src/
| +-- mypackage/
| +-- __init__.py
| +-- main.py
| +-- api/
| +-- models/
| +-- utils/
+-- tests/
| +-- conftest.py
| +-- test_api.py
| +-- test_models.py
+-- pyproject.toml
black . # Code formatting
isort . # Import sorting
ruff check . # Linting
mypy . # Type checking
pytest --cov=pkg # Testing with coverage
bandit -r . # Security scanning
pip-audit # Dependency vulnerabilities
# Bad: Mutable default arguments
def append_to(item, items=[]): # Shared across calls!
# Good: Use None
def append_to(item, items=None):
if items is None:
items = []
# Bad: Bare except
except:
pass
# Good: Specific exception
except SpecificError as e:
logger.error(f"Operation failed: {e}")
# Bad: type() for type checking
if type(obj) == list:
# Good: isinstance
if isinstance(obj, list):