LangChain tools for OilPriceAPI — real-time oil, gas, and commodity prices
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_oilpriceapi-1.0.0.tar.gz.
File metadata
- Download URL: langchain_oilpriceapi-1.0.0.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8d4a7d168c90b67a75a9740cae57a9ada1dad706370cbfa514882d5a1c5a8d4
|
|
| MD5 |
6979abc7b4073269443f80aebeee5651
|
|
| BLAKE2b-256 |
403665cf869380a270ee01d6199015c1bd617ed248967be5da2ee4de1a1c843b
|
File details
Details for the file langchain_oilpriceapi-1.0.0-py3-none-any.whl.
File metadata
- Download URL: langchain_oilpriceapi-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fbc9fb1ce0e27d41c2c1e167333b830b85c39562a07b1853ed6df5248fedb8f
|
|
| MD5 |
20bf711118cebc45d44b58f6c8262b08
|
|
| BLAKE2b-256 |
c08d918a5a382fa1bb106befa4bf832d4efa04dfaac64279b0ff28d14b525b1b
|