Skip to main content

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://www.oilpriceapi.com/signup?utm_source=openbb&utm_medium=integration&utm_campaign=readme)
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 Wholesale spot price
GASOLINE_US US Gasoline Wholesale spot price

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

Also Available As

License

MIT License - see LICENSE for 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.1.tar.gz (9.4 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.1-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: openbb_oilpriceapi-0.1.1.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.13 Linux/6.17.0-1018-azure

File hashes

Hashes for openbb_oilpriceapi-0.1.1.tar.gz
Algorithm Hash digest
SHA256 32438bbf742873f7d75777ec7f300107d2db7bf0874dac2860dde8ab65f86b9d
MD5 43f407f30909cbbc55fb5d00c68ed1a6
BLAKE2b-256 ad723ef2a18bed52e9b64a5b7228f534c9b7a8d5620d9d8ad240a0854e20e3c5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: openbb_oilpriceapi-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.13 Linux/6.17.0-1018-azure

File hashes

Hashes for openbb_oilpriceapi-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a94ea395e4c5bd2ff77d6be5a77cae8654496952e6cfb2a189a80747f2d1b609
MD5 dcfdc48cc01ae8b87e7987a535efc4f1
BLAKE2b-256 5dad59deebd82030973ecd00a3155a003ca9707ef22c1b7a0d3d982d4645b133

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 Sentry Error logging StatusPage Status page