A small Python CLI library that provides Pydantic-based argument parser with type safety.
- Type-safe CLI arguments with Pydantic validation
- Decorator-based design for clean, readable code
- Automatic argument parsing from class definitions
- Modern Python 3.11+ with full type hints
# Install via pip
pip install kliamka
# Install from source
git clone https://github.com/hotsyk/kliamka.git
cd kliamka
make install
# Or install in development mode
pip install -e .from kliamka import KliamkaArg, KliamkaArgClass, kliamka_cli
class MyArgs(KliamkaArgClass):
"""My CLI application arguments."""
verbose: bool | None = KliamkaArg("--verbose", "Enable verbose output")
count: int | None = KliamkaArg("--count", "Number of iterations", default=1)
@kliamka_cli(MyArgs)
def main(args: MyArgs) -> None:
"""Main application logic."""
if args.verbose:
print("Verbose mode enabled")
for i in range(args.count or 1):
print(f"Iteration {i + 1}")
if __name__ == "__main__":
main()Run your CLI:
python my_app.py --verbose --count 3Descriptor for defining CLI arguments with automatic type inference.
class KliamkaArg:
def __init__(self, flag: str, help_text: str = "", default: Any = None)Base class for CLI argument definitions using Pydantic models.
class MyArgs(KliamkaArgClass):
debug: bool | None = KliamkaArg("--debug", "Enable debug mode")
config: str | None = KliamkaArg("--config", "Configuration file path")Decorator that automatically parses CLI arguments and injects them as the first parameter.
@kliamka_cli(MyArgs)
def main(args: MyArgs) -> None:
# args is automatically populated from command line
passSee the examples/ directory for more comprehensive usage examples:
examples/basic_usage.py- Basic CLI argument handlingexamples/enums.py- Handling of enumerated types
- Python 3.11+
- Pydantic 2.0+
# Clone and setup
git clone https://github.com/hotsyk/kliamka.git
cd kliamka
make install
# Run tests
make test
# Lint and type check
make lint
# Run example
python examples/basic_usage.py --helpmake install- Install package in development modemake run- Run the CLI applicationmake test- Run tests with pytestmake lint- Run type checking and lintingmake format- Format code with ruffmake clean- Clean build artifacts
- Examples - Usage examples and demos
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Run
make lintandmake test - Submit a pull request
MIT-NORUS License - see LICENSE file for details.
Volodymyr Hotsyk - https://github.com/hotsyk