Skip to main content

IPython extension to mask sensitive data

Project description

IPython extension to mask sensitive data

Simple ipython extension to mask the username or other sensitive data from notebook cell outputs. It may be useful when printing or displaying sensitive information in public notebooks. The extension modifies the ipython display system to mask textual outputs from printing, logging and the native display system.


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. By default the extension will mask the username.

import os
import logging

from pathlib import Path

from IPython.display import display

logging.basicConfig(level="DEBUG", force=True)

%load_ext nbmask

username = os.getenv('USER')

print("My name is {username}!")
# >>> My name is ...!

documents = Path(f"/Users/{username}/Documents")
# >>> PosixPath('/Users/.../Documents')

You can add more secrets with the %nbmask magic line command using the ipython automatic $name variable expansion.

TOKEN = my_secret_token()

%nbmask "$TOKEN"

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

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

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

To mask print or pprint outputs the extension include a %%masked cell magic but is is no longer and it will be removed.


See nbmask-tests.ipynb in extras


You can install the current version of this package with pip

pip install nbmask



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


  • Masking pattern is cached

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

nbmask-0.0.4-py3-none-any.whl (4.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page