Skip to main content

OCPP-Anonymizer: Deterministic PII Redaction

PyPI version

A Python library for anonymizing OCPP log files while preserving the ability to trace sessions and identify unique devices.

The Problem

OCPP (Open Charge Point Protocol) logs are essential for debugging EV charging issues, but they often contain Personally Identifiable Information (PII) and other sensitive data. This includes:

  • idTag: A user's unique identifier (e.g., RFID card number).
  • Hardware Identifiers: chargeBoxSerialNumber, iccid, imsi, etc.
  • Transaction Data: transactionId which links charging sessions.

Exposing this data can lead to privacy violations and security risks, making it difficult to share logs with developers or third parties.

The Solution

This library redacts sensitive information by replacing it with a deterministic SHA256 hash. This means:

  • Anonymity: The original value cannot be reverse-engineered.
  • Traceability: The same input value (e.g., the same idTag) will always produce the same hash token. This allows you to track a user's activity across multiple log lines without knowing their actual identity.

The library also handles special cases like masking credentials in URLs and redacting AuthorizationKey values.

Installation

pip install ocpp-anonymizer

Usage

You can use the library in two primary ways:

1. Processing a Raw Log Line

If you have raw log files in the format CP_ID : direction [JSON_PAYLOAD], you can process them line by line.

from ocpp_anonymizer import process_log_line

raw_log = 'CP123 : receive [2, "12345", "StartTransaction", {"idTag": "USER1", "meterStart": 100}]'

anonymized_log = process_log_line(raw_log)

# The output will have the CP_ID and idTag hashed
print(anonymized_log)
# e.g., 'a1b2c3d4e5f6a7b8 : receive message [2, "12345", "StartTransaction", {"idTag": "f242c797e74b89bb", "meterStart": 100}]'

2. Anonymizing a Structured JSON Payload

If you have already parsed the JSON part of an OCPP message, you can anonymize the payload directly.

from ocpp_anonymizer import anonymize_payload

action = "StartTransaction"
payload = {"idTag": "USER1", "meterStart": 100}

anonymized_payload = anonymize_payload(action, payload)

print(anonymized_payload)
# {'idTag': 'f242c797e74b89bb', 'meterStart': 100}

Configuration

IMPORTANT: Set the Secret Salt

The library uses a deterministic hashing algorithm, which requires a secret salt. For security, it is crucial to use a unique, randomly generated salt in your environment.

You should set the OCPP_ANONYMIZER_SECRET_SALT environment variable to a long, random string.

Example:

export OCPP_ANONYMIZER_SECRET_SALT="a_very_long_and_random_secret_string_12345"

If this environment variable is not set, the library will use a default, insecure salt and print a UserWarning.

Running Tests

To run the tests, first install the package in editable mode:

pip install -e .

Then, run the tests using the following command:

OCPP_ANONYMIZER_SECRET_SALT="test_salt" python3 -m unittest discover tests

Contributing

Contributions are welcome! If you find a sensitive field that is not yet mapped in ocpp_anonymizer/mapping.py, please open an issue or submit a pull request.

Metadata

Release files for ocpp-anonymizer 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ocpp-anonymizer 0.1.0
File Size Uploaded
ocpp_anonymizer-0.1.0.tar.gz 10.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ocpp-anonymizer 0.1.0
File Interpreter ABI Platform
ocpp_anonymizer-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.7 kB

Release files / ocpp_anonymizer-0.1.0.tar.gz

Download URL ocpp_anonymizer-0.1.0.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
88723e928c82b863eee28ab94d746816df8754a36947c88314b6153994ae2562
BLAKE2b-256 checksum
How to use checksums
32241c148790023b55bbd931a3e76149bb09f7bf64afdcf0797496f20dba0425
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2025.

Transparency log

Release files / ocpp_anonymizer-0.1.0-py3-none-any.whl

Download URL ocpp_anonymizer-0.1.0-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb8c8d2bd8aee3a327b9fe8355c04d28a5e04101b09ce930d6a36f5d0dc3e370
BLAKE2b-256 checksum
How to use checksums
87aa5161f8ed7069fb682c1689936579aaca60cf7f2cf4e7a64fb80665467c57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page