Skip to main content

Excel 脱敏工具 - 对 xls/xlsx 文件中的个人敏感信息进行替换或重构脱敏

Project description

Tuomin - Excel 脱敏工具

命令行工具,对 xls/xlsx 文件中的个人敏感信息进行脱敏处理。

安装

uv tool install tuomin

Python >= 3.8

也可使用 pip install tuomin

开发

git clone https://github.com/annopick/tuomin.git
cd tuomin
uv sync

用法

tuomin <input_file> --col <列字母>:<字段类型>:<脱敏方式> [--col ...] [选项]

参数

参数 说明
input_file 输入的 xls/xlsx 文件路径
--sheet Sheet 名称或索引(从 0 开始),默认第一个 Sheet
--col 指定脱敏列,格式 列字母:字段类型:脱敏方式,可多次使用
--output 输出文件路径,默认在同目录生成 _masked.xlsx 后缀文件

字段类型

标识 说明
name 姓名
phone 手机号
idcard 身份证号
email 邮箱
bankcard 银行卡号
address 地址

脱敏方式

标识 说明
replace * 替换敏感部分,保留部分原文特征
reconstruct 生成与现实无关的假数据

示例

替换单列手机号:

tuomin data.xlsx --col C:phone:replace

重构多列:

tuomin data.xls --col B:name:reconstruct --col D:idcard:reconstruct --output result.xlsx

指定 Sheet + 混合脱敏:

tuomin data.xlsx --sheet 员工信息 --col B:name:replace --col C:phone:reconstruct --col E:email:replace

替换规则

字段类型 保留规则 示例
姓名 保留姓,名用 * 张三丰 → 张**
手机号 保留前 3 后 4 13812341234 → 138****1234
身份证号 保留前 3 后 4 310101199001011234 → 310***********1234
邮箱 首字符 + * + 域名 zhangsan@qq.comz*******@qq.com
银行卡号 保留前 4 后 4 6222021234565678 → 6222********5678
地址 保留到区/县 上海市浦东新区张江路88号 → 上海市浦东新区******

重构规则

生成的假数据不可能对应任何真实信息:

字段类型 生成规则 示例
姓名 姓氏 + 中文数字 张三四
手机号 110 开头(报警号段) 11056781234
身份证号 999 开头(不存在的地区码) 999999199901019923
邮箱 @notexist.invalid a3k9x@notexist.invalid
银行卡号 0000 开头(不存在的 BIN) 0000123456781234
地址 虚构路 + 数字号 广东省深圳市虚构路999号

特性

  • 一致性 — 同一原文在同一列中始终映射到相同结果
  • 叠加重构 — 对已包含 * 的替换数据可再次重构
  • 空值/非标准值 — 原样保留,不报错
  • 编码兼容 — 自动处理 xls GBK 编码和控制台输出编码
  • 安全 — 永不覆盖原文件,始终生成新文件
  • 格式统一 — 输出始终为 xlsx

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

tuomin-0.1.3.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

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

tuomin-0.1.3-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file tuomin-0.1.3.tar.gz.

File metadata

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

File hashes

Hashes for tuomin-0.1.3.tar.gz
Algorithm Hash digest
SHA256 062b093ac21c2497b309b4162b797693447146ccbd3113891bb518390d2fc20b
MD5 75eb9a9c6101e5442c7faec50c392579
BLAKE2b-256 f459c16e7140dafc109c29b206769300eedd8ae4fdc68cae988f215ed8f6ec37

See more details on using hashes here.

Provenance

The following attestation bundles were made for tuomin-0.1.3.tar.gz:

Publisher: ci.yml on annopick/tuomin

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

File details

Details for the file tuomin-0.1.3-py3-none-any.whl.

File metadata

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

File hashes

Hashes for tuomin-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a6272b5f5494ab4add5e89c3403005f23369f6ce0a50f2e2d2e4e72f59b232b3
MD5 b60de74b517f380adab075fd846fa707
BLAKE2b-256 af2675382f1f8ce72d743e49ae7a3d34b4e82458cbc731202ad7693907db9127

See more details on using hashes here.

Provenance

The following attestation bundles were made for tuomin-0.1.3-py3-none-any.whl:

Publisher: ci.yml on annopick/tuomin

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