bbelderbos,
@bbelderbos@fosstodon.org avatar

Managing environment variables in , python-dotenv or -decouple?

When I need to:

from distutils.util import strtobool
DEBUG = bool(strtobool(os.getenv('DEBUG', 'True')))

...to ensure correct types, I opt out of python-dotenv. Python-decouple (or Pydantic) it is for me :)

cpontvieux,
@cpontvieux@piaille.fr avatar

@bbelderbos I use:

from os import getenv  
DEBUG = getenv('DEBUG', 'True').lower() in ('True', '1', 'on')  

And I think it works great.
Better than using another dependency just for that imho.

bbelderbos,
@bbelderbos@fosstodon.org avatar

@cpontvieux thanks, cool, in this case it's more about swapping python-dotenv for python-decouple (or pydantic) for the extra casting. I would still use a library, because it also supports parsing an .env file for local development.

orsinium,
@orsinium@fosstodon.org avatar
  • All
  • Subscribed
  • Moderated
  • Favorites
  • python
  • tacticalgear
  • DreamBathrooms
  • InstantRegret
  • magazineikmin
  • osvaldo12
  • Youngstown
  • ngwrru68w68
  • slotface
  • everett
  • rosin
  • thenastyranch
  • kavyap
  • GTA5RPClips
  • tester
  • JUstTest
  • modclub
  • cubers
  • ethstaker
  • mdbf
  • khanakhh
  • Durango
  • normalnudes
  • Leos
  • cisconetworking
  • anitta
  • provamag3
  • megavids
  • lostlight
  • All magazines