Yes, that works, and I’ve used that on a couple of projects. Another alternative is defining an Abstract Base Class, https://docs.python.org/3/library/abc.html, and having an institution-specific implementation passed into your module.
From: Python-list <python-list-bounces+gweatherby=uchc....@python.org> on behalf of Loris Bennett <loris.benn...@fu-berlin.de> Date: Wednesday, March 15, 2023 at 1:03 PM To: python-list@python.org <python-list@python.org> Subject: Implementing a plug-in mechanism *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Hi, I have written a program which, as part of the non-core functionality, contains a module to generate email. This is currently very specific to my organisation, so the main program contains import myorg.mailer This module is specific to my organisation in that it can ask an internal server to generate individualised salutations for a given UID which is known within the organisation. I want to share the code with other institutions, so I would like to 1. replace the organisation-specific mailer with a generic one 2. allow an organisation-specific mailer to be used instead of the generic one, if so desired Is importlib the way to go here or is there another approach? Cheers, Loris -- This signature is currently under constuction. -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!izCZs2X5PFeGpCF4TrtdDABzPqCFFT5i89Zsu-msRJAIpyWZYybdHDOFdxno9J3JvpNsRRQK9w72qgYj0MjlB2L-LsVXW1o$<https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!izCZs2X5PFeGpCF4TrtdDABzPqCFFT5i89Zsu-msRJAIpyWZYybdHDOFdxno9J3JvpNsRRQK9w72qgYj0MjlB2L-LsVXW1o$> -- https://mail.python.org/mailman/listinfo/python-list