Async Client
oilpriceapi.async_client.AsyncOilPriceAPI
Asynchronous client for OilPriceAPI.
Provides async/await support for all API operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
Optional[str]
|
API key for authentication |
None
|
base_url
|
Optional[str]
|
Base URL for API |
None
|
timeout
|
Optional[float]
|
Request timeout in seconds |
None
|
max_retries
|
Optional[int]
|
Maximum retry attempts |
None
|
Example
async with AsyncOilPriceAPI() as client: ... price = await client.prices.get("BRENT_CRUDE_USD") ... print(f"Brent: ${price.value:.2f}")
request(method, path, params=None, json_data=None, **kwargs)
async
Make async HTTP request to API.
market_brief(codes, narrative=False)
async
Get a multi-commodity structured (+ optional narrative) market brief.
Composes existing price/forecast data for the given commodity codes into a single structured summary (#3245 Phase 1a). Counts as one request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
codes
|
List[str]
|
Commodity codes to include (e.g. ["BRENT_CRUDE_USD", "WTI"]). |
required |
narrative
|
bool
|
When True, request a natural-language narrative as well. |
False
|
Returns:
| Type | Description |
|---|---|
MarketBrief
|
A MarketBrief model. |
close()
async
Close the HTTP client and flush telemetry.
__aenter__()
async
Async context manager entry.
__aexit__(exc_type, exc_val, exc_tb)
async
Async context manager exit.