https://github.com/cdce8p/load-plugins
Provide interface to load custom Python plugins
https://github.com/cdce8p/load-plugins
Last synced: 8 months ago
JSON representation
Provide interface to load custom Python plugins
- Host: GitHub
- URL: https://github.com/cdce8p/load-plugins
- Owner: cdce8p
- License: mit
- Created: 2022-01-19T14:22:52.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-11-09T10:53:23.000Z (over 3 years ago)
- Last Synced: 2025-09-10T06:04:33.970Z (9 months ago)
- Language: Python
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Load-plugins
Dynamically load plugin packages based on `pyproject.toml` config.
Only recommend to use for applications that use a plugin
structure internally but don't officially support custom plugins.
## How does it work?
The library installs a `.pth` file into the `site-packages` directory.
This is executed for every Python program call.
The `.pth` file itself will load a Python module which reads the `pyproject.toml`
file to determine which packages to import. For each package, it will
import all individual modules separately. Thus, it's not necessary to
import them inside the package `__init__.py` file.
All that happens **before** the actual Python program is executed.
## Disclaimer
This library **will** slow down the startup of any Python program.
It is recommended to only use it in isolated environments!
E.g. together with `pre-commit`.
## Configuration and Usage
To configure the library, add a `pyproject.toml` file to the root of your project.
There are two different options, which can be used together.
1. Packages which should **always** be loaded
```toml
[tool.load_plugins]
packages = [
"plugin_package",
"folder.with_package",
]
```
2. And packages which should only be loaded for certain applications.
The name of the binary is used as filter.
E.g. for a Python application with entry point `app`, use this config.
```toml
[tool.load_plugins.app]
packages = [
"plugin_package",
]
```
If used with `pre-commit`, remember to add `load-plugins` as `additional_dependencies`.
## License
This Project is licensed under the MIT license.
See [LICENSE][LICENSE_FILE] for the full license text.
[LICENSE_FILE]: https://github.com/cdce8p/load-plugins/blob/main/LICENSE