Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/furechan/nbmask
IPython extension to mask sensitive data
https://github.com/furechan/nbmask
extension ipython privacy
Last synced: 24 days ago
JSON representation
IPython extension to mask sensitive data
- Host: GitHub
- URL: https://github.com/furechan/nbmask
- Owner: furechan
- License: mit
- Created: 2023-12-21T16:18:36.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-01-14T03:37:21.000Z (10 months ago)
- Last Synced: 2024-09-29T18:23:40.929Z (about 1 month ago)
- Topics: extension, ipython, privacy
- Language: Python
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# IPython extension to mask sensitive data
Simple ipython extension to mask the username or other sensitive data
from notebook cell outputs. This may be useful when printing or display
sensitive information in public notebooks. The extension modifies the
ipython display system to mask any occurence of one of the secrets strings
in the 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.```python
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 pass it any string parameter with the `$name` variable notation.```python
TOKEN = my_secret_token()%nbmask "$TOKEN"
credentials = dict(user=username, token=TOKEN)
credentials
# >>> {'user': '...', 'token': '...'}
```The extension applies to standard output, standard error and
also the default logging handlers.```python
import logginglogging.basicConfig(level="DEBUG")
logging.debug("Token is %s", TOKEN)
# >>> DEBUG:root:Token is ...
```To mask `print` or `pprint` outputs the extension still includes a `%%masked` cell magic,
but it is no longer needed and it will be removed.## Example
See nbmask-tests.ipynb in `extras`
## Installation
You can install the current version of this package with pip
```console
pip install nbmask
```## Changelog
### 0.0.4
- Cell magic `%%masked` is no longer needed. Will be removed### 0.0.3
- Masking pattern is cached