Is there a way to store secrets/access secrets/passwords in notebooks? I have an api endpoint where I pull data from, and I dont want to expose the apiKey to everyone who can view the notebook.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
cco's answer is good, but if you're looking for a simpler solution, many people use environmental variables to keep secrets segregated from source code.
For example, you can provide them when executing your script in the shell:
In your source code:
For your Jupyter notebooks, you can use
python-dotenv
or a similar package to "retrieve" a.env
file that contains your project's secrets and is ignored by your version control system.Once you've created your
.env
file (either manually, or using the package's command line tool), you can usepython-dotenv
in Jupyter (or IPython) like so:Store your credentials in a JSON or YAML, and have your notebook parse the necessary parts.
You should avoid printing the secrets in the cell outputs, for otherwise any technique you choose will be foiled.
You can use the keyring package to store sensitive information in a system-specific protected store.
It can be installed via
pip
from pypi.