I am trying to find the best practice for importing modules dynamically. I have multiple files in a specific folder called providers which contain a class Updater and all of them have the same objects.
This is the structure I have:
main.py
|-providers:
--__init__.py
--plex.py
--pihole.py
Each provider has 3 class objects: get_latest_version, get_current_version, install.
This is the contents of main.py file:
#!/usr/bin/env python3
from Updater.plex import Updater as PlexUpdater
from Updater.pihole import Updater as PiholeUpdater
for provClass in [PlexUpdater, PiholeUpdater]:
provider = provClass()
latest_version = provider.get_latest_version()
current_version = provider.get_current_version()
provider.install()
I need to be able to create file on the providers folder and be automatically imported on the main file without explicitly importing myself. Could you suggest a way to make this work?