Skip to main content

Charmcli

Charmcli, build great CLIs. Easy to code. Based on Python type hints.


Charmcli is a library for building command-line (CLI) apps that are both fun to use and easy to build. It’s powered by Python type hints.

The key features are:

  • Intuitive to write: Great editor support. Completion everywhere. Less time debugging. Designed to be easy to use and learn. Less time reading docs.
  • Easy to use: Automatically adds help messages, commands and args based on type annotation.
  • Less code: Avoid repeating yourself. One line of code can do a lot. Fewer mistakes.
  • Quick setup: You can integrate it into your app almost instantly.
  • Grow large: Grow in complexity as much as you want, create arbitrarily complex trees of commands and groups of subcommands, with options and arguments.

Installation

Create and activate a virtual environment and then install Charmcli:

$ pip install charmcli
---> 100%
Successfully installed charmcli

Example

Use Charmcli in your code

Create a charmcli.Charmcli() app, and create two commands with their parameters.

import charmcli

app = charmcli.Charmcli()

@app.command()
def hello(name: str):
    """Greet a user"""
    print(f"Hello {name}")

@app.command()
def goodbye(name: Annotated[str, "name of a user"], msg: str = "Goodbye"):
    """Farewell a user"""
    print(f"{msg}, Mr {name}.")

if __name__ == "__main__":
    app()

And that will:

  • Explicitly create a charmcli.Charmcli app.
  • Add two subcommands with @app.command().
  • Execute the app() itself

Run the example

Check the help:

$ python main.py

Usage: main.py [OPTIONS] COMMAND [ARGS]...

Positional arguments:
  hello                Greet a user
  goodbye              Farewell a user

Options:
  -h, --help           show this help message and exit

// You have 2 commands (the 2 functions): goodbye and hello
// Params are the postional arguments and options for the command.
// Docstring is used as help text for command.

Now check the help for the hello command:

$ python main.py hello --help

Usage: main.py hello [-h] name

Greet a user

Positional arguments:
  name

Options:
  -h, --help           show this help message and exit

And now check the help for the goodbye command:

$ python main.py goodbye --help

Usage: main.py goodbye [-h] [--greet GREET] name

Farewell a user

Positional arguments:
  name                 name of a user

Options:
  --msg MSG            (default: Goodbye)
  -h, --help           show this help message and exit

Now you can try out the new command line application:

// Use it with the hello command

$ python main.py hello Chad

Hello Chad

// And with the goodbye command

$ python main.py goodbye Chad

Goodbye Chad.

$ python main.py goodbye Chad --msg 'Bye Bye'

Bye Bye Chad.

Recap

In summary, you declare once the types of parameters (CLI arguments and CLI options) as function parameters.

You do that with standard modern Python types.

You don't have to learn a new syntax, the methods or classes of a specific library, etc.

Just standard Python.

For example, for an int:

total: int

or for a bool flag:

force: bool

TODO: add files, paths, enums (choices), etc. And tools to create groups of subcommands, add metadata, extra validation, etc.

You get: great editor support, including completion and type checks everywhere.

Dependencies

Charmcli uses no external dependencies it works with just standard Python. Internally, it includes lightweight modules for features like text coloring and hyperlink support, built using ASCII sequences. This ensures compatibility with a wide range of environments, including older terminals that may not support modern features.

License

This project is licensed under the terms of the MIT license.

Screenshots

Charmcli

Metadata

Release files for charmcli 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for charmcli 0.1.3
File Size Uploaded
charmcli-0.1.3.tar.gz 11.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for charmcli 0.1.3
File Interpreter ABI Platform
charmcli-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 22.1 kB

Release files / charmcli-0.1.3.tar.gz

Download URL charmcli-0.1.3.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d6385b0d0ecb090e8163e5562de7aefaeeb3209b23bf6d10666c6a91c64b6852
BLAKE2b-256 checksum
How to use checksums
948d0de8efc2c9590ca3e178c5bec59d76170157b1ab463e747b9e25fab18033
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.9

Release files / charmcli-0.1.3-py3-none-any.whl

Download URL charmcli-0.1.3-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a2a67429ebe0f7c1ef785a22a9605937d77ce2a922c37d7c244c5a1816bd666
BLAKE2b-256 checksum
How to use checksums
e7fba24e47d17d245d946fbb8a019f870b3e5d7c04cd6b0ea22cfc99a68cf870
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.9

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page