Skip to main content

This package provides functions for using secrets in a Jupyter notebook.

Project description

Latest PyPI Version Documentation Status License Supported Python Versions

IPython Secrets makes it easier to use secrets in a Jupyter notebook.

The first time get_secret is called, it prompts the user for the password or other secret. After this value is read, it is saved in the system keyring, and the Jupyter output cell is then cleared.

gif1

Subsequent calls to get_secret, use the saved value. This is true even if they are called in a different process running in the same account – for example, if the machine has been rebooted, or the local Jupyter server has otherwise been shut down and restarted.

gif2

Note

This package won’t work on Colaboratory (Colaboratory doesn’t run keyring). It probably won’t work on some other hosted notebook environments.

Warning

This package stores the secret on the Jupyter server. Don’t trust it with secrets you don’t trust the Jupyter server with. (This is true for all means of using a secret in a notebook.)

Warning

The package is intended to reduce the likelihood of accidental disclosure of secrets in notebook source. It won’t secure a secret from code that is running in the notebook; and it won’t keep you from writing code that displays the secret in a notebook output cell – in which case it has been disclosed to whoever can see the notebook.

Usage

from ipython_secrets import *

TWILIO_API_KEY = get_secret('TWILIO_API_KEY')

Alternatives

Secrets can also be stored in an environment variable, and read from the notebook. This is a best practice for applications (and especially web and other server-side services), but I’ve found it inconvenient for notebooks – the notebook server must be re-started to pick up a new environment variable; and, it complicates the setup instructions for notebook users.

Development

Install dev tools:

$ pip install -r requirements-dev.txt

Install locally:

flit install --symlink

Acknowledgements

This package is a thin wrapper around Keyring.

License

MIT

Project details


Release history Release notifications

This version
History Node

0.1.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
ipython_secrets-0.1.1-py3-none-any.whl (7.4 kB) Copy SHA256 hash SHA256 Wheel py3 Jan 26, 2018
ipython-secrets-0.1.1.tar.gz (62.7 kB) Copy SHA256 hash SHA256 Source None Jan 26, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page