Skip to main content

Python client for Energy Tracker API - focused on meter reading operations

Project description

Energy Tracker API Client

Python client for the Energy Tracker public REST API.

Installation

pip install energy-tracker-api

Requirements

  • Python 3.10+
  • Personal Access Token from Energy Tracker

Usage

from energy_tracker_api import EnergyTrackerClient, CreateMeterReadingDto
from datetime import datetime

client = EnergyTrackerClient(access_token="your-token")

meter_reading = CreateMeterReadingDto(
    value=123.45,
    timestamp=datetime.now(),     # Optional - server uses current time if omitted
    note="Manual reading"         # Optional
)

client.meter_readings.create(
    device_id="your-device-id",
    meter_reading=meter_reading,
    allow_rounding=True           # Optional
)

Context Manager

with EnergyTrackerClient(access_token="your-token") as client:
    reading = CreateMeterReadingDto(value=456.78)
    client.meter_readings.create("your-device-id", reading)

Configuration

client = EnergyTrackerClient(
    access_token="your-token",
    base_url="https://custom-api.example.com",  # Optional
    timeout=30                                  # Optional, default: 10 seconds
)

Error Handling

from energy_tracker_api import (
    EnergyTrackerAPIError,
    ValidationError,
    AuthenticationError,
    ForbiddenError,
    ResourceNotFoundError,
    ConflictError,
    RateLimitError
)

try:
    client.meter_readings.create(device_id, meter_reading)
except ValidationError as e:
    print(f"Validation error: {e}")
    print(f"Details: {e.api_message}")
except AuthenticationError:
    print("Authentication failed - check access token")
except ForbiddenError:
    print("Insufficient permissions")
except ResourceNotFoundError:
    print("No valid meter for timestamp")
except ConflictError:
    print("Meter reading already exists for timestamp")
except RateLimitError as e:
    print(f"Rate limit exceeded")
    if e.retry_after:
        print(f"Retry after {e.retry_after} seconds")
except EnergyTrackerAPIError as e:
    print(f"API error: {e}")

API Reference

EnergyTrackerClient

__init__(access_token, base_url=None, timeout=10)

  • access_token (str): Personal Access Token
  • base_url (str, optional): API base URL
  • timeout (int, optional): Request timeout in seconds

MeterReadingResource

meter_readings.create(device_id, meter_reading, allow_rounding=None)

Create a new meter reading.

  • device_id (str): Device identifier
  • meter_reading (CreateMeterReadingDto): Meter reading data
  • allow_rounding (bool, optional): Allow rounding to meter precision

CreateMeterReadingDto

CreateMeterReadingDto(value, timestamp=None, note=None)

  • value (float): Meter reading value
  • timestamp (datetime, optional): Reading timestamp (server uses current time if omitted)
  • note (str, optional): Note for the meter reading

Development

make install-dev  # Install dependencies
make test         # Run tests
make format       # Format code
make lint         # Run linters

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

energy_tracker_api-0.1.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

energy_tracker_api-0.1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file energy_tracker_api-0.1.0.tar.gz.

File metadata

  • Download URL: energy_tracker_api-0.1.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for energy_tracker_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8bd752bdea6b18d3e0cc134832874e0f50af1d95bc746200aa256250bdcbe625
MD5 b521bb222995aec7a81f1ab43fe53467
BLAKE2b-256 b8c501ac0913b9afca08d406ca1c32d47438de3c5b26e0b72ca4eaa791fa6900

See more details on using hashes here.

File details

Details for the file energy_tracker_api-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for energy_tracker_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2947a7a310d7d8caf05af4974f0a7b7307237bc17b95db185a0165ba6e6c5f05
MD5 eab4ceb84146c455e069e05dd0896bd1
BLAKE2b-256 5102bc38f0de070cd849dba1c31483fc54690734c51db82b4db5211eac9d0419

See more details on using hashes here.

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