I want get data using HubSpot Api in Python, however, I don't want to show my ApiKey in the code. What would be the best practice to get data using Api Without showing your Api key? I am currently working in Jupyter notebook.
CodePudding user response:
You would be looking to store the API key in your environment variables, then read from the environment variables in your python code.
In Jupyter you could achieve this with magic commands; https://ipython.readthedocs.io/en/stable/interactive/magics.html
Set with
%env VAR_KEY VAR_VALUE
You can then use these with
import os
os.getenv(key)
Alternatively, instead of magic commands you could set the env variable in your kernel.json, see here; https://stackoverflow.com/a/53595397/12707704
CodePudding user response:
https://www.youtube.com/watch?v=YdgIWTYQ69A u can flow this tutorial
Simply create a file name ".env" and write your API key in Like this : "API_KEY = YOUR_API_KEY"
then run "pip3 install dotenv" in your cmd
then in your code, add some lines :
from dotenv import load_dotenv
import os
load_dotenv()
API_KEY=os.getenv("API_KEY")