PKNLs?77ipython_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__ = '1.0.0' import os import keyring try: from IPython.display import clear_output except ImportError: def clear_output(): pass DEFAULT = object() def get_secret(service_name, *, username=None, default=DEFAULT, 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 supplied, 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 not force_prompt: password = keyring.get_password(service_name, username) if password is not None: return password if default is not DEFAULT: return default 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-1.0.0.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!HNO%ipython_secrets-1.0.0.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,zd&Y)r$[)T&UrPK!Hs^(ipython_secrets-1.0.0.dist-info/METADATAWnF}W,I 탊5QF蓽"GV]vw)E?gvIbmVO̜9sf8@AV2r^Y3/مlh*T 5Qhx^<Ϯn;7J.IήUE^,:Su,E$R06U -PdB͋6qZUIŻ_/j S#}G*Oŷ__eKZ.%cM mx>ɧ{P?:n%S1K`7Y80q*qULIlxNkҶElz&Zn\f 2p?IZQqa=W.qYvfݫ#\0+:Xݷ9z uׇ,^:^ܟMw]ZMϲ#ԫ Q⥿nvSX(hAՐ[RM>wQJ:e\4id?`uZG 5THSeBQ싟(5IG_ Ps=1=_id%Ƌc^E%k2`~BR9!%yTÒYM3M}M uGT4!QK/B#0="X;FkpRٍad#E==Zxk:zc[u[t#ɳ-^w}bi˹!z,EPF 2ki@/b=SR\jk"RN! 6PhF/!p I<$!(q=(jxؐP%tەIZHڊ@;1x|C7#v،+J[Q 7DMԒVDmd0l;IZnzub*VeقpQ}͉Mm;TJ Ugfyz({1l$r;ߎhxCͯ۳~n=}rhLC5>~HOSE:R ,)x(w!VR )oT N:K{5N0S1GgO֌%%)SZ8K3dY VGyX *WkYXy( 1qZpމ7baDEkb>./Yjr^"| ;3` rm2+H\cipd=إxc y-*XTQ kW5׊t e'U[2V4E;1;w/qa2hn﹣AĔ>?gȣ T)Sq\w}u0m. $9OPqB?{5pJп[y|qb"|-X