Skip to main content

redacted-py

Redacting classified documents

GitHub tag (latest by date) GitHub last commit GitHub issues GitHub license PyPI - Version

This repository holds the code base for my redacted-py library in Python.
It is mainly based off my Feistel cipher for Format-Preserving Encryption to which I added a few tools to handle document, database and file manipulation to ease out the operation.

Motivation

In some fields (like healthcare for instance), protecting the privacy of data whilst being able to conduct in-depth studies is both vital and mandatory. Redacting documents and databases is therefore the obligatory passage. With redacted-py, I provide a simple yet secure tool to help redacting documents based on either a dictionary, a record layout or a tag to decide which parts should actually be redacted.

Usage

You can use either a dictionary or a tag (or both) to identify the words you want to redact in a document. The tag should be placed before any word that should be redacted. The default tag is the tilde character (~).

For example, the following sentence will only see the word tagged redacted: "This is a ~tagged sentence".

$ pip install redacted-py
from redacted import DefaultRedactor, Dictionary
from feistel import FPECipher, SHA_256

source = "Some text ~tagged or using words in a dictionary"

cipher = FPECipher(SHA_256, key, 10)
redactor = DefaultRedactor(cipher)
redacted = redactor.redact(source)

expanded = redactor.expand(redacted)
assert expanded == source, "Original data should equal ciphered then deciphered data"

cleansed = redactor.clean(expanded)
assert cleansed == "Some text tagged or using words in a dictionary", "Cleaning should remove any tag mark"

You may also use it in the console with the following command line instructions:

usage: python3 -m redacted [-h] [-b | --both | --no-both] [-d DICTIONARY] [-H HASH] [-i INPUT] [-k KEY] [-o OUTPUT] [-r ROUNDS] [-t TAG] [-x | --expand | --no-expand]

options:
  -h, --help            show this help message and exit
  -b, --both, --no-both
                        Add to use both dictionary and tag
  -d DICTIONARY, --dictionary DICTIONARY
                        The optional path to the dictionary of words to redact
  -H HASH, --hash HASH  The hash engine for the round function [default sha-256]
  -i INPUT, --input INPUT
                        The path to the document to be redacted
  -k KEY, --key KEY     The optional key for the FPE scheme (leave it empty to use default)
  -o OUTPUT, --output OUTPUT
                        The name of the output file
  -r ROUNDS, --rounds ROUNDS
                        The number of rounds for the Feistel cipher [default 10]
  -t TAG, --tag TAG     The optional tag that prefixes words to redact [default ~]
  -x, --expand, --no-expand
                        Add to expand a redacted document

Tests

$ git clone https://github.com/cyrildever/redacted.git
$ cd redacted/py/
$ pip install -e .
$ python3 -m unittest discover

License

The use of the redacted libraries and executables are subject to fees for commercial purpose and to the respect of the BSD-2-Clause-Patent license.
Please contact me to get further information.

NB: It is still under development so use in production at your own risk for now.


© 2024-2026 Cyril Dever. All rights reserved.

Release files for redacted-py 1.0.14

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

Source distribution (sdist)

Source distribution for redacted-py 1.0.14
File Size Uploaded
redacted_py-1.0.14.tar.gz 9.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for redacted-py 1.0.14
File Interpreter ABI Platform
redacted_py-1.0.14-py3-none-any.whl Python 3 none any Details

Total release size: 17.5 kB

Release files / redacted_py-1.0.14.tar.gz

Download URL redacted_py-1.0.14.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
48a02843bca6bb9df7224c4be70aee5e3d3da9bc68121daf3fcce4168c968dd8
BLAKE2b-256 checksum
How to use checksums
db3c69a2fa8e53309604ce6d7341107ce0486beff7d369fe1618391f24fab674
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.2

Release files / redacted_py-1.0.14-py3-none-any.whl

Download URL redacted_py-1.0.14-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bee930d3c8889ee3196c640eace7640712897cd160b692b2044430f2487da3cf
BLAKE2b-256 checksum
How to use checksums
73f1a05e9a42d481015bcb275506e86e77837d7398a56a6361e4a31d85a8c635
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.2

Release history Release notifications | RSS feed

This release

1.0.14 This release

2 release files

1.0.13

2 release files

1.0.12

2 release files

1.0.11

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

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