Skip to main content

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


Download files

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

Source Distribution

langchain_oilpriceapi-1.0.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

langchain_oilpriceapi-1.0.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

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

Hashes for langchain_oilpriceapi-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c8d4a7d168c90b67a75a9740cae57a9ada1dad706370cbfa514882d5a1c5a8d4
MD5 6979abc7b4073269443f80aebeee5651
BLAKE2b-256 403665cf869380a270ee01d6199015c1bd617ed248967be5da2ee4de1a1c843b

See more details on using hashes here.

File details

Details for the file langchain_oilpriceapi-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_oilpriceapi-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5fbc9fb1ce0e27d41c2c1e167333b830b85c39562a07b1853ed6df5248fedb8f
MD5 20bf711118cebc45d44b58f6c8262b08
BLAKE2b-256 c08d918a5a382fa1bb106befa4bf832d4efa04dfaac64279b0ff28d14b525b1b

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