import os os.path.exists("api_key.txt") with open("api_key.txt", "r") as f: my_api_key = f.read().strip() # my_api_key = os.environ.get("my_api_key") print(my_api_key)