Skip to main content

A library for developing command-line applications in Python.

License PyPI Version Python Versions Documentation Downloads

The cmdkit library implements a few common patterns needed by well-formed command-line applications in Python. It only touches a few concepts but it implements them well. The idea is to reduce the boilerplate needed to get a full featured CLI off the ground. Applications developed using cmdkit are easy to implement, easy to maintain, and easy to understand.


Features

An Application class provides the boilerplate for a good entry-point. Building your command-line application in layers with ApplicationGroup let’s you develop simple structures and modules that mirror your CLI.

An Interface class modifies the behavior of the standard argparse.ArgumentParser class to raise simple exceptions instead of exiting.

class Add(Application):
    """Application class for adding routine."""

    interface = Interface('add', USAGE_TEXT, HELP_TEXT)
    interface.add_argument('-v', '--version', action='version', '0.0.1')

    lhs: int
    rhs: int
    interface.add_argument('lhs', type=float)
    interface.add_argument('rhs', type=float)

    def run(self) -> None:
        """Business logic of the application."""
        print(self.lhs + self.rhs)

A Configuration class makes it basically a one-liner to pull in a configuration with a dictionary-like interface from a cascade of files as well as expanding environment variables into a hierarchy and merged.

The standard behavior for any good application is for a configuration to allow for system-level, user-level, and local configuration to overlap. Merging these should not clobber the same section in a lower-priority source. The Namespace class extends the behavior of a standard Python dict to have a depth-first merge for its update implementation.

config = Configuration.from_local(env=True, prefix='MYAPP', default=default, **paths)

The underlying Namespace also supports the convention of having parameters with _env and _eval automatically expanded.

[database]
password_eval = "gpg ..."

Accessing the parameter with dot-notation, i.e., config.database.password would execute "gpg ..." as a shell command and return the output.


Installation

CmdKit is tested on Python 3.7+ for Windows, macOS, and Linux, and can be installed from the Python Package Index using Pip.

$ pip install cmdkit

Getting Started

Checkout the Tutorial for examples.

You can also checkout how CmdKit is being used by other projects, e.g., REFITT and HyperShell.


Documentation

Documentation for getting started, the API, and common recipes are available at cmdkit.readthedocs.io.


Contributions

Contributions are welcome in the form of suggestions for additional features, pull requests with new features or bug fixes, etc. If you find bugs or have questions, open an Issue here. If and when the project grows, a code of conduct will be provided along side a more comprehensive set of guidelines for contributing; until then, just be nice.

Metadata

Release files for cmdkit 2.5.0

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

Source distribution (sdist)

Source distribution for cmdkit 2.5.0
File Size Uploaded
cmdkit-2.5.0.tar.gz 26.6 kB Details

Built distribution (wheel)

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

Total release size: 55.0 kB

Release files / cmdkit-2.5.0.tar.gz

Download URL cmdkit-2.5.0.tar.gz
Size 26.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3f84567fb8b1f528e280451549ccdc19c039f166ef62ebd446bae04c9bf602c6
BLAKE2b-256 checksum
How to use checksums
b1e9c794b0e89a6c9d7a3a6c3e7ef49a85d24aa66a69a6df8c9022534a6ddf99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

Release files / cmdkit-2.5.0-py3-none-any.whl

Download URL cmdkit-2.5.0-py3-none-any.whl
Size 28.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f40e2a5752bc165fcd4ff1aa9f83d78255f2060d6bb931a416618c41e4dd78a3
BLAKE2b-256 checksum
How to use checksums
84561584de77b513debff9edf4a7e51b35fe02c2ac48ae7633a8c90b2db02a25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

Release history Release notifications | RSS feed

2.7.7

2 release files

2.7.6

2 release files

2.7.5

2 release files

2.7.4

2 release files

2.7.3

2 release files

2.7.2

2 release files

2.7.1

2 release files

2.6.1

2 release files

2.6.0

2 release files

2.5.1

2 release files

This release

2.5.0 This release

2 release files

2.4.0

2 release files

2.3.0

2 release files

2.2.3

2 release files

2.2.2

2 release files

2.2.1

3 release files

2.1.3

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.5.5

2 release files

1.5.4

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.1.0

1 release file

1.0.1

1 release file

0.0.4

1 release file

0.0.1

1 release file

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