Get Diesel Prices in Python
Install in 30 seconds. Get real-time diesel prices from 130,000+ US gas stations.
Quick Start (3 Steps)
Install SDK
pip install oilpriceapiStart 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:00ZCompare 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 →Get Diesel Prices by State
Click any state to see current prices and get state-specific Python code examples:
Alabama
State tax: $0.270/gal
Get AL prices →
Alaska
State tax: $0.089/gal
Get AK prices →
Arizona
State tax: $0.270/gal
Get AZ prices →
Arkansas
State tax: $0.245/gal
Get AR prices →
California
State tax: $0.538/gal
Get CA prices →
Colorado
State tax: $0.205/gal
Get CO prices →
Connecticut
State tax: $0.495/gal
Get CT prices →
Delaware
State tax: $0.220/gal
Get DE prices →
Florida
State tax: $0.352/gal
Get FL prices →
Georgia
State tax: $0.329/gal
Get GA prices →
Hawaii
State tax: $0.160/gal
Get HI prices →
Idaho
State tax: $0.320/gal
Get ID prices →
Simple, Transparent Pricing
State Averages
- ✓Unlimited queries
- ✓All 50 US states
- ✓Weekly EIA updates
- ✓Perfect for analytics
Station-Level Prices
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 oilpriceapiIs 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