Metadata-Version: 2.1
Name: nbmask
Version: 0.0.3
Summary: IPython extension to mask sensitive data
Project-URL: homepage, https://github.com/furechan/nbmask
Author-email: furechan <furechan@xsmail.com>
License: Copyright (c) 2016 The Python Packaging Authority (PyPA)
        
        Permission is hereby granted, free of charge, to any person obtaining a copy of
        this software and associated documentation files (the "Software"), to deal in
        the Software without restriction, including without limitation the rights to
        use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
        of the Software, and to permit persons to whom the Software is furnished to do
        so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE.txt
Keywords: extension,ipython,privacy
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.8
Description-Content-Type: text/markdown

# 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.

```python
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.


```python
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.

```python
%%masked

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

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


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

```python
%%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

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

## Changelog

### 0.0.3
- Masking pattern is cached
