Skip to main content

Parse and analyze OCPP 1.6 EV charger log files — sessions, faults, and reports.

Project description

⚡ ocpp-lens

Parse and analyze OCPP 1.6 EV charger log files in Python.

ocpp-lens turns raw OCPP 1.6 JSON logs into structured charging sessions, fault events, and readable reports — with zero dependencies.

from ocpp_lens import OCPPLogParser, OCPPAnalyzer, OCPPReporter

messages = OCPPLogParser().parse_file("charger.log")
result   = OCPPAnalyzer().analyze(messages)

print(result.total_sessions)       # 42
print(result.total_energy_kwh)     # 318.5
print(result.critical_faults)      # [FaultEvent(...), ...]

OCPPReporter().to_html(result, "report.html")

Features

  • Multi-format parser — handles newline-delimited JSON, JSON arrays, timestamp-prefixed lines, and wrapped-object formats
  • Session reconstruction — pairs StartTransaction / StopTransaction messages to compute energy, duration, avg power, and stop reason
  • Fault detection — extracts StatusNotification errors, Faulted / Unavailable states, and CALLERROR frames
  • Charger identity — reads vendor, model, serial number, and firmware version from BootNotification
  • HTML report — self-contained dark-theme report you can open in any browser
  • CSV export — sessions and faults as comma-separated values
  • CLI tool — analyze logs directly from the terminal
  • Zero dependencies — pure Python standard library

Installation

pip install ocpp-lens

For local development:

pip install -e ".[dev]"

Quick Start

Python API

from ocpp_lens import OCPPLogParser, OCPPAnalyzer, OCPPReporter

# 1. Parse the log file
parser   = OCPPLogParser()
messages = parser.parse_file("charger.log")

# 2. Analyze
result = OCPPAnalyzer().analyze(messages)

# 3. Explore
print(f"Charger  : {result.charger_vendor} {result.charger_model}")
print(f"Sessions : {result.total_sessions}")
print(f"Energy   : {result.total_energy_kwh} kWh")
print(f"Faults   : {result.total_faults}")

for session in result.sessions:
    print(session)

for fault in result.faults:
    print(fault)

# 4. Export
reporter = OCPPReporter()
reporter.to_html(result, "report.html")
reporter.to_csv(result, "report.csv")

Command-Line Interface

# Print summary
ocpp-lens charger.log

# Export HTML + CSV reports
ocpp-lens charger.log --html report.html --csv sessions.csv

# Quiet mode (no terminal output)
ocpp-lens charger.log --html report.html --quiet

Supported Log Formats

ocpp-lens auto-detects the format — no configuration needed.

Format 1 — Newline-delimited JSON (most common):

[2,"msg1","BootNotification",{"chargePointModel":"EVC-001"}]
[3,"msg1",{"status":"Accepted","currentTime":"2024-01-01T10:00:00Z","interval":300}]

Format 2 — JSON array:

[[2,"msg1","Heartbeat",{}],[3,"msg1",{"currentTime":"2024-01-01T10:00:00Z"}]]

Format 3 — Timestamp prefix (ISO 8601 or Unix):

2024-01-01T10:00:00.000Z [2,"msg1","Heartbeat",{}]
1704067200.123 [3,"msg1",{}]

Format 4 — Wrapped objects:

{"timestamp":"2024-01-01T10:00:00Z","message":[2,"msg1","Heartbeat",{}]}

Data Models

ChargingSession

Property Type Description
transaction_id int OCPP transaction ID
connector_id int Connector number
id_tag str RFID / ID tag used
start_time datetime Session start (UTC)
stop_time datetime | None Session stop (UTC), None if ongoing
energy_kwh float | None Energy delivered (kWh)
duration_minutes float | None Session duration (minutes)
avg_power_kw float | None Average charging power (kW)
stop_reason str | None OCPP stop reason
is_complete bool True if a matching StopTransaction was found

FaultEvent

Property Type Description
timestamp datetime | None Fault timestamp (UTC)
connector_id int Affected connector
error_code str OCPP 1.6 error code
status str Connector status at fault time
info str | None Additional info string
is_critical bool True for hardware-level faults

AnalysisResult

Property Type Description
sessions list[ChargingSession] All sessions (complete + ongoing)
faults list[FaultEvent] All fault events
call_errors list[OCPPMessage] All CALLERROR frames
total_energy_kwh float Sum of all delivered energy
critical_faults list[FaultEvent] Hardware-level faults only
charger_vendor str | None From BootNotification
charger_model str | None From BootNotification
log_start / log_end datetime | None Time range of the log

Running Tests

pytest tests/ -v

Project Structure

ocpp-lens/
├── ocpp_lens/
│   ├── __init__.py
│   ├── models.py
│   ├── parser.py
│   ├── analyzer.py
│   ├── reporter.py
│   └── cli.py
├── tests/
├── examples/
├── pyproject.toml
├── README.md
└── LICENSE

Publish To PyPI

# Build source + wheel
python -m build

# Validate package metadata
twine check dist/*

# Upload to TestPyPI first (recommended)
twine upload --repository testpypi dist/*

# Upload to PyPI
twine upload dist/*

License

MIT © Sahil Sandhu

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

ocpp_lens-0.1.0.tar.gz (18.1 kB view details)

Uploaded Source

Built Distribution

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

ocpp_lens-0.1.0-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ocpp_lens-0.1.0.tar.gz
  • Upload date:
  • Size: 18.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for ocpp_lens-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cb3bdcea6eb317c6072b697a2a3904407960d79150e57ec246ebbc538c72e69e
MD5 bd4e5c8d7f042be9bdf02dc19a78ae66
BLAKE2b-256 75545405de39f0cd8a397f439f6f7ca3fb70235f9a010f1fd5ff05fcf45cd3ad

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ocpp_lens-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for ocpp_lens-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 22d638c50a28bea02e510f90d1a469b39f7fb014a2a4ff80770cc7183f274cf6
MD5 84743841d5b972014363f36f87e12061
BLAKE2b-256 89d2c5a08ac2eb09b7ff099e3359c9c35d787614ebe2b14bc60bc3c064aef2f1

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