-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path__init__.py
More file actions
103 lines (90 loc) · 2.48 KB
/
Copy path__init__.py
File metadata and controls
103 lines (90 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"""
OilPriceAPI Python SDK
The official Python SDK for OilPriceAPI - Real-time and historical oil prices.
"""
from typing import Optional
from oilpriceapi.version import __version__ # noqa: F401
__author__ = "OilPriceAPI"
__email__ = "support@oilpriceapi.com"
from oilpriceapi.async_client import AsyncOilPriceAPI
from oilpriceapi.client import OilPriceAPI
from oilpriceapi.exceptions import (
AuthenticationError,
ConfigurationError,
DataNotFoundError,
OilPriceAPIError,
RateLimitError,
ServerError,
TimeoutError,
ValidationError,
)
from oilpriceapi.models import (
DataConnectorPrice,
DieselPrice,
DieselStation,
DieselStationsResponse,
MarketBrief,
MarketBriefCommodity,
MarketBriefForecast,
PriceAlert,
Subscription,
SubscriptionEvent,
WebhookTestResponse,
)
from oilpriceapi.resources.subscriptions import SubscriptionEventsPage
from oilpriceapi.streaming import (
PriceStream,
PriceUpdate,
RigCountUpdate,
StreamingNotInstalledError,
StreamUpdate,
)
__all__ = [
"OilPriceAPI",
"AsyncOilPriceAPI",
"OilPriceAPIError",
"AuthenticationError",
"RateLimitError",
"DataNotFoundError",
"ServerError",
"ValidationError",
"TimeoutError",
"ConfigurationError",
"DieselPrice",
"DieselStation",
"DieselStationsResponse",
"PriceAlert",
"WebhookTestResponse",
"DataConnectorPrice",
"MarketBrief",
"MarketBriefCommodity",
"MarketBriefForecast",
"Subscription",
"SubscriptionEvent",
"SubscriptionEventsPage",
"PriceStream",
"StreamUpdate",
"PriceUpdate",
"RigCountUpdate",
"StreamingNotInstalledError",
]
from oilpriceapi.resources.webhooks import WebhooksResource
# Standalone webhook signature verification
verify_webhook_signature = WebhooksResource.verify_signature
# Convenience function for quick access
def get_current_price(commodity: str, api_key: Optional[str] = None) -> float:
"""
Quick helper to get current price without client initialization.
Args:
commodity: Commodity code (e.g., "BRENT_CRUDE_USD")
api_key: Optional API key (uses environment variable if not provided)
Returns:
Current price as float
Example:
>>> import oilpriceapi as opa
>>> price = opa.get_current_price("BRENT_CRUDE_USD")
>>> print(f"Oil: ${price}")
"""
with OilPriceAPI(api_key=api_key) as client:
price = client.prices.get(commodity)
return price.value