Skip to content

Commit c44c78b

Browse files
committed
Created async_call_nb.ipynb to demonstrate async requests.
Updated sync_call_nb.ipynb with RDP and notebook information.
1 parent a8e3794 commit c44c78b

3 files changed

Lines changed: 543 additions & 8 deletions

File tree

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Python examples that use [`httpx`](https://www.python-httpx.org/) to authenticat
1414
src/
1515
├── .env.example # Environment variable template
1616
├── simple_call_nb.ipynb # Jupyter notebook — synchronous, shared httpx.Client
17+
├── async_call_nb.ipynb # Jupyter notebook — async, asyncio.gather() with Semaphore
1718
├── example_sync_httpx.py # Synchronous — direct httpx module calls (no shared client)
1819
├── example_client.py # Synchronous — shared httpx.Client
1920
├── example_async_simple.py # Async — sequential awaits in a loop
@@ -43,6 +44,27 @@ Notebook structure:
4344
5. Main execution block — authenticate, fetch data sequentially, revoke token
4445
6. Elapsed time output
4546

47+
### `src/async_call_nb.ipynb` — Async, concurrent Jupyter notebook (`asyncio.gather`)
48+
49+
Interactive notebook version of the async concurrent workflow using `httpx.AsyncClient` and `asyncio.gather()`. Jupyter's native top-level `await` support means no `asyncio.run()` wrapper is needed.
50+
51+
Demonstrates:
52+
- `POST /auth/oauth2/v1/token` — async OAuth 2.0 Password Grant authentication
53+
- `GET /data/historical-pricing/v1/views/interday-summaries/{ric}` — daily OHLCV data fetched concurrently for 10 RICs
54+
- `asyncio.Semaphore` — caps concurrent in-flight requests (default: 3) to respect server rate limits
55+
- `asyncio.gather(return_exceptions=True)` — all RIC coroutines run simultaneously; one failure does not cancel the rest
56+
- Per-result error inspection: `httpx.HTTPStatusError`, `httpx.RequestError`, generic `Exception`
57+
- `async with httpx.AsyncClient` — shared connection pool, closed cleanly on exit
58+
- Wall-clock timing across the full workflow
59+
60+
Notebook structure:
61+
1. Imports
62+
2. Constants (endpoint paths, RIC list)
63+
3. Credentials loaded from `src/.env`
64+
4. Helper functions (`post_authentication`, `post_auth_revoke`, `get_historical_interday_summaries`)
65+
5. Main execution block — authenticate, gather concurrent RIC fetches, per-result error handling
66+
6. Elapsed time output
67+
4668
## Included Scripts
4769

4870
### `src/example_sync_httpx.py` — Synchronous, direct `httpx` calls
@@ -135,6 +157,9 @@ APPKEY_RDP=<RDP AppKey>
135157
# Jupyter notebook (synchronous)
136158
jupyter lab src/simple_call_nb.ipynb
137159
160+
# Jupyter notebook (async — asyncio.gather)
161+
jupyter lab src/async_call_nb.ipynb
162+
138163
# Synchronous
139164
python .\src\example_client.py
140165

0 commit comments

Comments
 (0)