I wanted to find a different method that didn't require me to read the json file or to have to upload it to root while using Colab. I instead wanted to just store the json in my drive somewhere and let the kaggle cli know where it is.
As it turns out, there's a way to do that, which is set the environment variable KAGGLE_CONFIG_DIR
If you don't have the json file yet, check the docs for how to get that: link Then upload it to your drive. Mine happens to be at /content/drive/My Drive/fastai-v3/.kaggle/kaggle.json. (ayyy shoutout to the FastAI courses 👌 ) Now in colab you can just run:
import os
os.environ['KAGGLE_CONFIG_DIR'] = "/content/drive/My Drive/fastai-v3/.kaggle/" # put path for wherever you put it