In a nutshell Python Dynamic plugins
is a small library for manage Python plugins dynamically.
This library has two main parts:
- Pip utils
- Dynamic library loading
This module provides some utilities for pip from Python.
This library load, following some contrains, Python packages and load specific symbols from them. This is: functions, class definitions, variables, etc
The main idea of the project is to be able to create a plugin system which is easy to use and easy to maintain.
> pip install dynamic-plugins
For this example we'll use the demo package demo_module
that you can find in the demo_plugins
folder.
First you need to install the demo package
> cd demo_plugins/demo_module
> pip install . -U
In this example we'll load the hello_world()
function dynamically from the demo_module
package.
from dynamic_plugins import get_extensions
def main():
for package_name, package_content in get_extensions("demo-", sub_package="setup",symbols="hello_world").items():
print(package_name)
print(package_content["module_object"])
for fn in package_content["symbols"]:
print(fn())
if __name__ == '__main__':
main()
from dynamic_plugins import list_installed_packages
def main():
for package_name, package_version in list_installed_packages().items():
print(f"{package_name} {package_version}")
if __name__ == '__main__':
main()
from dynamic_plugins import install_library_from_pypi
def main():
install_library_from_pypi("requests")
if __name__ == '__main__':
main()
from dynamic_plugins import install_library_from_path
def main():
install_library_from_path("/path/to/package")
if __name__ == '__main__':
main()
Dictionary Search is Open Source and available under the MIT.
Contributions are very welcome. See CONTRIBUTING.md or skim existing tickets to see where you could help out.