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 the ipython notebook outputs. It may be useful when printing or displaying sensitive information in public notebooks.

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

import os

from pathlib import Path

from IPython.display import display

%load_ext nbmask

username = os.getenv('USER')
message = f"My name is {username}!"
documents = Path(f"/Users/{username}/Documents")

display(username) # >>> '...'

display(message) # >>> 'My name is ...!'

display(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(token=TOKEN)

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

To mask print or pprint outputs you need to explicitely use the %%masked cell magic for any cell that prints sensitive data.

%%masked

message = f"My name is {username}!"

print(message) # >>> My name is ...!

The %%masked cell magic can also be used to mask logging outputs.

%%masked

import logging

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

logging.debug("Used token %s", TOKEN) # >>> DEBUG:root:Used token ...

Example

See nbmask-tests.ipynb in extras

Installation

You can install the current version of this package with pip

python -mpip install git+https://github.com/furechan/nbmask.git

Changelog

0.0.3

  • 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.3-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