{
  "id": 18685943,
  "title": "Python: Call Multiple APIs in Parallel with asyncio.gather and Semaphore in 10 Minutes",
  "url": "https://urgent.news/2026/11/07/python-call-multiple-apis-in-parallel-with-asyncio-gather-and",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-07T10:03:43.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/linhfishcr7/python-call-multiple-apis-in-parallel-with-asynciogather-and-semaphore-in-10-minutes-2n8l"
  },
  "original_language": "en",
  "account": "When you need to call multiple APIs simultaneously, sequencing them with loops adds up all the waiting time. Using asyncio.gather and Semaphore, you can run coroutines concurrently inside a single event loop, speeding up I/O-bound tasks like HTTP calls. To avoid overwhelming partner APIs, Semaphore limits the number of concurrent requests. For each of 20 users, fetching info from a partner API that takes about 1 second each sequentially would take ≈ 20 seconds. By using asyncio.gather with Semaphore(5), you can run up to 5 requests concurrently, reducing the total time to ≈ 4 seconds. To handle errors, use return_exceptions=True, allowing the function to return a list of results including any exceptions that occurred. Start with Semaphore(5) and adjust based on the API's response limits and observed performance. Remember, this technique is useful for any I/O-bound tasks but not for CPU-bound work.",
  "summary": "When you need to call dozens of APIs — syncing data, crawling prices, firing webhooks — a sequential for loop adds up the waiting time of every request: 20 requests × 1 second = 20 seconds. asyncio.gather runs many coroutines concurrently inside a single event loop, while asyncio.Semaphore limits how many requests fly at the same time so you don't overwhelm the partner API. This technique applies…",
  "key_points": [
    "asyncio.gather enables concurrent execution of coroutines in a single event loop.",
    "Semaphore limits concurrent requests to avoid overwhelming partner APIs.",
    "Using returnexceptions=True allows handling of errors while returning a list of results."
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}