Skip to main content

langchain-oilpriceapi

LangChain tools for OilPriceAPI — real-time oil, gas, and commodity prices for AI agents.

Installation

pip install langchain-oilpriceapi

Quick Start

import os
from langchain_oilpriceapi import OilPriceTools
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent

# Set your API key
os.environ["OILPRICEAPI_KEY"] = "your_api_key_here"

# Get all tools
tools = OilPriceTools().get_tools()

# Build an agent
llm = ChatOpenAI(model="gpt-4o")
agent = create_react_agent(llm, tools)

# Ask questions
result = agent.invoke({
    "messages": [{"role": "user", "content": "What's the current Brent crude price and how does it compare to WTI?"}]
})
print(result["messages"][-1].content)

Tools

Tool Description
get_commodity_price Get the current price of a commodity by name or code
get_market_overview Get all commodity prices, optionally filtered by category
compare_prices Compare 2–5 commodities side by side with spread calculation
list_commodities List all available commodity codes
get_historical_prices Get price history over day/week/month/year with statistics

Using Individual Tools

from langchain_oilpriceapi import get_commodity_price, get_historical_prices

# Direct tool call
price = get_commodity_price.invoke({"commodity": "brent crude"})
print(price)

# Historical data
history = get_historical_prices.invoke({"commodity": "natural gas", "period": "week"})
print(history)

Supported Commodities

Crude Oil: Brent (BRENT_CRUDE_USD), WTI (WTI_USD), Urals (URALS_CRUDE_USD), Dubai (DUBAI_CRUDE_USD)

Natural Gas: US Henry Hub (NATURAL_GAS_USD), UK NBP (NATURAL_GAS_GBP), European TTF (DUTCH_TTF_EUR)

Refined Products: Diesel, Gasoline, RBOB Gasoline, Jet Fuel, Heating Oil (all _USD)

Coal: COAL_USD, NEWCASTLE_COAL_USD

Precious Metals: Gold (USD/GBP/EUR AM+PM fixes), Silver (USD/GBP/EUR)

Other: EU Carbon (EU_CARBON_EUR), EUR/USD, GBP/USD

You can use natural language names like "brent oil", "natural gas", or "diesel" — the tools will resolve to the correct code automatically.

Authentication

Set the OILPRICEAPI_KEY environment variable to your API key:

export OILPRICEAPI_KEY=your_api_key_here

Get your API key at oilpriceapi.com.

Metadata

Release files for langchain-oilpriceapi 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-oilpriceapi 1.0.0
File Size Uploaded
langchain_oilpriceapi-1.0.0.tar.gz 3.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for langchain-oilpriceapi 1.0.0
File Interpreter ABI Platform
langchain_oilpriceapi-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.9 kB

Release files / langchain_oilpriceapi-1.0.0.tar.gz

Download URL langchain_oilpriceapi-1.0.0.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c8d4a7d168c90b67a75a9740cae57a9ada1dad706370cbfa514882d5a1c5a8d4
BLAKE2b-256 checksum
How to use checksums
403665cf869380a270ee01d6199015c1bd617ed248967be5da2ee4de1a1c843b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / langchain_oilpriceapi-1.0.0-py3-none-any.whl

Download URL langchain_oilpriceapi-1.0.0-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5fbc9fb1ce0e27d41c2c1e167333b830b85c39562a07b1853ed6df5248fedb8f
BLAKE2b-256 checksum
How to use checksums
c08d918a5a382fa1bb106befa4bf832d4efa04dfaac64279b0ff28d14b525b1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page