Skip to main content

Python library for accessing the UK Government Fuel Finder API

Project description

UK Fuel Finder Python Library

License: MIT Python 3.8+

Python library for accessing the UK Government Fuel Finder API.

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

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 example
  • error_handling.py - Comprehensive error handling
  • fetch_fuel_prices.py - Fetch all fuel prices and save to JSON
  • fetch_all_sites.py - Fetch all forecourt sites and save to JSON
  • location_search.py - Search for stations near a location

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

Support

Changelog

See CHANGELOG.md for version history.

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

ukfuelfinder-1.0.0.tar.gz (48.2 kB view details)

Uploaded Source

Built Distribution

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

ukfuelfinder-1.0.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file ukfuelfinder-1.0.0.tar.gz.

File metadata

  • Download URL: ukfuelfinder-1.0.0.tar.gz
  • Upload date:
  • Size: 48.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ukfuelfinder-1.0.0.tar.gz
Algorithm Hash digest
SHA256 208e786741d976ec5ddecb41bd6866f80f4cad3a455543d1ca0536adacaa64a5
MD5 0146a67b21d01b467a61b5e1a355e6d1
BLAKE2b-256 7f049457a373979d05806248fd7dd25a70dcc093e7d1ca9f2295144f4dae1db6

See more details on using hashes here.

Provenance

The following attestation bundles were made for ukfuelfinder-1.0.0.tar.gz:

Publisher: publish.yml on mretallack/ukfuelfinder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: ukfuelfinder-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ukfuelfinder-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa1b0163b3cfcb45560a943bb8ec292e2d4f3c81f66e3e7b28732d6df6915984
MD5 89b7101c6be786ca0fad8abc81ad0f8c
BLAKE2b-256 a456f94388e28ba46c8c0d9f3ec3c50356ee888aa01961ea372ab8f8b79b9adb

See more details on using hashes here.

Provenance

The following attestation bundles were made for ukfuelfinder-1.0.0-py3-none-any.whl:

Publisher: publish.yml on mretallack/ukfuelfinder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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