|
9 | 9 | [](https://codecov.io/gh/oilpriceapi/python-sdk) |
10 | 10 | [](https://opensource.org/licenses/MIT) |
11 | 11 |
|
12 | | -**[Get Free API Key](https://oilpriceapi.com/auth/signup)** • **[Documentation](https://docs.oilpriceapi.com/sdk/python)** • **[Examples](EXAMPLES.md)** • **[Pricing](https://oilpriceapi.com/pricing)** |
| 12 | +**[Get Free API Key](https://oilpriceapi.com/auth/signup)** • **[Documentation](https://docs.oilpriceapi.com/sdk/python)** • **[Pricing](https://oilpriceapi.com/pricing)** |
13 | 13 |
|
14 | 14 | The official Python SDK for [OilPriceAPI](https://oilpriceapi.com) - Real-time and historical oil prices for Brent Crude, WTI, Natural Gas, and more. |
15 | 15 |
|
| 16 | +> **📝 Documentation Status**: This README reflects v1.4.0 features. All code examples shown are tested and working. Advanced features like technical indicators and CLI tools are planned for future releases - see our [GitHub Issues](https://github.com/OilpriceAPI/python-sdk/issues) for roadmap. |
| 17 | +
|
16 | 18 | **Quick start:** |
17 | 19 | ```bash |
18 | 20 | pip install oilpriceapi |
@@ -56,14 +58,8 @@ df = client.prices.to_dataframe( |
56 | 58 | interval="daily" |
57 | 59 | ) |
58 | 60 |
|
59 | | -# Add technical indicators |
60 | | -df = client.analysis.with_indicators( |
61 | | - df, |
62 | | - indicators=["sma_20", "sma_50", "rsi", "bollinger_bands"] |
63 | | -) |
64 | | - |
65 | | -# Calculate spread between Brent and WTI |
66 | | -spread = client.analysis.spread("BRENT_CRUDE_USD", "WTI_USD", start="2024-01-01") |
| 61 | +print(f"Retrieved {len(df)} data points") |
| 62 | +print(df.head()) |
67 | 63 | ``` |
68 | 64 |
|
69 | 65 | ### Diesel Prices (New in v1.3.0) |
@@ -173,13 +169,12 @@ print(df[["name", "commodity_code", "condition_value", "trigger_count"]]) |
173 | 169 | - ✅ **Simple API** - Intuitive methods for all endpoints |
174 | 170 | - ✅ **Type Safe** - Full type hints for IDE autocomplete |
175 | 171 | - ✅ **Pandas Integration** - First-class DataFrame support |
176 | | -- ✅ **Price Alerts** - Automated monitoring with webhook notifications 🔔 NEW |
| 172 | +- ✅ **Price Alerts** - Automated monitoring with webhook notifications 🔔 |
177 | 173 | - ✅ **Diesel Prices** - State averages + station-level pricing ⛽ |
178 | 174 | - ✅ **Async Support** - High-performance async client |
179 | 175 | - ✅ **Smart Caching** - Reduce API calls automatically |
180 | 176 | - ✅ **Rate Limit Handling** - Automatic retries with backoff |
181 | | -- ✅ **Technical Indicators** - Built-in SMA, RSI, MACD, etc. |
182 | | -- ✅ **CLI Tool** - Command-line interface included |
| 177 | +- ✅ **Error Handling** - Comprehensive exception classes |
183 | 178 |
|
184 | 179 | ## 📚 Documentation |
185 | 180 |
|
@@ -261,51 +256,74 @@ async def get_prices(): |
261 | 256 | prices = asyncio.run(get_prices()) |
262 | 257 | ``` |
263 | 258 |
|
264 | | -## 🛠️ CLI Tool |
| 259 | +## 🧪 Testing |
265 | 260 |
|
266 | | -```bash |
267 | | -# Get current price |
268 | | -oilprice get BRENT_CRUDE_USD |
| 261 | +The SDK uses standard Python testing frameworks. Example using pytest: |
269 | 262 |
|
270 | | -# Export historical data |
271 | | -oilprice export WTI_USD --start 2024-01-01 --format csv -o wti_2024.csv |
| 263 | +```python |
| 264 | +import pytest |
| 265 | +from oilpriceapi import OilPriceAPI |
272 | 266 |
|
273 | | -# Watch prices in real-time |
274 | | -oilprice watch BRENT_CRUDE_USD --interval 60 |
| 267 | +def test_get_price(): |
| 268 | + client = OilPriceAPI(api_key="your_test_key") |
| 269 | + price = client.prices.get("BRENT_CRUDE_USD") |
| 270 | + |
| 271 | + assert price is not None |
| 272 | + assert price.value > 0 |
| 273 | + assert price.commodity == "BRENT_CRUDE_USD" |
275 | 274 | ``` |
276 | 275 |
|
277 | | -## 🧪 Testing |
| 276 | +## 📈 Examples |
278 | 277 |
|
279 | | -The SDK includes utilities for testing your applications: |
| 278 | +### Quick Examples |
280 | 279 |
|
281 | 280 | ```python |
282 | | -from oilpriceapi.testing import MockClient |
| 281 | +# Example 1: Get multiple commodity prices |
| 282 | +from oilpriceapi import OilPriceAPI |
283 | 283 |
|
284 | | -def test_my_strategy(): |
285 | | - client = MockClient() |
286 | | - client.set_price("BRENT_CRUDE_USD", 75.50) |
| 284 | +client = OilPriceAPI() |
| 285 | +commodities = ["BRENT_CRUDE_USD", "WTI_USD", "NATURAL_GAS_USD"] |
| 286 | +prices = client.prices.get_multiple(commodities) |
287 | 287 |
|
288 | | - result = my_trading_strategy(client) |
289 | | - assert result.action == "BUY" |
| 288 | +for price in prices: |
| 289 | + print(f"{price.commodity}: ${price.value:.2f}") |
290 | 290 | ``` |
291 | 291 |
|
292 | | -## 📈 Examples |
| 292 | +```python |
| 293 | +# Example 2: Historical data analysis with pandas |
| 294 | +import pandas as pd |
| 295 | +from oilpriceapi import OilPriceAPI |
293 | 296 |
|
294 | | -### Real-World Use Cases |
| 297 | +client = OilPriceAPI() |
| 298 | +df = client.prices.to_dataframe( |
| 299 | + commodity="BRENT_CRUDE_USD", |
| 300 | + start="2024-01-01", |
| 301 | + end="2024-12-31" |
| 302 | +) |
295 | 303 |
|
296 | | -See **[EXAMPLES.md](https://github.com/OilpriceAPI/python-sdk/blob/main/EXAMPLES.md)** for comprehensive examples including: |
297 | | -- 📊 **Trading Strategies** - Moving averages, spread analysis, risk management |
298 | | -- 📈 **Data Analysis** - Seasonal patterns, correlations, forecasting |
299 | | -- 💻 **Web Applications** - Dashboards, REST APIs, monitoring systems |
300 | | -- 📤 **Data Export** - Excel reports, database integration, alerts |
| 304 | +# Calculate simple moving average |
| 305 | +df['SMA_20'] = df['price'].rolling(window=20).mean() |
| 306 | +print(df[['created_at', 'price', 'SMA_20']].tail()) |
| 307 | +``` |
301 | 308 |
|
302 | | -### Code Samples |
| 309 | +```python |
| 310 | +# Example 3: Price alerts with webhooks |
| 311 | +from oilpriceapi import OilPriceAPI |
| 312 | + |
| 313 | +client = OilPriceAPI() |
303 | 314 |
|
304 | | -Check out the [examples/](https://github.com/OilpriceAPI/python-sdk/tree/main/examples/) directory for: |
305 | | -- [Quickstart Notebook](examples/quickstart.ipynb) |
306 | | -- [Data Analysis](examples/data_analysis.ipynb) |
307 | | -- [Trading Signals](examples/trading_signals.ipynb) |
308 | | -- [Async Operations](examples/async_example.py) |
| 315 | +# Create alert when oil exceeds $85 |
| 316 | +alert = client.alerts.create( |
| 317 | + name="High Oil Price Alert", |
| 318 | + commodity_code="BRENT_CRUDE_USD", |
| 319 | + condition_operator="greater_than", |
| 320 | + condition_value=85.00, |
| 321 | + webhook_url="https://your-app.com/webhook", |
| 322 | + enabled=True |
| 323 | +) |
| 324 | + |
| 325 | +print(f"Alert created: {alert.id}") |
| 326 | +``` |
309 | 327 |
|
310 | 328 | ## 🔧 Development |
311 | 329 |
|
|
0 commit comments