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.

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
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")
print(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)

print(credentials)
# >>> {'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.

Example

See nbmask-tests.ipynb in extras

Installation

You can install the current version of this package with pip

pip install nbmask

Changelog

0.0.4

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

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.4-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file nbmask-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: nbmask-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for nbmask-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e144338ad6817fc0b85847ff767af01d835cca1b9881704e7c03a566e085eccc
MD5 3f371fdad997f3d7a061846137d2587e
BLAKE2b-256 c95f928229ca6627138db3467028452499fddbd4b2315efe3b22e4bca0b062b6

See more details on using hashes here.

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