Python library for accessing the UK Government Fuel Finder API
Project description
UK Fuel Finder Python Library
Python library for accessing the UK Government Fuel Finder API.
⚠️ API Changes (February 17, 2025)
The UK Fuel Finder API has been updated with breaking changes:
Breaking Changes
- Removed Fields:
successandmessagefields removed from API responses - New Field:
price_change_effective_timestampadded to fuel price responses - Error Codes: Invalid batch numbers now return HTTP 404 (Not Found) instead of previous error codes
- Data Types: Latitude and longitude values now use double precision
Backward Compatibility
This library includes backward compatibility mode (enabled by default):
# With backward compatibility (default)
client = FuelFinderClient(backward_compatible=True)
prices = client.get_all_pfs_prices()
print(prices[0].success) # Returns True (for backward compatibility)
print(prices[0].message) # Returns empty string (for backward compatibility)
# Without backward compatibility
client = FuelFinderClient(backward_compatible=False)
prices = client.get_all_pfs_prices()
# prices[0].success and prices[0].message not available
Environment Variable
Control backward compatibility via environment variable:
export UKFUELFINDER_BACKWARD_COMPATIBLE=0 # Disable backward compatibility
Migration Guide
- Update to the latest version of this library
- Test with
backward_compatible=True(default) - Update your code to remove usage of
successandmessagefields - Handle 404 errors for invalid batch numbers
- Switch to
backward_compatible=Falsewhen ready - Update to use the new
price_change_effective_timestampfield
⚠️ API Changes (February 25-26, 2026)
The UK Fuel Finder API has removed additional fields:
Breaking Changes
- Removed Field:
mft_organisation_nameremoved from all API responses - Removed Field:
mft.nameremoved from CSV extracts
Impact
- The
mft_organisation_namefield inPFSandPFSInfomodels is nowOptional[str] - Field will be
Nonefor all new API responses - Existing code accessing this field will receive
Noneinstead of a string value
Migration
Check for None before using the field:
pfs = client.get_all_pfs_prices()[0]
if pfs.mft_organisation_name:
print(f"Organisation: {pfs.mft_organisation_name}")
else:
print("Organisation name not available")
Features
- OAuth 2.0 Authentication - Automatic token management with refresh support
- Comprehensive Data Access - Fuel prices and forecourt information
- Built-in Caching - Reduces API calls with configurable TTL
- Rate Limiting - Automatic retry with exponential backoff
- Type Hints - Full type annotations for better IDE support
- Extensive Error Handling - Clear exceptions for all error cases
- Batch Pagination - Automatic handling of 500-record batches
- Incremental Updates - Fetch only changed data since a specific date
Installation
pip install ukfuelfinder
Quick Start
from ukfuelfinder import FuelFinderClient
# Initialize client
client = FuelFinderClient(
client_id="your_client_id",
client_secret="your_client_secret",
environment="production" # or "test"
)
# Get all fuel prices
prices = client.get_all_pfs_prices()
# Search for stations near a location (returns list of (distance, PFSInfo) tuples)
nearby = client.search_by_location(latitude=51.5074, longitude=-0.1278, radius_km=5.0)
for distance, station in nearby:
print(f"{distance:.2f}km - {station.trading_name}")
# Get prices for specific fuel type
unleaded_prices = client.get_prices_by_fuel_type("unleaded")
# Get forecourt information
forecourts = client.get_all_pfs_info()
# Get incremental updates since yesterday
from datetime import datetime, timedelta
yesterday = (datetime.now() - timedelta(days=1)).strftime("%Y-%m-%d")
updated_prices = client.get_incremental_price_updates(yesterday)
Environment Variables
Set credentials via environment variables:
export FUEL_FINDER_CLIENT_ID="your_client_id"
export FUEL_FINDER_CLIENT_SECRET="your_client_secret"
export FUEL_FINDER_ENVIRONMENT="production"
Then initialize without parameters:
client = FuelFinderClient()
Documentation
Requirements
- Python 3.8+
- Valid Fuel Finder API credentials from developer.fuel-finder.service.gov.uk
API Coverage
This library provides access to all Information Recipient API endpoints:
-
Authentication
- Generate OAuth access token
- Refresh access token
-
Fuel Prices
- Fetch all PFS fuel prices (full or incremental)
-
Forecourt Information
- Fetch all PFS information (500 per batch)
- Fetch incremental PFS information updates
Examples
See the examples/ directory for complete working examples:
basic_usage.py- Simple getting started exampleerror_handling.py- Comprehensive error handlingfetch_fuel_prices.py- Fetch all fuel prices and save to JSONfetch_all_sites.py- Fetch all forecourt sites and save to JSONlocation_search.py- Search for stations near a location
Backward Compatibility Example
# With backward compatibility (default)
client = FuelFinderClient(backward_compatible=True)
prices = client.get_all_pfs_prices()
print(prices[0].success) # Returns True (for backward compatibility)
print(prices[0].message) # Returns empty string (for backward compatibility)
# Without backward compatibility
client = FuelFinderClient(backward_compatible=False)
prices = client.get_all_pfs_prices()
# prices[0].success and prices[0].message not available
# Use price_change_effective_timestamp instead
if prices[0].fuel_prices:
print(prices[0].fuel_prices[0].price_change_effective_timestamp)
Development
Setup
git clone https://github.com/mretallack/ukfuelfinder.git
cd ukfuelfinder
pip install -e .[dev]
Running Tests
pytest
Code Quality
black ukfuelfinder tests
mypy ukfuelfinder
flake8 ukfuelfinder
Future Enhancements
Potential features for future development:
Smart Fuel Recommendations
- Cost-optimized routing - Calculate total fuel cost including detour distance based on vehicle consumption
- Cheapest fuel finder - Find the most economical option considering current location, fuel prices, and distance
- Route integration - Suggest fuel stops along planned routes with minimal detour
Price Intelligence
- Price alerts - Notify users when prices drop below a threshold in their area
- Price forecasting - Predict price trends based on historical data
- Price comparison - Compare prices across brands, regions, and fuel types
Advanced Filtering
- Multi-criteria search - Filter by amenities (car wash, shop, 24-hour, EV charging)
- Brand preferences - Filter by preferred fuel brands or loyalty programs
- Fuel type availability - Find stations with specific fuel types (HVO, E10, premium diesel)
Journey Planning
- Fuel range calculator - Estimate remaining range and suggest refuel points
- Multi-stop optimization - Plan optimal fuel stops for long journeys
- Emergency fuel finder - Quick search for nearest station when running low
Data Analytics
- Spending tracking - Monitor fuel expenses over time
- Savings calculator - Calculate savings from using cheapest stations
- Regional price analysis - Compare average prices across different areas
Integration Features
- Navigation app integration - Direct routing to selected stations
- Calendar integration - Schedule reminders for regular refueling
- Vehicle integration - Sync with vehicle telematics for automatic consumption data
Contributions implementing these features are welcome! See CONTRIBUTING.md for guidelines.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Data provided by the UK Government Fuel Finder service
- API documentation: developer.fuel-finder.service.gov.uk
- Content available under Open Government Licence v3.0
Support
- Issues: GitHub Issues
- API Support: Contact Fuel Finder Team
Changelog
See CHANGELOG.md for version history.
Release Procedure
To create a new release:
-
Update version in all files:
pyproject.tomlsetup.pyukfuelfinder/__init__.py
-
Update CHANGELOG.md with new version entry
-
Commit and push version updates:
git add pyproject.toml setup.py ukfuelfinder/__init__.py CHANGELOG.md git commit -m "Release: vX.Y.Z" git push origin main
-
Create GitHub release:
- Go to GitHub repository → Releases → Create new release
- Tag:
vX.Y.Z(must match version in files) - Title:
vX.Y.Z - Description: Copy from CHANGELOG.md for the version
- Publish release
-
Automated publishing:
- GitHub Actions will automatically build and publish to PyPI
- Check
.github/workflows/publish.ymlfor details
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
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 ukfuelfinder-3.0.0.tar.gz.
File metadata
- Download URL: ukfuelfinder-3.0.0.tar.gz
- Upload date:
- Size: 76.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b4fe05f6cef92af8ec732f99799db795841fc139b05557b5bac4198dfc0ba71
|
|
| MD5 |
5481d1f38280448920f1fa379d3e80f9
|
|
| BLAKE2b-256 |
2fdf0d34680e8df2f0794cea459577be7e2c649cc35d72f21f801d2889384b7f
|
Provenance
The following attestation bundles were made for ukfuelfinder-3.0.0.tar.gz:
Publisher:
publish.yml on mretallack/ukfuelfinder
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ukfuelfinder-3.0.0.tar.gz -
Subject digest:
9b4fe05f6cef92af8ec732f99799db795841fc139b05557b5bac4198dfc0ba71 - Sigstore transparency entry: 992230390
- Sigstore integration time:
-
Permalink:
mretallack/ukfuelfinder@9e7c3495196012a911a97e4a81b0b2310db2b340 -
Branch / Tag:
refs/tags/v3.0.0 - Owner: https://github.com/mretallack
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9e7c3495196012a911a97e4a81b0b2310db2b340 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ukfuelfinder-3.0.0-py3-none-any.whl.
File metadata
- Download URL: ukfuelfinder-3.0.0-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa6a1760de7c4dc182f4a8b3b3e8321eb5a3db53651cbdbea1551488ce57c643
|
|
| MD5 |
dce88568d21da5aa1e8ee65b3ed81b12
|
|
| BLAKE2b-256 |
c8d75abe05ed19a0c24bdc589fc56a92e390fafc998d95a17d9ea8533725d814
|
Provenance
The following attestation bundles were made for ukfuelfinder-3.0.0-py3-none-any.whl:
Publisher:
publish.yml on mretallack/ukfuelfinder
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ukfuelfinder-3.0.0-py3-none-any.whl -
Subject digest:
aa6a1760de7c4dc182f4a8b3b3e8321eb5a3db53651cbdbea1551488ce57c643 - Sigstore transparency entry: 992230392
- Sigstore integration time:
-
Permalink:
mretallack/ukfuelfinder@9e7c3495196012a911a97e4a81b0b2310db2b340 -
Branch / Tag:
refs/tags/v3.0.0 - Owner: https://github.com/mretallack
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9e7c3495196012a911a97e4a81b0b2310db2b340 -
Trigger Event:
release
-
Statement type: