Welcome to the official Python SDK for OilPriceAPI - the most affordable way to access professional-grade oil and commodity price data.
Install the SDK using pip:
pip install oilpriceapi- Sign up for free at OilPriceAPI
- Get your API key from the dashboard
- Start making requests immediately
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}")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 →
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 →
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")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())Build algorithmic trading strategies with real-time price feeds and historical data for backtesting.
Integrate commodity prices into financial models and risk management systems.
Analyze long-term price trends, correlations, and market dynamics for academic or commercial research.
Embed live commodity price widgets and charts in your applications.
- Brent Crude (
BRENT_CRUDE_USD) - International benchmark - WTI (
WTI_USD) - US benchmark - Dubai Crude (
DUBAI_CRUDE_USD) - Middle East benchmark
- Natural Gas (
NATURAL_GAS_USD) - Henry Hub spot price - LNG (
LNG_USD) - Liquefied natural gas
- Diesel (
DIESEL_USD) - Gasoline (
GASOLINE_USD) - Heating Oil (
HEATING_OIL_USD) - Jet Fuel (
JET_FUEL_USD)
View complete commodity list →
# 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
)# In-memory caching
client = OilPriceAPI(
cache="memory",
cache_ttl=300 # 5 minutes
)
# Redis caching
client = OilPriceAPI(
cache="redis",
cache_url="redis://localhost:6379"
)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}")Choose the plan that fits your needs:
- 1,000 API requests/month
- Real-time data
- No credit card required
- 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
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"# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# With coverage
pytest --cov=oilpriceapi --cov-report=html- 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
- FAQ - Frequently asked questions
- Status Page - API status and uptime
- GitHub Issues - Bug reports and feature requests
- Email Support - Get help from our team
- Blog - Industry insights and tutorials
- Use Cases - Learn how others use the API
- Changelog - SDK version history
We welcome contributions! Check out our Contributing Guide to get started.
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 →