How to Hide API Keys When Deploying Code: Use Environment Variables on a Remote Server

preview_player
Показать описание
When deploying code to a server, it's best *not* to use a ".env" file to hide your API keys. Instead, here are two methods for storing environment variables – directly in the server's terminal or using the hosting platform's variable storage feature.

Whichever method you use, you can then easily access your environment variables with Python using the built-in "os" module's "getenv" function.

Get the source code here:

If you just want to hide API keys in your local environment, then using ".env" files is a convenient method. I made a video about how to do that here:

00:00 Introduction
00:29 Set variables directly on the server
02:20 Access environment variables with Python
03:54 Use your host's variables feature

#Python #programming
Рекомендации по теме