PK0:L@[++ipython_secrets.py"""This package provides functions for using secrets in a Jupyter notebook. These functions are for use in a notebook that needs to make use of secrets, such as passwords and API keys, to avoid storing the secret in the notebook source. .. note:: This package uses Keyring_. See the `Keyring API documentation`_ for additional information about where secrets are stored, and how to change the default location. .. _Keyring: https://pypi.python.org/pypi/keyring .. _Keyring API documentation: http://keyring.readthedocs.io/en/latest/?badge=latest """ __version__ = '0.1.1' import os import keyring try: from IPython.display import clear_output except ImportError: def clear_output(): pass def get_secret(service_name, username=None, *, default=None, force_prompt=False, prompt=None): """Read a secret from the keyring or the user. Look for a secret in the keyring. If it's not present, prompt the user, clear the cell, and save the secret. Parameters ---------- service_name : str A keyring service name. username : str, optional A keyring username. This defaults to the value of the USER environment variable. (Note that this can programmatically altered.) default : str, optional The default value, if the secret is not present in the keyring. If this is non-None, the user is never prompted. force_prompt : str, optional If true, the user is always prompted for a secret. prompt : str, optional The text displayed to the user as part of the prompt. Examples -------- :: from ipython_secrets import * TWILIO_API_KEY = get_secret('TWILIO_API_KEY') TWILIO_API_KEY = get_secret('TWILIO_API_KEY', 'my-account') TWILIO_API_KEY = get_secret('TWILIO_API_KEY', 'my-account', prompt="Enter the API key") """ if username is None: username = os.environ.get('USER') password = None if force_prompt else keyring.get_password(service_name, username) if password is None: password = default if password is None: # uses ternary instead of `prompt or …`, in order to support prompt == '' prompt = '{}[{}]'.format(service_name, username) if prompt is None else prompt password = input(prompt) keyring.set_password(service_name, username, password) clear_output() return password def set_secret(service_name, password, *, username=None): """Sets a secret value. Parameters ---------- service_name : str A keyring service name. password : str A keyring service name. username : str, optional A keyring username. This defaults to the value of the USER environment variable. Notes ----- The argument order to `set_secret` is different from :func:`keyring.set_password`, and `username` can only be used as keyword parameter. This is in order that `username` can be optional, for compatibility with the more-frequently-used functions in this package. """ if username is None: username = os.environ.get('USER') keyring.set_password(service_name, username, password) def delete_secret(service_name, username=None): """Deletes a secret from the keyring. Parameters ---------- service_name : str A keyring service name. username : str, optional A keyring username. This defaults to the value of the USER environment variable. """ if username is None: username = os.environ.get('USER') keyring.delete_password(service_name, username) PK b"L0*88'ipython_secrets-0.1.1.dist-info/LICENSEThe MIT License (MIT) Copyright (c) 2018 Oliver Steele 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. PK!HxQP%ipython_secrets-0.1.1.dist-info/WHEEL1 0 RZq+D-Dv;_[*7Fp 8MRq%_:==ߘPT PK!H $3a(ipython_secrets-0.1.1.dist-info/METADATAWQo6~ׯ IX^Zl.h6kKbO --]eMdIwt~KA2伲f"ٕi"T 5#O,?nۺn3wR.H4ήTI^[Su,D$R06ebk5@*O U; [DƇaQwW_e-޻j=Q-coWMğ_f^gb-d"] dJ*E[*2%Hlv*.;۾\DvSKj\7.qoY\A׋R0K8X>*e+ʲǛT-POZmƺncZ.!LIlD%}N]Eb"Â}yP~!qQR]>4`(u9VRĈdo/a|*jG멐6hۆ (4IG%x\mgbyO4ϋǸ%k25g~BT99!ydÒ.(l шi胬M;XE Jz1#$Hnv' IDG_Ү $kc9X,[[sDlgrf^m-ɳ-Dr14Lo=Hrxr 1tLaSR\*k"x4C Zci6O`D\c8_$1rQEP>Jlx;!J-ZV%(fRK m} ^?|zۺb1R `}s(lI0T2vV'ʜ0G--ڒ FSqdfP3EWREނqkᢪQWP TوH>cXtW =5Vq3{?}3޿q.vhžАWiE>]D"$4H~` 9&ӮeFYk?$ϲN  D Ga†k 8?eXvy?|lC N>me07Fa"іy¤")Ѷ,#~ǦL>%ҝ%'sXRhݺ\][jÀ;M_}>V |wؤIZD Kò Ǫʿ!Ffhv1Xu5$i?ZVY{^|