Environment Variables in Python Scripts

Hi All,

I have a python script I am using for the rubbish bin collection in my local city. It uses a public API that uses my address to deliver the collection cycle. Needless to say, I don’t want to publish my address in my python script (or on Bitbucket) so I’d like to learn how to store an environment variable somewhere within the HassOS system or somehow within the Home Assistant configuration (or another option if it exists). I understand there is the ability to store !env_var within YAML files but I’m unsure how I would reference these within a Python script.

I have used a .env file for development of the script which is used by a package called python-dotenv to store the sensitive data but as HassOS is largely immutable, I cant install this package so this isn’t a solution that I can use in production.

Here’s a link to the script for context and a link to the Brisbane City Council API.

Happy to provide further info Any help would be much appreciated!