Builds concurrent Python services with asyncio: coroutines, task groups, aiohttp clients, timeouts, and semaphore-bounded concurrency.
Agentic Workflow: Read -> Reason -> Act (async-asyncio-basics)
You are Async Asyncio Basics (api/general) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — api context for async-asyncio-basics
- Domain: Builds concurrent Python services with asyncio: coroutines, task groups, aiohttp clients, timeouts, and semaphore-bounded concurrency.
- asyncio-basics: Run coroutines and tasks on the asyncio event loop. —
python -c "import asyncio; asyncio.run(asyncio.sleep(0.1)); print('ok')"
- async-http: Make concurrent HTTP calls with aiohttp and bound timeouts. —
pip install aiohttp
- Check
knowledge and prerequisites: pip, python
2. Reason — think for async-asyncio-basics
- For
asyncio-basics: Run coroutines and tasks on the asyncio event loop. — decide which checks to run
- For
async-http: Make concurrent HTTP calls with aiohttp and bound timeouts. — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with async-asyncio-basics tools
- Tools:
Glob, Grep, Read, Bash (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
async-asyncio-basics:52baebed
Async v2 (Python asyncio)
What this skill does
Builds concurrent I/O-bound Python services on asyncio: coroutines and tasks, parallel gather, aiohttp clients with timeouts, semaphores for bounded concurrency, and correct shutdown.
When to use
- A Python service blocks on many HTTP calls that could be parallel
- Replacing threads/process pools with an event loop
- Debugging 'Event loop is closed' or timeout leaks
Real commands
# Basic coroutine execution
python -c "import asyncio; asyncio.run(asyncio.sleep(0.1)); print('ok')"
# Parallel execution: 2s of sleeps in ~1s wall time
python -c "import asyncio, time; async def m(): t=time.perf_counter(); await asyncio.gather(asyncio.sleep(1), asyncio.sleep(1)); print(f'{time.perf_counter()-t:.2f}s')"
# aiohttp with total timeout
pip install aiohttp
python -c "import aiohttp, asyncio; async def m(): async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=5)) as s: r=await s.get('https://httpbin.org/delay/3'); print(r.status)"
Bounded concurrency
import asyncio, aiohttp
async def fetch_all(urls, limit=10):
sem = asyncio.Semaphore(limit)
async with aiohttp.ClientSession() as s:
async def one(u):
async with sem:
async with s.get(u) as r:
return r.status
return await asyncio.gather(*(one(u) for u in urls))
Testing
- Unit-test with pytest-asyncio and asyncio.run(main())
- Verify parallelism by timing concurrent sleeps (max, not sum)
Best practices
- Prefer asyncio.timeout() context managers over raw wait_for
- Bound concurrency with semaphores for rate-limited APIs
- Do CPU work in executors, never in the event loop
Capabilities
asyncio-basics
Run coroutines and tasks on the asyncio event loop.
Parameters:
tasks (string): Comma-separated coroutines to gather
timeout (number): asyncio.timeout value in seconds
Commands:
python -c "import asyncio; asyncio.run(asyncio.sleep(0.1)); print('ok')"
python -c "import asyncio, time; async def m(): t=time.perf_counter(); await asyncio.gather(asyncio.sleep(1), asyncio.sleep(1)); print(f'{time.perf_counter()-t:.2f}s')"
python -m asyncio
python -c "import asyncio; async def f(): return 42; print(asyncio.run(f()))"
Examples:
- python -c "import asyncio; print(asyncio.run(asyncio.gather(*(asyncio.sleep(i/10) for i in range(5)))))"
- python -c "import asyncio; async def f(): return 42; print(asyncio.run(f()))"
- python -c "import asyncio; print(asyncio.get_event_loop_policy().get_event_loop().class_)"
async-http
Make concurrent HTTP calls with aiohttp and bound timeouts.
Parameters:
url (string): Endpoint to call
total_timeout (number): aiohttp.ClientTimeout total seconds
concurrency (number): Concurrent requests via gather/semaphore
Commands:
pip install aiohttp
python -c "import aiohttp, asyncio; async def m(): async with aiohttp.ClientSession() as s: r=await s.get('https://httpbin.org/get'); print(r.status)"
python -c "import aiohttp, asyncio; async def m(): async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=5)) as s: r=await s.get('https://httpbin.org/delay/3'); print(r.status)"
python -c "import aiohttp, asyncio, time; async def m(): t=time.perf_counter(); async with aiohttp.ClientSession() as s: await asyncio.gather(*(s.get('https://httpbin.org/delay/1') for _ in range(5))); print(f'{(time.perf_counter()-t):.2f}s')"
Examples:
- python -c "import aiohttp, asyncio; async def m(): async with aiohttp.ClientSession() as s: r=await s.post('https://httpbin.org/post', json={'a':1}); print(r.status); print((await r.json())['json'])"
- python -c "import aiohttp, asyncio; async def m(): async with aiohttp.ClientSession() as s: await asyncio.gather(*(s.get('https://httpbin.org/get') for _ in range(10)))"
- python -c "import aiohttp; print([k for k in aiohttp.dict if 'Client' in k])"
References
1---2name: "async-asyncio-basics"3description: "Builds concurrent Python services with asyncio: coroutines, task groups, aiohttp clients, timeouts, and semaphore-bounded concurrency. Use when working with asyncio basics, async http, api or when the user mentions asyncio basics, async http, api."4license: "MIT"5compatibility: "Requires pip, python."6metadata:7 source: https://skillmd.com/skills/opknock/async-asyncio-basics8 author: Kdesk9 version: 2.0.010 category: api11allowed-tools: "Glob Grep Read Bash(pip:*) Bash(python:*)"12---1314Builds concurrent Python services with asyncio: coroutines, task groups, aiohttp clients, timeouts, and semaphore-bounded concurrency.1516## Agentic Workflow: Read -> Reason -> Act (async-asyncio-basics)1718You are **Async Asyncio Basics** (api/general) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — api context for `async-asyncio-basics`21- Domain: Builds concurrent Python services with asyncio: coroutines, task groups, aiohttp clients, timeouts, and semaphore-bounded concurrency.22- **asyncio-basics**: Run coroutines and tasks on the asyncio event loop. — `python -c "import asyncio; asyncio.run(asyncio.sleep(0.1)); print('ok')"`23- **async-http**: Make concurrent HTTP calls with aiohttp and bound timeouts. — `pip install aiohttp`24- Check `knowledge` and `prerequisites: pip, python`2526### 2. Reason — think for `async-asyncio-basics`27- For `asyncio-basics`: Run coroutines and tasks on the asyncio event loop. — decide which checks to run28- For `async-http`: Make concurrent HTTP calls with aiohttp and bound timeouts. — decide which checks to run29- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs3031### 3. Act — execute with `async-asyncio-basics` tools32- Tools: `Glob`, `Grep`, `Read`, `Bash` (see frontmatter `tools`/`allowed-tools`)33- Use `safe_path` for any write; record evidence (paths, checksums)34- Fingerprint: `async-asyncio-basics:52baebed`3536# Async v2 (Python asyncio)3738## What this skill does3940Builds concurrent I/O-bound Python services on asyncio: coroutines and tasks, parallel gather, aiohttp clients with timeouts, semaphores for bounded concurrency, and correct shutdown.4142## When to use4344- A Python service blocks on many HTTP calls that could be parallel45- Replacing threads/process pools with an event loop46- Debugging 'Event loop is closed' or timeout leaks4748## Real commands4950```bash51# Basic coroutine execution52python -c "import asyncio; asyncio.run(asyncio.sleep(0.1)); print('ok')"5354# Parallel execution: 2s of sleeps in ~1s wall time55python -c "import asyncio, time; async def m(): t=time.perf_counter(); await asyncio.gather(asyncio.sleep(1), asyncio.sleep(1)); print(f'{time.perf_counter()-t:.2f}s')"5657# aiohttp with total timeout58pip install aiohttp59python -c "import aiohttp, asyncio; async def m(): async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=5)) as s: r=await s.get('https://httpbin.org/delay/3'); print(r.status)"60```6162## Bounded concurrency6364```python65import asyncio, aiohttp6667async def fetch_all(urls, limit=10):68 sem = asyncio.Semaphore(limit)69 async with aiohttp.ClientSession() as s:70 async def one(u):71 async with sem:72 async with s.get(u) as r:73 return r.status74 return await asyncio.gather(*(one(u) for u in urls))75```7677## Testing7879- Unit-test with pytest-asyncio and asyncio.run(main())80- Verify parallelism by timing concurrent sleeps (max, not sum)8182## Best practices8384- Prefer asyncio.timeout() context managers over raw wait_for85- Bound concurrency with semaphores for rate-limited APIs86- Do CPU work in executors, never in the event loop8788## Capabilities8990### asyncio-basics91Run coroutines and tasks on the asyncio event loop.9293**Parameters:**94- `tasks` (string): Comma-separated coroutines to gather95- `timeout` (number): asyncio.timeout value in seconds9697**Commands:**98- `python -c "import asyncio; asyncio.run(asyncio.sleep(0.1)); print('ok')"`99- `python -c "import asyncio, time; async def m(): t=time.perf_counter(); await asyncio.gather(asyncio.sleep(1), asyncio.sleep(1)); print(f'{time.perf_counter()-t:.2f}s')"`100- `python -m asyncio`101- `python -c "import asyncio; async def f(): return 42; print(asyncio.run(f()))"`102103**Examples:**104- python -c "import asyncio; print(asyncio.run(asyncio.gather(*(asyncio.sleep(i/10) for i in range(5)))))"105- python -c "import asyncio; async def f(): return 42; print(asyncio.run(f()))"106- python -c "import asyncio; print(asyncio.get_event_loop_policy().get_event_loop().class_)"107108### async-http109Make concurrent HTTP calls with aiohttp and bound timeouts.110111**Parameters:**112- `url` (string): Endpoint to call113- `total_timeout` (number): aiohttp.ClientTimeout total seconds114- `concurrency` (number): Concurrent requests via gather/semaphore115116**Commands:**117- `pip install aiohttp`118- `python -c "import aiohttp, asyncio; async def m(): async with aiohttp.ClientSession() as s: r=await s.get('https://httpbin.org/get'); print(r.status)"`119- `python -c "import aiohttp, asyncio; async def m(): async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=5)) as s: r=await s.get('https://httpbin.org/delay/3'); print(r.status)"`120- `python -c "import aiohttp, asyncio, time; async def m(): t=time.perf_counter(); async with aiohttp.ClientSession() as s: await asyncio.gather(*(s.get('https://httpbin.org/delay/1') for _ in range(5))); print(f'{(time.perf_counter()-t):.2f}s')"`121122**Examples:**123- python -c "import aiohttp, asyncio; async def m(): async with aiohttp.ClientSession() as s: r=await s.post('https://httpbin.org/post', json={'a':1}); print(r.status); print((await r.json())['json'])"124- python -c "import aiohttp, asyncio; async def m(): async with aiohttp.ClientSession() as s: await asyncio.gather(*(s.get('https://httpbin.org/get') for _ in range(10)))"125- python -c "import aiohttp; print([k for k in aiohttp.__dict__ if 'Client' in k])"126127## References128- [Python asyncio](https://docs.python.org/3/library/asyncio.html)129- [aiohttp](https://docs.aiohttp.org/en/stable/)130- [uvloop](https://github.com/MagicStack/uvloop)