Skip to main content

Small Python CLI library

Project description

Stand With Ukraine

Kliamka

A small Python CLI library that provides Pydantic-based argument parser with type safety.

PyPI - Version

Features

  • 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

Installation

# 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 .

Quick Start

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 3

API Reference

Core Components

KliamkaArg

Descriptor for defining CLI arguments with automatic type inference.

class KliamkaArg:
    def __init__(self, flag: str, help_text: str = "", default: Any = None)

KliamkaArgClass

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")

@kliamka_cli

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
    pass

Examples

See the examples/ directory for more comprehensive usage examples:

  • examples/basic_usage.py - Basic CLI argument handling
  • examples/enums.py - Handling of enumerated types

Development

Requirements

  • Python 3.11+
  • Pydantic 2.0+

Setup

# 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 --help

Versions

See VERSIONS.md for detailed version history and changelog.

Available Make Commands

  • make install - Install package in development mode
  • make run - Run the CLI application
  • make test - Run tests with pytest
  • make lint - Run type checking and linting
  • make format - Format code with ruff
  • make clean - Clean build artifacts

Documentation

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with tests
  4. Run make lint and make test
  5. Submit a pull request

License

MIT-NORUS License - see LICENSE file for details.

Author

Volodymyr Hotsyk - https://github.com/hotsyk

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kliamka-0.4.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kliamka-0.4.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file kliamka-0.4.0.tar.gz.

File metadata

  • Download URL: kliamka-0.4.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kliamka-0.4.0.tar.gz
Algorithm Hash digest
SHA256 db61a3979eb2b0352dbcace33f8defbd6c773e9032bf9ccd78709d3c0b3c78e2
MD5 eee4ea25f1063bb10e9d1be4e17c8a44
BLAKE2b-256 59320db390eca5a4f0b7c9d4381b2dbc53eba154c77e1dd137687e31a09b74dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for kliamka-0.4.0.tar.gz:

Publisher: publish.yml on hotsyk/kliamka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kliamka-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: kliamka-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kliamka-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1a368063ed131be854ef3c540a8542b0acfaedc07e6b2af405e2599c3d31f5d6
MD5 2c812da025aa803a2c4f2651d6a49a12
BLAKE2b-256 cec8504165891eed8ee4dce875a7cedd2197a243effcc2e47f680388054321af

See more details on using hashes here.

Provenance

The following attestation bundles were made for kliamka-0.4.0-py3-none-any.whl:

Publisher: publish.yml on hotsyk/kliamka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page