Python client for the Fuelog fuel tracking API — REST and MCP.
Project description
fuelog-python
Official Python client library for the Fuelog API.
Covers the full REST API and the MCP (Model Context Protocol) server — with zero third-party dependencies, typed models, and a comprehensive test suite.
Installation
pip install fuelog
Requires Python 3.9+. No external dependencies.
Quick Start
REST Client
from fuelog import FuelogClient, CreateFuelLogRequest, CreateVehicleRequest, FuelType
client = FuelogClient(token="your_bearer_token")
# ── Logs ───────────────────────────────────────────────────────────────────
# List the 20 most recent fill-ups
logs = client.list_logs(limit=20)
for log in logs:
print(f"{log.timestamp} {log.brand} €{log.cost} {log.distance_km} km")
# Create a new fill-up
new_id = client.create_log(
CreateFuelLogRequest(
brand="Shell",
cost=50.00,
distance_km=400.0,
fuel_amount_liters=35.0,
vehicle_id="vehicle-abc",
)
)
print(f"Created log: {new_id}")
# Update a log
from fuelog import UpdateFuelLogRequest
client.update_log(new_id, UpdateFuelLogRequest(brand="Shell Express", cost=51.00))
# Delete a log
client.delete_log(new_id)
# ── Vehicles ───────────────────────────────────────────────────────────────
vehicles = client.list_vehicles()
vehicle_id = client.create_vehicle(
CreateVehicleRequest(
name="My Corolla",
make="Toyota",
model="Corolla",
year="2022",
fuel_type=FuelType.PETROL,
is_default=True,
)
)
from fuelog import UpdateVehicleRequest
client.update_vehicle(vehicle_id, UpdateVehicleRequest(name="Daily Driver"))
client.delete_vehicle(vehicle_id)
# Include archived vehicles
all_vehicles = client.list_vehicles(include_archived=True)
# ── Analytics ──────────────────────────────────────────────────────────────
stats = client.get_analytics(
vehicle_id="vehicle-abc",
start_date="2025-01-01",
end_date="2025-12-31",
)
print(f"Avg efficiency: {stats.efficiency} km/L")
print(f"Total spent: {stats.home_currency} {stats.total_spent}")
MCP Client
The MCP client wraps all tools, resources, and prompts registered on the
/api/mcp endpoint.
from fuelog import FuelogMCPClient, FuelType, TrendMetric, CostOptimizationPeriod
mcp = FuelogMCPClient(token="your_bearer_token")
# ── Tools ──────────────────────────────────────────────────────────────────
# List logs (with optional filters)
result = mcp.list_logs(limit=10, brand="Shell")
print(result.text)
# Log a fill-up
result = mcp.log_fuel(
brand="BP",
cost=45.0,
distance_km=300.0,
fuel_amount_liters=28.0,
vehicle_id="v1",
)
# Edit and delete
mcp.edit_fuel_log("log-id", cost=46.0)
mcp.delete_fuel_log("log-id") # confirm=True added automatically
# Vehicles
mcp.add_vehicle(name="EV", make="Tesla", model="Model 3", year="2024",
fuel_type=FuelType.ELECTRIC, is_default=True)
mcp.update_vehicle("v1", is_archived=True)
# Analytics
result = mcp.get_analytics(vehicle_id="v1")
result = mcp.compare_vehicles(vehicle_ids=["v1", "v2"])
# ── Resources ──────────────────────────────────────────────────────────────
summary = mcp.get_analytics_summary_resource()
monthly = mcp.get_analytics_monthly_resource()
profile = mcp.get_profile_resource()
# By ID
log_data = mcp.get_log_resource("log-123")
vehicle_data = mcp.get_vehicle_resource("v-abc")
# Raw URI access
data = mcp.read_resource("fuelog://analytics/vehicles")
# ── Prompts ────────────────────────────────────────────────────────────────
# Monthly report for March 2025
prompt = mcp.monthly_report(month="2025-03")
for msg in prompt.messages:
print(f"[{msg.role}]", msg.content.get("text", ""))
# Trend analysis
prompt = mcp.trend_analysis(
start_date="2025-01-01",
end_date="2025-12-31",
metric=TrendMetric.KML,
)
# Cost optimisation suggestions
prompt = mcp.cost_optimization(period=CostOptimizationPeriod.LAST_QUARTER)
Error Handling
All errors derive from FuelogError:
| Exception | When it's raised |
|---|---|
FuelogAuthError |
401 Unauthorized — invalid or missing token |
FuelogForbiddenError |
403 Forbidden — token lacks the required scope |
FuelogNotFoundError |
404 Not Found — resource doesn't exist |
FuelogValidationError |
422 Unprocessable — bad request body |
FuelogRateLimitError |
429 Too Many Requests |
FuelogServerError |
5xx server-side error |
FuelogAPIError |
Any other HTTP error (base class for the above) |
FuelogMCPError |
JSON-RPC error from the MCP server |
from fuelog import FuelogClient, FuelogNotFoundError, FuelogForbiddenError
client = FuelogClient(token="sk-...")
try:
client.delete_log("non-existent-id")
except FuelogNotFoundError:
print("Log not found")
except FuelogForbiddenError as e:
print(f"Permission denied: {e}")
Configuration
client = FuelogClient(
token="your_token",
base_url="https://api.fuelog.app", # default
timeout=30, # seconds, default
)
Development
# Clone and install in editable mode with dev dependencies
git clone https://github.com/Irishsmurf/fuelog-python.git
cd fuelog-python
pip install -e ".[dev]"
# Run the test suite with coverage
pytest --cov=fuelog --cov-report=term-missing
# Lint
ruff check fuelog/ tests/
# Type check
mypy fuelog/
# Build for release
pip install hatch
hatch build
Publishing to PyPI
Releases are published automatically via GitHub Actions when a GitHub Release is created. The workflow uses OIDC Trusted Publishing — no PyPI API token is stored in repository secrets.
To set up a new repo:
- Create a Trusted Publisher on pypi.org/manage/account/publishing/ pointing to this repository.
- Tag a release:
git tag vX.Y.Z && git push --tags. - Create a GitHub Release from the tag — the
publish.ymlworkflow triggers automatically.
License
Project details
Release history Release notifications | RSS feed
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 fuelog-1.1.0.tar.gz.
File metadata
- Download URL: fuelog-1.1.0.tar.gz
- Upload date:
- Size: 23.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32779cf406419477fdfa6d1768a7184580b037a29a0f37ab39b143c8d3a94a0e
|
|
| MD5 |
6f1608f80c567b478822d8ff63bcae80
|
|
| BLAKE2b-256 |
2b97110eb444add5585df4cdd068acb52d0a417024a834c9d4a46f8807ee8050
|
Provenance
The following attestation bundles were made for fuelog-1.1.0.tar.gz:
Publisher:
publish.yml on Irishsmurf/fuelog-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fuelog-1.1.0.tar.gz -
Subject digest:
32779cf406419477fdfa6d1768a7184580b037a29a0f37ab39b143c8d3a94a0e - Sigstore transparency entry: 1065511295
- Sigstore integration time:
-
Permalink:
Irishsmurf/fuelog-python@78fff19fbbdef0ffd3901d622a5545e0763af9d4 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/Irishsmurf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@78fff19fbbdef0ffd3901d622a5545e0763af9d4 -
Trigger Event:
release
-
Statement type:
File details
Details for the file fuelog-1.1.0-py3-none-any.whl.
File metadata
- Download URL: fuelog-1.1.0-py3-none-any.whl
- Upload date:
- Size: 15.4 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 |
777db555c912bce30d3537150650fc6f0885fcd5aab3ef4cd8640ce43210390a
|
|
| MD5 |
c82ed09b7ddcaf70aa9edf052d5e2bc3
|
|
| BLAKE2b-256 |
1411300c03d1961a5bf7933de51ebe9012f6e542899d0826fd7ab19f606fcbf0
|
Provenance
The following attestation bundles were made for fuelog-1.1.0-py3-none-any.whl:
Publisher:
publish.yml on Irishsmurf/fuelog-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fuelog-1.1.0-py3-none-any.whl -
Subject digest:
777db555c912bce30d3537150650fc6f0885fcd5aab3ef4cd8640ce43210390a - Sigstore transparency entry: 1065511298
- Sigstore integration time:
-
Permalink:
Irishsmurf/fuelog-python@78fff19fbbdef0ffd3901d622a5545e0763af9d4 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/Irishsmurf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@78fff19fbbdef0ffd3901d622a5545e0763af9d4 -
Trigger Event:
release
-
Statement type: