You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Data Platform APIs HTTP REST Application using HTTPX
2
2
3
-
Small Python examples that use [`httpx`](https://www.python-httpx.org/) to authenticate with [LSEG Data Platform APIs](https://developers.lseg.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis) (RDP, also known as Delivery Platform) using OAuth2 Password Grant, then call sample REST endpoints.
3
+
- Version: 1.0
4
+
- Last update: Mar 2026
5
+
- Environment: Python + JupyterLab + Data Platform Account
6
+
- Prerequisite: Data Platform access/entitlements
7
+
8
+
Python examples that use [`httpx`](https://www.python-httpx.org/) to authenticate with [LSEG Data Platform APIs](https://developers.lseg.com/en/api-catalog/refinitiv-data-platform/refinitiv-data-platform-apis) (RDP, also known as Delivery Platform) using OAuth 2.0 Password Grant, then call sample REST endpoints — covering both synchronous and asynchronous patterns.
9
+
10
+
## Project Structure
11
+
12
+
```
13
+
├── requirements.txt # Pinned dependencies
14
+
src/
15
+
├── .env.example # Environment variable template
16
+
├── example_sync_httpx.py # Synchronous — direct httpx module calls (no shared client)
- Synchronous (blocking) requests with direct `httpx` calls.
9
-
- Demonstrates:
10
-
-`POST /auth/oauth2/v1/token`
11
-
-`GET /data/pricing/chains/v1/`
12
-
-`POST /data/historical-pricing/v1/views/events`
13
-
- Refresh token flow (`grant_type=refresh_token`)
14
-
-`POST /auth/oauth2/v1/revoke`
25
+
### `src/example_sync_httpx.py` — Synchronous, direct `httpx` calls
26
+
27
+
Simplest synchronous example. Each function calls `httpx.get()` / `httpx.post()` directly — no shared client or connection pool. Good as a minimal reference or quick script.
28
+
29
+
Demonstrates:
30
+
-`POST /auth/oauth2/v1/token` — OAuth 2.0 Password Grant authentication
31
+
-`GET /data/pricing/chains/v1/` — chain constituent lookup for a single RIC
32
+
-`POST /data/historical-pricing/v1/views/events` — historical trade events for multiple RICs
33
+
- Refresh token flow (`grant_type=refresh_token`)
34
+
-`POST /auth/oauth2/v1/revoke` — session revocation using HTTP Basic Auth
35
+
- Per-call `verify=False` passed directly to each `httpx` function
36
+
37
+
### `src/example_client.py` — Synchronous with shared client
38
+
39
+
Synchronous (blocking) script using a single shared `httpx.Client` instance for connection pooling and consistent configuration across all requests.
40
+
41
+
Demonstrates:
42
+
-`POST /auth/oauth2/v1/token` — OAuth 2.0 Password Grant authentication
Async script using `httpx.AsyncClient`. Fetches interday-summaries for each RIC one after another inside a `for` loop. Simple starting point before introducing concurrency.
-`GET /data/historical-pricing/v1/views/interday-summaries/{ric}` — daily OHLCV data with corporate-action adjustments
56
+
- Sequential `await` per RIC — no concurrent requests
15
57
16
-
-`src/example_client.py`
17
-
- Synchronous (blocking) script using one shared `httpx.Client` (connection pooling + shared config).
18
-
- Includes simple environment validation and reusable helper methods.
19
-
- Demonstrates the same endpoint flow as above.
58
+
### `src/example_async_gather.py` — Async with `asyncio.gather()` and `Semaphore`
59
+
60
+
Async script that fires all RIC requests concurrently via `asyncio.gather()`, with an `asyncio.Semaphore` to cap the number of in-flight requests and avoid hitting server rate limits.
### `src/async_learn.py` — `ExceptionGroup` and `except*` sandbox
71
+
72
+
Standalone learning script demonstrating how `asyncio.gather(return_exceptions=True)` results can be re-raised as an `ExceptionGroup`, and how `except*` dispatches individual exception types from the group.
20
73
21
74
## Prerequisites
22
75
23
-
- Python 3.10+
76
+
- Python 3.11+ (required for `asyncio.TaskGroup` and `except*`)
24
77
- LSEG RDP credentials:
25
78
- Machine ID
26
79
- Password
@@ -43,9 +96,7 @@ python -m venv .venv
43
96
pip install -r requirements.txt
44
97
```
45
98
46
-
3. Create your environment file.
47
-
48
-
Copy `src/.env.example` to `src/.env` and fill in values:
99
+
3. Create your environment file by creating `src/.env` with the following content:
49
100
50
101
```dotenv
51
102
RDP_BASE_URL=https://api.refinitiv.com
@@ -58,27 +109,33 @@ APPKEY_RDP=<RDP AppKey>
58
109
## Run
59
110
60
111
```powershell
61
-
python .\src\example_sync_httpx.py
62
-
```
63
-
64
-
```powershell
112
+
# Synchronous
65
113
python .\src\example_client.py
114
+
115
+
# Async — sequential loop
116
+
python .\src\example_async_simple.py
117
+
118
+
# Async — concurrent via asyncio.gather()
119
+
python .\src\example_async_gather.py
120
+
121
+
# Async — concurrent via asyncio.TaskGroup
122
+
python .\src\example_async_taskgroup.py
66
123
```
67
124
68
-
For demo purposes, scripts print token/output payloads and endpoint responses.
125
+
Each script prints the authenticated request URLs and JSON responses. Timing is printed on exit for the async scripts.
69
126
70
127
## Security Notes
71
128
72
-
- The examples currently use `verify=False`, which disables TLS certificate verification.
73
-
- This is not safe for production. Remove `verify=False` (or provide a proper CA bundle) for real usage.
74
-
- Avoid printing access tokens in production applications/logs.
129
+
- All examples use `verify=False` to disable TLS certificate verification. This is intended for local/dev environments only (e.g. where a TLS-inspecting proxy such as ZScaler is in use). Remove `verify=False` or supply a proper CA bundle for production use.
130
+
- Do not log or print access tokens in production applications.
0 commit comments