Skip to main content

OpenBB provider for OilPriceAPI - Real-time oil and commodity prices (WTI, Brent, Urals, Natural Gas, Coal)

Project description

openbb-oilpriceapi

PyPI version License: MIT

OpenBB provider for OilPriceAPI - Real-time oil and commodity prices.

Installation

pip install openbb-oilpriceapi

Quick Start

from openbb import obb

# Configure your API key (get free key at https://oilpriceapi.com/signup)
obb.user.credentials.oilpriceapi_api_key = "your_api_key"

# Get all commodity prices
prices = obb.commodity.oil.price(provider="oilpriceapi")
df = prices.to_dataframe()
print(df)

# Get specific commodity (WTI crude)
wti = obb.commodity.oil.price(symbol="WTI", provider="oilpriceapi")
print(f"WTI Price: ${wti.results[0].price}/barrel")

Supported Commodities

Symbol Name Description
WTI WTI Crude Oil West Texas Intermediate benchmark
BRENT Brent Crude Oil North Sea benchmark
URALS Urals Crude Oil Russian export blend
DUBAI Dubai Crude Oil Middle East benchmark
NG Natural Gas (US) Henry Hub
NG_EU Natural Gas (EU) TTF
NG_UK Natural Gas (UK) NBP
COAL Coal Thermal coal
DIESEL_US US Diesel National average
GASOLINE_US US Gasoline National average

Configuration

Set Credentials

You can set your API key in multiple ways:

Option 1: In Python

obb.user.credentials.oilpriceapi_api_key = "your_key"

Option 2: Via settings file Add to ~/.openbb_platform/user_settings.json:

{
  "credentials": {
    "oilpriceapi_api_key": "your_key"
  }
}

Option 3: Environment variable

export OPENBB_OILPRICEAPI_API_KEY="your_key"

Examples

Get Price History

# Get WTI prices for the past week
history = obb.commodity.oil.historical(
    symbol="WTI",
    period="past_week",
    provider="oilpriceapi"
)
df = history.to_dataframe()

Compare Commodities

import pandas as pd

# Get all prices and compare
prices = obb.commodity.oil.price(provider="oilpriceapi")
df = prices.to_dataframe()

# Filter for crude oils
crude = df[df['symbol'].isin(['WTI', 'BRENT', 'URALS'])]
print(crude[['symbol', 'price', 'change_percent']])

Visualize Prices

import matplotlib.pyplot as plt

history = obb.commodity.oil.historical(
    symbol="BRENT",
    period="past_month",
    provider="oilpriceapi"
)
df = history.to_dataframe()

plt.figure(figsize=(10, 6))
plt.plot(df['date'], df['price'])
plt.title('Brent Crude - Past Month')
plt.ylabel('Price (USD/barrel)')
plt.show()

API Reference

OilPrice

Fetch latest commodity prices.

Parameters:

  • symbol (str, optional): Commodity symbol. If not provided, returns all commodities.
  • provider (str): Must be "oilpriceapi"

Returns:

  • symbol: Commodity symbol
  • name: Commodity name
  • price: Current price
  • currency: Price currency
  • unit: Unit of measurement
  • updated_at: Last update timestamp
  • change: Price change (absolute)
  • change_percent: Price change (percentage)

OilHistorical

Fetch historical price data.

Parameters:

  • symbol (str, required): Commodity symbol
  • period (str): Historical period - past_day (24h hourly), past_week (7d daily), past_month (30d daily). Default: past_week
  • provider (str): Must be "oilpriceapi"

Returns:

  • date: Price timestamp
  • symbol: Commodity symbol
  • price: Price at timestamp
  • currency: Price currency
  • unit: Unit of measurement

Development

# Clone the repository
git clone https://github.com/OilpriceAPI/openbb-oilpriceapi.git
cd openbb-oilpriceapi

# Install dependencies
poetry install

# Run tests
poetry run pytest

# Run tests with coverage
poetry run pytest --cov=openbb_oilpriceapi

Links

License

MIT License - see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openbb_oilpriceapi-0.1.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openbb_oilpriceapi-0.1.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file openbb_oilpriceapi-0.1.0.tar.gz.

File metadata

  • Download URL: openbb_oilpriceapi-0.1.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.6.87.2-microsoft-standard-WSL2

File hashes

Hashes for openbb_oilpriceapi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 89a611d8098e5f143394667d2b6e62df384addd5823bc797f3617cfdc241d533
MD5 ef76f3f04bd04e6342d4d713262356c8
BLAKE2b-256 8b8d3f109170f9d3114460007a4b4ffa33ea82aa848358d5d64e7f740d83c882

See more details on using hashes here.

File details

Details for the file openbb_oilpriceapi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: openbb_oilpriceapi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.6.87.2-microsoft-standard-WSL2

File hashes

Hashes for openbb_oilpriceapi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0ee43e26e0103610f747abbb418684cead01f70b44a2b575d55a10adeb4bcf7f
MD5 f0397ebe231a2697a68a081c5a3d6664
BLAKE2b-256 f4163cd3a79841e8e58f47aaeea1997e7db008ee955e0db6edb8d190cf7d18d1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page