Quick Start Guide

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Redaction MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-redaction -- dnx GroupDocs.Redaction.Mcp --yes
Folders, licensing and more →

This guide shows how to set up GroupDocs.Redaction for Python via .NET and run your first redactions. The library finds sensitive text, metadata, comments and image areas in documents and removes or replaces them, so the saved document no longer contains them.

Prerequisites

To proceed, make sure you have:

  1. Configured environment as described in the System Requirements topic.
  2. Optionally you may Get a Temporary License to test all the product features.

Set Up Your Development Environment

For best practices, use a virtual environment to manage dependencies in Python applications. Learn more about virtual environments at the Create and Use Virtual Environments documentation topic.

Create and Activate a Virtual Environment

Create a virtual environment:

py -m venv .venv
python3 -m venv .venv
python3 -m venv .venv

Activate a virtual environment:

.venv\Scripts\activate
source .venv/bin/activate
source .venv/bin/activate

Install groupdocs-redaction-net Package

After activating the virtual environment, run the following command in your terminal to install the latest version of the package:

py -m pip install groupdocs-redaction-net
python3 -m pip install groupdocs-redaction-net
python3 -m pip install groupdocs-redaction-net

Ensure the package is installed successfully. pip installs groupdocs-shared-net, the package of the shared groupdocs.pydrawing and groupdocs.pycore modules, with it. You should see the message

Successfully installed groupdocs-redaction-net-* groupdocs-shared-net-*

Example 1: Redact a name in a Word document

The complaint letter sample.docx names the customer, Emily Johnson, twice. The example replaces the name with [customer] and saves the letter as a Word document:

from groupdocs.redaction import Redactor
from groupdocs.redaction.options import SaveOptions
from groupdocs.redaction.redactions import ExactPhraseRedaction, ReplacementOptions


def redact_phrase():
    with Redactor("sample.docx") as redactor:
        # Replace every occurrence of the name with a label
        result = redactor.apply(ExactPhraseRedaction("Emily Johnson", ReplacementOptions("[customer]")))
        print("Status:", result.status.name)

        # Keep the Word format and add a suffix to the file name
        options = SaveOptions()
        options.add_suffix = True
        options.rasterize_to_pdf = False
        options.redacted_file_suffix = "redacted"
        print("Saved to", redactor.save(options))


if __name__ == "__main__":
    redact_phrase()

sample.docx is the sample file used in this example. Click here to download it.

Binary file (DOCX, 40 KB)

Download full output

Run the App

py redact_phrase.py
python3 redact_phrase.py
python3 redact_phrase.py

Explanation

  • Redactor("sample.docx"): Opens the document. Use it in a with block, so the file is released when you are done.
  • ExactPhraseRedaction(phrase, ReplacementOptions(text)): Finds the phrase, ignoring case, and replaces it with the text. Pass True as the second argument for a case-sensitive search.
  • apply(...): Runs the redaction and returns a change log; its status is APPLIED, PARTIALLY_APPLIED, SKIPPED or FAILED.
  • SaveOptions: rasterize_to_pdf = False keeps the original format; add_suffix and redacted_file_suffix name the output sample_redacted.docx, next to the source.

Example 2: Black out account numbers in a PDF

The customer statement sample.pdf holds an account number such as 12 34 567890. A regular expression finds it, and a black box covers it:

from groupdocs.redaction import Redactor
from groupdocs.redaction.options.drawing import Color
from groupdocs.redaction.redactions import RegexRedaction, ReplacementOptions


def redact_account_numbers():
    with Redactor("sample.pdf") as redactor:
        # Two digits, two digits, then six digits: "12 34 567890"
        pattern = r"\d{2}\s*\d{2}[^\d]*\d{6}"
        result = redactor.apply(RegexRedaction(pattern, ReplacementOptions(Color.black)))
        print("Status:", result.status.name)

        # The default save writes a PDF of page images, from which no text can be recovered
        print("Saved to", redactor.save())


if __name__ == "__main__":
    redact_account_numbers()

sample.pdf is the sample file used in this example. Click here to download it.

Binary file (PDF, 914 KB)

Download full output

Explanation

  • RegexRedaction(pattern, options): Redacts every match of a regular expression, in .NET syntax.
  • ReplacementOptions(Color.black): Draws a box of that colour over the match instead of replacing its text. Color comes from groupdocs.redaction.options.drawing, with Point, Size and Rectangle.
  • save(): With no options, saves a rasterized PDF with the _Redacted suffix, sample_Redacted.pdf. Each page becomes an image, so the covered text is gone from the file, not only hidden.

Example 3: Clean a spreadsheet of a name and its metadata

apply() also takes a list. This example replaces the customer’s name in the delivery log sample.xlsx and erases the workbook’s metadata, such as its author and company, in one call:

from groupdocs.redaction import Redactor
from groupdocs.redaction.options import SaveOptions
from groupdocs.redaction.redactions import (
    EraseMetadataRedaction,
    ExactPhraseRedaction,
    MetadataFilters,
    ReplacementOptions,
)


def redact_spreadsheet():
    with Redactor("sample.xlsx") as redactor:
        log = redactor.apply([
            ExactPhraseRedaction("Emily Johnson", ReplacementOptions("[customer]")),
            EraseMetadataRedaction(MetadataFilters.ALL),
        ])
        # One log entry per redaction
        for entry in log.redaction_log:
            print(entry.result.status.name)

        # Keep the Excel format, with the "redacted" suffix
        print("Saved to", redactor.save(SaveOptions(False, "redacted")))


if __name__ == "__main__":
    redact_spreadsheet()

sample.xlsx is the sample file used in this example. Click here to download it.

Binary file (XLSX, 8 KB)

Download full output

Explanation

  • apply([...]): Applies the redactions in order and returns one change log, with an entry per redaction in redaction_log.
  • EraseMetadataRedaction(MetadataFilters.ALL): Clears every metadata property; a filter such as MetadataFilters.AUTHOR clears one.
  • SaveOptions(False, "redacted"): Keeps the format and adds the suffix: sample_redacted.xlsx.

Next Steps