Skip to main content

Python library for rich text and beautiful formatting in the terminal.

Project description

Charmcli

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

Charmcli is a library for building CLI applications that users will love using and developers will love creating. Based on 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: It's easy to use for the final users. Automatic help, and automatic completion for all shells.
  • Short: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs.
  • 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
// 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

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

charmcli-0.1.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

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

charmcli-0.1.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file charmcli-0.1.0.tar.gz.

File metadata

  • Download URL: charmcli-0.1.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for charmcli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c218ea2299703c99c3db86683c9e998ceab6bb546e83b78f1ea621dd505817b4
MD5 6558916017fa12bc316f8d2eebb64721
BLAKE2b-256 40f2747a1bfa7a8f7be2caaea6693cb39c7c27e224ceb47cea4e15f023b995db

See more details on using hashes here.

File details

Details for the file charmcli-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: charmcli-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for charmcli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a21bacc292d82483020e7c86dded5e7d464655dbcc20f691ea5c1b36d09786da
MD5 bb55c86a092681f8476e97c3755d395c
BLAKE2b-256 c86fd709f9dba9316b914fa8c36798bb61fd19005d5cc3d5cd13650b19292ded

See more details on using hashes here.

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