Skip to main content
    ______           __               __       __
   / ____/_  _____  / /      ______ _/ /______/ /_  ___  _____
  / /_  / / / / _ \/ / | /| / / __ `/ __/ ___/ __ \/ _ \/ ___/
 / __/ / /_/ /  __/ /| |/ |/ / /_/ / /_/ /__/ / / /  __/ /
/_/    \__,_/\___/_/ |__/|__/\__,_/\__/\___/_/ /_/\___/_/

Fuelwatcher

A simple python module that scrapes XML data from the government of Western Australia's FuelWatch website that makes parsing a breeze.

Fuelwatch.wa.gov.au provides information on fuel prices by fuel type, location, brand and region within Western Australia. Fuelwatcher will parse the XML from the fuelwatch.wa.gov.au RSS feed giving the developer an easy way to manipulate the information.

Installation

Requires pip to be installed or pip3 dependent on system, or environment.

pip install fuelwatcher

Usage example

Basic Usage (Recommended)

The recommended way to access fuel station data is via the typed stations property, which returns a list of FuelStation dataclass instances:

from fuelwatcher import FuelWatch

api = FuelWatch()

# Query the API
api.query(product=2, region=25, day='yesterday')

# Access stations as typed dataclass instances
for station in api.stations:
    print(f"{station.trading_name}: ${station.price}")
    print(f"  Address: {station.address}")
    print(f"  Location: {station.latitude}, {station.longitude}")

The FuelStation dataclass provides IDE autocomplete and type safety:

from fuelwatcher import FuelStation

# FuelStation fields:
# - title, description, brand, date, price
# - trading_name, location, address, phone
# - latitude, longitude, site_features

Alternative Access Methods

As list of dictionaries:

api = FuelWatch()
api.query(region=1)

# Access as list of dicts
stations = api.xml
print(stations[0]['title'])
>>> '143.9: United Boulder Kalgoorlie'

As JSON string:

api = FuelWatch()
api.query(region=1)

json_response = api.json
>>> [
>>>   {
>>>       "title": "143.9: United Boulder Kalgoorlie",
>>>       "description": "Address: Cnr Lane St & Davis St, BOULDER...",
>>>       "brand": "United",
>>>       ...
>>>   }
>>> ]

Raw XML bytes:

api = FuelWatch()
api.query(product=1)

raw_xml = api.raw
>>> b'<?xml version="1.0" encoding="UTF-8"?>...'

Query Parameters

The query method takes several keyword arguments:

def query(
    product: int = None,      # Fuel type ID
    suburb: str = None,       # WA suburb name
    region: int = None,       # Region ID
    brand: int = None,        # Brand ID
    surrounding: bool = None, # Include surrounding suburbs
    day: str = None,          # 'today', 'tomorrow', 'yesterday', or 'DD/MM/YYYY'
)

A query without any arguments returns all of today's Unleaded stations in Western Australia.

Notes:

  • If suburb is set, surrounding defaults to yes. To get only the suburb, explicitly pass surrounding=False
  • Don't mix region with suburb and surrounding together
  • The surrounding parameter accepts both bool (True/False) and str ('yes'/'no')

A list of valid suburbs, brands, regions and products (fuel types) can be found in constants.py

Error Handling

Fuelwatcher validates inputs and raises FuelWatchError for invalid parameters or failed requests:

from fuelwatcher import FuelWatch, FuelWatchError

api = FuelWatch()

try:
    api.query(product=999)  # Invalid product ID
except FuelWatchError as e:
    print(f"Error: {e}")
>>> Error: Invalid product ID: 999. Valid options: 1: Unleaded Petrol, 2: Premium Unleaded...

Backwards Compatibility

The previous get_* property names are still supported but deprecated:

# Deprecated (still works, emits DeprecationWarning)
api.get_xml    # Use api.xml instead
api.get_json   # Use api.json instead
api.get_raw    # Use api.raw instead

Migration guide:

Old (deprecated) New
api.get_xml api.xml or api.stations
api.get_json api.json
api.get_raw api.raw
AssertionError FuelWatchError
surrounding='yes' surrounding=True

Meta

Daniel Michaels – https://danielms.site

Distributed under the MIT license. See LICENSE for more information.

Contributing

All requests, ideas or improvements are welcomed!

  1. Fork it
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

Inspired by..

A local python meetup group idea that turned into a PyPi package for anyone to use!

Release files for fuelwatcher 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fuelwatcher 1.0.0
File Size Uploaded
fuelwatcher-1.0.0.tar.gz 33.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fuelwatcher 1.0.0
File Interpreter ABI Platform
fuelwatcher-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 44.7 kB

Release files / fuelwatcher-1.0.0.tar.gz

Download URL fuelwatcher-1.0.0.tar.gz
Size 33.7 kB
Tags Source
SHA-256 checksum
How to use checksums
db2527b994158cc0b10ca6fb558df9ea6219526025b7114f9da38ef1fb3c361e
BLAKE2b-256 checksum
How to use checksums
35ff77c3199bf484395086e79b5c9cd6624805b0d1e800cc942bbf24f61bd372
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.20 {"installer":{"name":"uv","version":"0.9.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / fuelwatcher-1.0.0-py3-none-any.whl

Download URL fuelwatcher-1.0.0-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8bfbe50c88928792417612c290cf03c15c22cace1787dd7b92c6e7d9e5ec06ea
BLAKE2b-256 checksum
How to use checksums
161948e1e77d484d9fb59b74a7bc21e60fdb87c653bd7ae34540679d4cdd39ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.20 {"installer":{"name":"uv","version":"0.9.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.21

1 release file

0.2.4

2 release files

0.2.3

2 release files

0.2.2

1 release file

0.2.0

2 release files

0.1.1

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page