IPython extension to mask sensitive data
Project description
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_buildbackend - Added testing with
pytestandnbmake - Requires python >= 3.10
0.0.4
- Cell magic
%%maskedis 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nbmask-0.0.5-py3-none-any.whl.
File metadata
- Download URL: nbmask-0.0.5-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4694da079fa099cc727557492c8357ff240521574c55ff8383a309be33a26bc5
|
|
| MD5 |
00bdff7e9c35c32b1aa718f0199dfc31
|
|
| BLAKE2b-256 |
7fadec553f37bd55ad3f4c913e60760aa1afe09623c9a79051299aa180221265
|