As AI said (as well as Organic Intelligence), since python 3.9 there is zoneinfo module.
A Frankenstein from current script mixed with zoneinfo, outputing same json format (and without error handling):
import json
import sys
import zoneinfo
from functools import lru_cache
@lru_cache(maxsize=None)
def get_timezones():
return zoneinfo.available_timezones()
accepted_timezone_list = list(get_timezones())
config={
"accepted_timezone_list": accepted_timezone_list,
}
json.dump(config, fp=sys.stdout)
Tested on Debian and Rocky.
Additionally to the zoneinfo python’s module info page, a good read for other missing parts (CLDR, deprecated names… although nowadays the list is current) and where the cache tip came from is How to List All Time Zones in Python - Adam Johnson