S
Saurav Danej
90-Day AI/ML LinkedIn Content System
← All days
83
Day 83 of 90Automation

API integrations — retries, timeouts, idempotency

POST 1 of 5 MorningAutomationConcept

httpx > requests for new code

requests is fine. httpx is better for new code in 2026:

- Sync AND async with the same API
- HTTP/2 by default
- Connection pooling clearer
- Built-in timeouts (5s default — never hang forever)

Drop-in replacement: import httpx as requests works for many scripts. For async jobs (parallel API calls), httpx.AsyncClient is the cleanest path.
#Automation#Python#WebScraping#AI#100DaysOfCode#httpx
POST 2 of 5 MiddayAutomationDeep dive

Retries that don't make things worse

Naïve retry on every error makes a flaky API into a stampede.

Rules:
- Retry only on 5xx, 429, network errors
- Exponential backoff with jitter (1s, 2s, 4s + random)
- Cap at 3-5 retries
- Idempotent calls only (GET, idempotency-key on POST)
- Respect Retry-After header on 429

tenacity library or stamina library handle this cleanly. Don't roll your own loop unless you enjoy debugging.
#Automation#Python#WebScraping#AI#100DaysOfCode#Retries
POST 3 of 5 AfternoonAutomationCode

Production-grade API client

httpx + tenacity. Timeouts. Selective retries. Reusable.

Drop into any project. Set BASE_URL and TOKEN; you have a robust client in 20 lines.
#Automation#Python#WebScraping#AI#100DaysOfCode#httpx
POST 4 of 5 EveningAutomationTip

Idempotency keys for any state-changing call

Network retry on a POST without an idempotency key = 'created the order twice'.

Pattern: client generates a uuid; sends it as Idempotency-Key header (or in body); server treats requests with same key as duplicate of the first.

Stripe, GitHub, AWS APIs all support this. For your own APIs, add it. Saves the 'why are there two of these' postmortem.
#Automation#Python#WebScraping#AI#100DaysOfCode#APIDesign
POST 5 of 5 NightAutomationRecap

Day 83 — APIs that don't lie

Day 83 done.

- httpx > requests for new code
- Retries with backoff + jitter
- 20-line robust client
- Idempotency keys

Tomorrow (Day 84): cloud automation — Lambda, scheduled functions, the serverless cron. Then we wrap week 12.
#Automation#Python#WebScraping#AI#100DaysOfCode#httpx