https://github.com/esther-poniatowski/khimera
Python library for composing structured and modular CLI, dynamic plugin discovery and caching
https://github.com/esther-poniatowski/khimera
cli dynamic-programming plugin-manager python
Last synced: 3 months ago
JSON representation
Python library for composing structured and modular CLI, dynamic plugin discovery and caching
- Host: GitHub
- URL: https://github.com/esther-poniatowski/khimera
- Owner: esther-poniatowski
- License: gpl-3.0
- Created: 2025-02-14T09:31:20.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-02-15T06:40:43.000Z (4 months ago)
- Last Synced: 2025-02-15T07:30:50.937Z (4 months ago)
- Topics: cli, dynamic-programming, plugin-manager, python
- Language: Python
- Homepage:
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Khimera
**Khimera** is a Python library designed for structured CLI management with modular and dynamic command registration, nested CLI structures, and automatic discovery of internal and external plugins.
## Key Features
- **Structured CLI Framework**: Allows nested command groups, extending the `Typer` library.
- **Dynamic Command Registery**: Commands and groups can be composed and retrieved modularly at runtime to assemble the main application.
- **Automatic Plugin Discovery**: Supports internal (built-in) and external (third-party) plugins in a uniform process.
- **Plugin Caching**: Reduces startup time by avoiding redundant discovery operations in each application call.## Installation
Khimera is a standalone package that can be installed via pip:
```sh
pip install khimera
```## Usage
### Creating a CLI
Initialize the main application:
```python
# cli.py
from khimera import CliAppapp = CliApp()
```Register a command group:
```python
setup_group = app.add_group("setup", help="Setup project components.")@setup_group.command("init")
def setup_project():
print("Project initialized!")if __name__ == "__main__":
app()
```Run:
```sh
python cli.py setup init
```### Plugin Discovery & Dynamic Registration
Plugins register their commands using the `@register_plugin_command` decorator:
```python
# external_plugin.py
from khimera import register_plugin_command@register_plugin_command("setup", "custom-tool")
def custom_setup():
print("Custom setup logic executed!")
```The main application scans installed plugins and registers their commands automatically:
```python
# cli.py
from khimera.plugin_loader import discover_pluginsdiscover_plugins()
```## Plugin System
The application can integrate both internal and external plugins uniformly.
### Internal (Built-in) Plugins
Built-in plugins can be disabled or replaced at runtime:
```python
from khimera import disable_plugindisable_plugin("setup")
```### External Plugins
Third-party plugins register themselves via `pyproject.toml`:
```toml
[project.entry-points."khimera.plugins"]
my_plugin = "my_plugin.commands"
```Once installed:
```sh
pip install my_plugin
```The plugin will be discovered automatically.
## Plugin Caching
To prevent unnecessary rediscovery each time the application is called, plugins are cached.
Forcing a manual refresh:
```sh
python cli.py --reload-plugins
```## License
Khimera is licensed under the GNU [License](LICENSE).