Skip to main content
🐍 Python SDK

Get Diesel Prices in Python

Install in 30 seconds. Get real-time diesel prices from 130,000+ US gas stations.

Quick Start (3 Steps)

1

Install SDK

pip install oilpriceapi
2

Get API Key

Free tier includes unlimited state averages. Sign up in 30 seconds.

Get free key →
3

Start Querying

Get diesel prices for any state, city, or specific gas station.

Get State Diesel Average (FREE)

from oilpriceapi import OilPriceAPI

client = OilPriceAPI(api_key="YOUR_API_KEY")

# Get California diesel price
ca_diesel = client.diesel_prices.get_regional(state="CA")

print(f"California diesel: $" + str(ca_diesel.price) + "/gal")
print(f"Last updated: " + str(ca_diesel.updated_at))

# Output:
# California diesel: $4.86/gal
# Last updated: 2025-12-15T00:00:00Z

Compare All 50 States

from oilpriceapi import OilPriceAPI

client = OilPriceAPI(api_key="YOUR_API_KEY")

# Get all state prices
states = ["CA", "TX", "FL", "NY", "PA"]
prices = []

for state in states:
    data = client.diesel_prices.get_regional(state=state)
    prices.append({
        "state": state,
        "price": data.price
    })

# Sort by price
prices.sort(key=lambda x: x["price"])

# Show cheapest 5 states
for p in prices[:5]:
    print(f"{p['state']}: $" + str(p['price']) + "/gal")

Get Cheapest Stations in a City ($0.024/query)

from oilpriceapi import OilPriceAPI

client = OilPriceAPI(api_key="YOUR_API_KEY")

# Get cheapest diesel in Los Angeles
stations = client.diesel_prices.get_stations(
    lat=34.0522,
    lng=-118.2437,
    radius=8047  # 5 miles in meters
)

# Sort by price
stations.sort(key=lambda s: s.diesel_price)

# Show top 10
for i, station in enumerate(stations[:10], 1):
    print(f"#{i}: " + station.name)
    print(f"   $" + str(station.diesel_price) + "/gal")
    print(f"   " + station.address)
    print()

Analyze Price Trends with Pandas

import pandas as pd
from oilpriceapi import OilPriceAPI

client = OilPriceAPI(api_key="YOUR_API_KEY")

# Get prices for multiple states
states = ["CA", "TX", "FL", "NY", "PA", "IL", "OH", "NC", "GA", "MI"]
data = []

for state in states:
    price_data = client.diesel_prices.get_regional(state=state)
    data.append({
        "state": state,
        "price": price_data.price,
        "updated": price_data.updated_at
    })

# Create DataFrame
df = pd.DataFrame(data)

# Calculate statistics
print(f"Average price: $" + str(df['price'].mean()))
print(f"Cheapest state: " + df.loc[df['price'].idxmin()]['state'])
print(f"Most expensive: " + df.loc[df['price'].idxmax()]['state'])

# Export to CSV
df.to_csv("diesel_prices.csv", index=False)

What Can You Build?

📊

Price Tracking Dashboard

Monitor diesel prices across your fleet's routes. Get alerts when prices drop.

See example →
📈

Data Analysis

Analyze fuel price trends, forecast costs, and optimize purchasing with pandas.

See example →
🤖

Automated Alerts

Build bots that notify your team when diesel prices change or drop below thresholds.

See example →

Simple, Transparent Pricing

State Averages

FREE
  • Unlimited queries
  • All 50 US states
  • Weekly EIA updates
  • Perfect for analytics

Station-Level Prices

$0.024

per query

  • 130,000+ US gas stations
  • 24-hour updates
  • GPS coordinates included
  • Perfect for routing apps

Frequently Asked Questions

How do I install the Python SDK?

Install via pip in one command:

pip install oilpriceapi

Is there a free tier?

Yes! State-level diesel prices are completely free with unlimited queries. Station-level prices cost $0.024 per query.

What data sources do you use?

State averages come from the EIA (Energy Information Administration). Station-level prices come from Google Maps (OPIS data) covering 130,000+ US locations.

Can I use this in production?

Absolutely! Our API powers production applications for fleet management, fuel price comparison apps, and data analytics platforms. 99.9% uptime SLA available.

Ready to Start Building?

Get your free API key and start querying diesel prices in Python today