OilPriceAPI Python SDK Documentation
Welcome to the official Python SDK for OilPriceAPI - the most affordable way to access professional-grade oil and commodity price data.
🚀 Getting Started
Installation
Install the SDK using pip:
pip install oilpriceapi
Get Your API Key
- Sign up for free at OilPriceAPI
- Get your API key from the dashboard
- Start making requests immediately
Quick Example
from oilpriceapi import OilPriceAPI
# Initialize with your API key
client = OilPriceAPI(api_key="your_api_key")
# Get latest Brent Crude price
price = client.prices.get("BRENT_CRUDE_USD")
print(f"Brent Crude: ${price.value:.2f}")
📚 Core Features
Real-Time Price Data
Get the latest commodity prices updated every 5 minutes:
# Single commodity
brent = client.prices.get("BRENT_CRUDE_USD")
# Multiple commodities
prices = client.prices.get_multiple([
"BRENT_CRUDE_USD",
"WTI_USD",
"NATURAL_GAS_USD"
])
View all available commodities →
Historical Data
Access years of historical price data for backtesting and analysis:
# Get historical data
df = client.prices.to_dataframe(
commodity="BRENT_CRUDE_USD",
start="2024-01-01",
end="2024-12-31",
interval="daily"
)
# Analyze trends
print(df.describe())
Learn about historical endpoints →
Technical Analysis
Built-in technical indicators for trading strategies:
# Add moving averages, RSI, MACD
df = client.analysis.with_indicators(
df,
indicators=["sma_20", "sma_50", "rsi", "bollinger_bands"]
)
# Calculate spread between commodities
spread = client.analysis.spread("BRENT_CRUDE_USD", "WTI_USD")
Async Support
High-performance async operations for concurrent requests:
import asyncio
from oilpriceapi import AsyncOilPriceAPI
async def get_all_prices():
async with AsyncOilPriceAPI() as client:
prices = await asyncio.gather(
client.prices.get("BRENT_CRUDE_USD"),
client.prices.get("WTI_USD"),
client.prices.get("NATURAL_GAS_USD")
)
return prices
prices = asyncio.run(get_all_prices())
🎯 Use Cases
Energy Trading
Build algorithmic trading strategies with real-time price feeds and historical data for backtesting.
Financial Analysis
Integrate commodity prices into financial models and risk management systems.
Research & Analytics
Analyze long-term price trends, correlations, and market dynamics for academic or commercial research.
Web & Mobile Apps
Embed live commodity price widgets and charts in your applications.
📊 Available Commodities
Crude Oil
- Brent Crude (
BRENT_CRUDE_USD) - International benchmark - WTI (
WTI_USD) - US benchmark - Dubai Crude (
DUBAI_CRUDE_USD) - Middle East benchmark
Natural Gas
- Natural Gas (
NATURAL_GAS_USD) - Henry Hub spot price - LNG (
LNG_USD) - Liquefied natural gas
Refined Products
- Diesel (
DIESEL_USD) - Gasoline (
GASOLINE_USD) - Heating Oil (
HEATING_OIL_USD) - Jet Fuel (
JET_FUEL_USD)
View complete commodity list →
🔧 Advanced Configuration
Authentication
# Environment variable (recommended)
export OILPRICEAPI_KEY="your_api_key"
client = OilPriceAPI()
# Direct configuration
client = OilPriceAPI(
api_key="your_api_key",
timeout=30,
max_retries=3
)
Caching
# In-memory caching
client = OilPriceAPI(
cache="memory",
cache_ttl=300 # 5 minutes
)
# Redis caching
client = OilPriceAPI(
cache="redis",
cache_url="redis://localhost:6379"
)
Error Handling
from oilpriceapi.exceptions import (
OilPriceAPIError,
RateLimitError,
DataNotFoundError
)
try:
price = client.prices.get("BRENT_CRUDE_USD")
except RateLimitError as e:
print(f"Rate limited. Resets in {e.seconds_until_reset}s")
except DataNotFoundError:
print("Commodity not found")
except OilPriceAPIError as e:
print(f"API error: {e}")
💰 Pricing & Plans
Choose the plan that fits your needs:
Free Tier
- 1,000 API requests/month
- Real-time data
- No credit card required
Paid Plans
- Exploration: $15/month - 10,000 requests
- Production Boost: $45/month - 50,000 requests
- Reservoir Mastery: $129/month - 250,000 requests
All plans include: - ✅ Real-time price updates every 5 minutes - ✅ Historical data access - ✅ 99.9% uptime SLA - ✅ Email support - ✅ No hidden fees
🛠️ Development
Testing Your Integration
from oilpriceapi.testing import MockClient
def test_trading_strategy():
# Create mock client
client = MockClient()
client.set_price("BRENT_CRUDE_USD", 75.50)
# Test your code
result = my_strategy(client)
assert result.action == "BUY"
Running Tests
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# With coverage
pytest --cov=oilpriceapi --cov-report=html
📖 Additional Resources
Documentation
- API Reference - Complete REST API documentation
- SDK Reference - Python SDK API reference
- Quickstart Guide - Get started in 5 minutes
- Code Examples - Real-world code samples
Support
- FAQ - Frequently asked questions
- Status Page - API status and uptime
- GitHub Issues - Bug reports and feature requests
- Email Support - Get help from our team
Learning
- Blog - Industry insights and tutorials
- Use Cases - Learn how others use the API
- Changelog - SDK version history
🤝 Contributing
We welcome contributions! Check out our Contributing Guide to get started.
📝 License
MIT License - see LICENSE file for details.
Ready to get started? Sign up for your free API key →
Questions? Contact our support team →
Want to learn more? Visit OilPriceAPI.com →