1

I have a directory called plugins. It contains an empty __init__.py file.

There can be several Python files in this directory. For example plugin_a.py and plugin_b.py.

I want to import these files at runtime.

How to import all files in the plugins directory?

I want to leave the __init__.py file empty.

The existence of a new file in the directory should be enough to make the plugin available.

This loading happens in a script. At runtime no new python files get added. Loading once is enough.

petezurich
  • 9,280
  • 9
  • 43
  • 57
guettli
  • 25,042
  • 81
  • 346
  • 663
  • 1
    Where are you importing the plugin from? A long-running process or a script? Do you need to hot-reload? Or import at startup? – rdas Jun 18 '19 at 09:29
  • 1
    Possible duplicate of [How to load all modules in a folder?](https://stackoverflow.com/questions/1057431/how-to-load-all-modules-in-a-folder) – rdas Jun 18 '19 at 09:32

0 Answers0