Is there somewhere I can find which python modules that are available natively for use in a python script for HA?
I’m trying to find the difference between two dates maintaining month/day/year formatting. Everything I’ve read says to use “relativedelta” which is available by importing the dateutil module.
The problem is I can’t import that module. I get an error:
2019-11-08 02:17:51 ERROR (SyncWorker_18) [homeassistant.components.python_script.future_date.py] Error executing script: __import__ not found
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/python_script/__init__.py", line 195, in execute
exec(compiled.code, restricted_globals, local)
File "future_date.py", line 29, in <module>
ImportError: __import__ not found
I found this thread that says that there are some standard modules imported already (datetime being one of them) so that we don’t need to import those.
That thread also mentions that dt_util is also being natively included. I figured that maybe that module would include the relativedelta that I need but when I try to call that module I get an error:
2019-11-08 01:55:05 ERROR (SyncWorker_18) [homeassistant.components.python_script.future_date.py] Error executing script: Not allowed to access module.relativedelta
I thought that HA is written in Python and used Python “stuff” but I can’t find the “stuff” that HA already has included. And I don’t know why I can’t import the other “stuff” that’s not already included by using the import command.
it seems that HA doesn’t use the standard syntax/naming to run Python “stuff” that everyone else uses since looking at using other references from outside of HA many times fails.
How can we know the differences?
Any help would be appreciated.
EDIT:
Here is a thread that ultimately has an example of exactly what i’m trying to accomplish: