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
  • JSON export — machine-friendly structured output for pipelines and dashboards
  • 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

# Export JSON report
ocpp-lens charger.log --json report.json

# Quiet mode (no terminal output)
ocpp-lens charger.log --html report.html --json report.json --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.2.0.tar.gz (18.9 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.2.0-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ocpp_lens-0.2.0.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ocpp_lens-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6a1a5ad435c2ef6dc0a2db17bb99070ed24da7d20f2e9190385a11ba37e34edb
MD5 5083886ff83838dcf693871909a11647
BLAKE2b-256 4a45049d0ba5df099742b64d80ea33e3a8f787700c9866fca74aa5ce6eae3e65

See more details on using hashes here.

Provenance

The following attestation bundles were made for ocpp_lens-0.2.0.tar.gz:

Publisher: publish-pypi.yml on sahilsandhu-spec/ocpp_analyser

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

File details

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

File metadata

  • Download URL: ocpp_lens-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ocpp_lens-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b7fcfc79eeb51d5442c75b84c8fb36a399cf4e6b2a4930248a64774e24940867
MD5 896afecac04587482f60d27f6c385377
BLAKE2b-256 20e6667127fc7b88ae731fad268e5cabfee96456009ca02b00b943de94a7a062

See more details on using hashes here.

Provenance

The following attestation bundles were made for ocpp_lens-0.2.0-py3-none-any.whl:

Publisher: publish-pypi.yml on sahilsandhu-spec/ocpp_analyser

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