Skip to main content

Python client for the Fuelog fuel tracking API — REST and MCP.

Project description

fuelog-python

CI codecov PyPI version Python versions Docs License: MIT

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:

  1. Create a Trusted Publisher on pypi.org/manage/account/publishing/ pointing to this repository.
  2. Tag a release: git tag vX.Y.Z && git push --tags.
  3. Create a GitHub Release from the tag — the publish.yml workflow triggers automatically.

License

MIT

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

fuelog-1.1.1.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

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

fuelog-1.1.1-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file fuelog-1.1.1.tar.gz.

File metadata

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

File hashes

Hashes for fuelog-1.1.1.tar.gz
Algorithm Hash digest
SHA256 5bceba6a5f7069e0472e144652a4142f3c77101a40744b23675ae47c4343c1c5
MD5 ea715280b9b6349992ca238d218d0879
BLAKE2b-256 82f7c014925b655a5a52c2f0823e536e0198aa2607df9141bf14321bac19a98b

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuelog-1.1.1.tar.gz:

Publisher: publish.yml on Irishsmurf/fuelog-python

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

File details

Details for the file fuelog-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: fuelog-1.1.1-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

Hashes for fuelog-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 163e97fb83a321189b204baef8880a5a47911d8ead692288fd81be06ee110607
MD5 10fdaf703e10d7f228a6e480de6b009f
BLAKE2b-256 ddc9b656ae11d6f5a06bdae794d305963f2789e146413659a69fc84b5bc3efc5

See more details on using hashes here.

Provenance

The following attestation bundles were made for fuelog-1.1.1-py3-none-any.whl:

Publisher: publish.yml on Irishsmurf/fuelog-python

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