Skip to content

Instantly share code, notes, and snippets.

@akaIDIOT
Last active March 9, 2026 13:13
Show Gist options
  • Select an option

  • Save akaIDIOT/f5de7c491bf21ab44e3a88591c2175df to your computer and use it in GitHub Desktop.

Select an option

Save akaIDIOT/f5de7c491bf21ab44e3a88591c2175df to your computer and use it in GitHub Desktop.
Enable some optional but useful features of Python through environment variables
# This file is intended to be sourced by a shell, not doing anything by
# default, but adding functions "full-monty" and "no-monty" as enabler and
# disabler respectfully of some useful features in Python through environment
# variables. Put it somewhere like /etc/profile.d/ or the likes. Or don't 🤷
#
# See https://docs.python.org/3/using/cmdline.html#environment-variables
full-monty() {
# run in optimized mode, removing assert and debug code
export PYTHONOPTIMIZE=1
# use UTF-8 as the default encoding basically everywhere
export PYTHONUTF8=1
# use colors where supported (3.13+)
export PYTHON_COLORS=1
# attempt to disable the GIL (3.13+)
export PYTHON_GIL=0
# enable the JIT compiler (3.13+)
export PYTHON_JIT=1
# make lazy imports the default (3.15+)
export PYTHON_LAZY_IMPORTS=all
}
no-monty() {
unset PYTHONOPTIMIZE
unset PYTHONUTF8
unset PYTHON_COLORS
unset PYTHON_GIL
unset PYTHON_JIT
unset PYTHON_LAZY_IMPORTS
}
export -f full-monty
export -f no-monty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment