Skip to main content

IPython extension to mask sensitive data

Simple ipython extension to mask sensitive data like credentials from notebook cell outputs. This extensions may be useful to avoid inadvertently displaying sensitive data in public notebooks. The extension modifies the ipython display system to try and mask any occurence of any of the given strings that appear in textual outputs from printing, logging and the native display system.

Usage

To load the extension use the magic command %load_ext nbmask. The extension will automatically mask the notebook display textual outputs without any further magic commands. When first loaded the extension will mask just the username.

import os
from pathlib import Path

%load_ext nbmask

username = os.getenv('USER')
print("My name is {username}!")
# >>> My name is ...!

documents = Path(f"~/Documents").expanduser()
documents
# >>> PosixPath('/Users/.../Documents')

You can add more secrets with the %nbmask magic line command and a string parameter using python builtin variable expansion syntax.

TOKEN = my_secret_token()

%nbmask "$TOKEN"

credentials = dict(user=username, token=TOKEN)

credentials
# >>> {'user': '...', 'token': '...'}

The extension modifies standard output, standard error and also the default logging handlers.

import logging

logging.basicConfig(level="DEBUG")

logging.debug("Token is %s", TOKEN)
# >>> DEBUG:root:Token is ...

Example

See nbmask-tests.ipynb in extras

Installation

You can install the current version of this package with pip

pip install nbmask

Changelog

0.05

  • Now using uv_build backend
  • Added testing with pytest and nbmake
  • Requires python >= 3.10

0.0.4

  • Cell magic %%masked is no longer needed. Will be removed

0.0.3

  • Masking pattern is cached

Metadata

Release files for nbmask 0.0.5

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

Built distribution (wheel)

Table of built distributions (wheels) for nbmask 0.0.5
File Interpreter ABI Platform Actions
nbmask-0.0.5-py3-none-any.whl Python 3 none any Details for nbmask-0.0.5-py3-none-any.whl

Release files / nbmask-0.0.5-py3-none-any.whl

Download URL nbmask-0.0.5-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4694da079fa099cc727557492c8357ff240521574c55ff8383a309be33a26bc5
BLAKE2b-256 checksum
How to use checksums
7fadec553f37bd55ad3f4c913e60760aa1afe09623c9a79051299aa180221265
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.7

Security for nbmask 0.0.5

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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