Python Package Index

local Python Package Index (PyPI)

corelibs-dump-data (1.1.0)

Published 2026-02-03 15:55:07 +09:00 by clemens

Installation

pip install --index-url  --extra-index-url https://pypi.org/simple corelibs-dump-data

About this package

CoreLibs Dump Data

CoreLibs Python Dump Data

This is part of the Python CoreLibs

Overview

Dump variable data in formatted output

Install

uv add --index opj-pypi=https://git.egplusww.jp/api/packages/PyPI/pypi/simple/ corelibs-dump-data

Usage

The CoreLibs debug support module contains the following

  • corelibs_dump_data.dump_data
  • corelibs_dump_data.dict_mask

corelibs_dump_data.dump_data usage

Formated print of variable values

from corelibs_dump_data.dump_data import dump_data

dump_data

def dump_data(data: Any, use_indent: bool = True) -> str:

Retuns a formatted string for any data, data will be parsed through json dumps.

Note that bad data might throw some json dump exceptions.

Example

from corelibs_debug.dump_data import dump_data

data = {
    "name": "Test",
    "value": 123,
    "items": [1, 2, 3],
    "nested": {"a": 1, "b": 2}
}
print(f"A: {dump_data(data)}")

Example output:

A: {
    "name": "Test",
    "value": 123,
    "items": [
        1,
        2,
        3
    ],
    "nested": {
        "a": 1,
        "b": 2
    }
}

corelibs_dump_data.dict_mask usage

Hide secret information behind masking values

from corelibs_dump_data.dict_mask import mask

mask

[!warning] key names can be various, so be careful with secrets in data structurs dumped to logs

Will try mask and values that start, end or are in key names like "encryption", "password" or "secret". Those values can be defined by the "mask_key" argument, the default values are seen above, and if this argument is set, those are no longer used. If set to an empty list, then nothing is masked, None will trigger default masking.

All checks are done case insenstivie and for keys that start, end or are inside surouned by the "mask_str_edge". Does match keys where the search value is inside.

If we taek "secret" then the following values below will match

  • secret: starts with and ends with match
  • secret1: starts with match
  • test_secret: ends with match
  • test_secret_inside: secret with "_" as edge character matches

Below will not match

  • test.secret.test: not matching "_"

The edge character can be changed with "mask_str_edges" but only for all matches

the "skip" argument ca be used for extra debugging output as is allow

def mask(
    data_set: dict[str, Any],
    mask_keys: list[str] | None = None,
    mask_str: str = "***",
    mask_str_edges: str = '_',
    skip: bool = False
) -> dict[str, Any]:

Example:

from corelibs_dump_data.dict_mask import mask

dict_a = {
    "secret": "match",
    "secret1": "match",
    "1secret": "match",
    "test_secret": "match",
    "secret_test": "match",
    "test.secret": "match",
    "secret.test": "match",
    "test_secret_test": "match",
    "invalid.secret.match": "match"
}
print(f"OUT: {mask(dict_a)}")

Output will be:

{
    "secret": "***",
    "secret1": "***",
    "1secret": "***",
    "test_secret": "***",
    "secret_test": "***",
    "test.secret": "***",
    "secret.test": "***",
    "test_secret_test": "***",
    "invalid.secret.match": "match"
}

Development

UV setup

uv must be installed

Python venv setup

After clone, run the command below to install all dependenciss

uv sync

Build and Publish

uv build
uv publish --index opj-pypi --token <gitea token>

Python tests

All python tests are the tests/ folder. They are structured by the source folder layout

run them with

uv run pytest

Get a coverate report

uv run pytest --cov=<project>
uv run pytest --cov=<project> --cov-report=term-missing

Other tests

In the test-run folder usage and run tests are located, runt them below

uv run test-run/<script>

Requirements

Requires Python: >=3.13
Details
PyPI
2026-02-03 15:55:07 +09:00
0
Clemens Schwaighofer
8.4 KiB
Assets (2)
Versions (4) View all
1.3.0 2026-02-03
1.2.0 2026-02-03
1.1.0 2026-02-03
1.0.0 2026-02-02