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.
Asked
Active
Viewed 2,340 times
2 Answers
2
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

ElliotSknr
- 246
- 1
- 7
2
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")

Bao Dinh
- 64
- 6
-
I have tried this, but it says 'none'. – Renu Dhaka Dec 16 '21 at 03:08
-
Where do u put your .env file ? – Bao Dinh Dec 16 '21 at 03:17
-
it's in my C drive – Renu Dhaka Dec 16 '21 at 03:45
-
This worked for me in my ipynb notebook – Nirmal Sankalana Feb 16 '23 at 14:23
-
worked. "pip install python-dotenv" – aravinda_gn May 17 '23 at 16:05