Agent skill
bsee-sodir-extraction-1-rate-limiting
Sub-skill of bsee-sodir-extraction: 1. Rate Limiting (+2).
Install this agent skill to your Project
npx add-skill https://github.com/vamseeachanta/workspace-hub/tree/main/.claude/skills/_archive/data/analysis/bsee-sodir-extraction/1-rate-limiting
SKILL.md
1. Rate Limiting (+2)
1. Rate Limiting
import time
from functools import wraps
def rate_limit(calls_per_minute: int = 30):
"""Decorator to rate limit API calls."""
min_interval = 60.0 / calls_per_minute
last_call = [0.0]
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
elapsed = time.time() - last_call[0]
if elapsed < min_interval:
time.sleep(min_interval - elapsed)
last_call[0] = time.time()
return func(*args, **kwargs)
return wrapper
return decorator
@rate_limit(calls_per_minute=30)
def fetch_with_rate_limit(url: str) -> requests.Response:
return requests.get(url)
2. Caching
from functools import lru_cache
from datetime import datetime, timedelta
@lru_cache(maxsize=100)
def cached_fetch(url: str, cache_hours: int = 24) -> pd.DataFrame:
"""Fetch with caching."""
cache_file = Path(f".cache/{hash(url)}.parquet")
if cache_file.exists():
mtime = datetime.fromtimestamp(cache_file.stat().st_mtime)
if datetime.now() - mtime < timedelta(hours=cache_hours):
return pd.read_parquet(cache_file)
# Fetch fresh data
response = requests.get(url)
df = pd.DataFrame(response.json())
cache_file.parent.mkdir(exist_ok=True)
df.to_parquet(cache_file)
return df
3. Error Handling
import logging
from tenacity import retry, stop_after_attempt, wait_exponential
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10))
def robust_fetch(url: str) -> requests.Response:
"""Fetch with automatic retry on failure."""
try:
response = requests.get(url, timeout=60)
response.raise_for_status()
return response
except requests.exceptions.RequestException as e:
logger.error(f"Fetch failed for {url}: {e}")
raise
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
gsd-complete-milestone
Archive completed milestone and prepare for next version
gsd-reapply-patches
Reapply local modifications after a GSD update
gsd-verify-work
Validate built features through conversational UAT
gsd-thread
Manage persistent context threads for cross-session work
clinical-trial-protocol
Generate clinical trial protocols for medical devices or drugs through a modular, waypoint-based architecture with research-only and full protocol modes.
single-cell-rna-qc
Performs quality control on single-cell RNA-seq data (.h5ad or .h5 files) using scverse best practices with MAD-based filtering and comprehensive visualizations.
Didn't find tool you were looking for?