Python Command-line Application Tools

Overview

Clint: Python Command-line Interface Tools

Clint is a module filled with a set of awesome tools for developing commandline applications.

https://raw.github.com/kennethreitz/clint/master/misc/clint.jpeg

C ommand L ine IN terface T ools .

Clint is awesome. Crazy awesome. It supports colors, but detects if the session is a TTY, so doesn't render the colors if you're piping stuff around. Automagically.

Awesome nest-able indentation context manager. Example: (with indent(4): puts('indented text')). It supports custom email-style quotes. Of course, it supports color too, if and when needed.

It has an awesome Column printer with optional auto-expanding columns. It detects how wide your current console is and adjusts accordingly. It wraps your words properly to fit the column size. With or without colors mixed in. All with a single function call.

The world's easiest to use implicit argument system w/ chaining methods for filtering. Seriously.

Run the various executables in examples to get a good feel for what Clint offers.

You'll never want to not use it.

https://travis-ci.org/kennethreitz/clint.png?branch=master

Current Features:

  • Little Documentation (bear with me for now)
  • CLI Colors and Indents
  • Extremely Simple + Powerful Column Printer
  • Iterator-based Progress Bar
  • Implicit Argument Handling
  • Simple Support for Incoming Unix Pipes
  • Application Directory management

Future Features:

  • Documentation!
  • Simple choice system Are you sure? [Yn]
  • Suggestions welcome.

Example

I want to indent my console text.

>>> from clint.textui import puts, indent

>>> puts('not indented text')
>>> with indent(4):
>>>     puts('indented text')
not indented text
    indented text

I want to quote my console text (like email).

>>> puts('not indented text')
>>> with indent(4, quote=' >'):
>>>     puts('quoted text')
>>>     puts('pretty cool, eh?')

not indented text
 >  quoted text
 >  pretty cool, eh?

I want to color my console text.

>>> from clint.textui import colored, puts

>>> puts(colored.red('red text'))
red text

# It's red in Windows, OSX, and Linux alike.

I want to get data piped to stdin.

>>> clint.piped_in()

# if no data was piped in, piped_in returns None

I want to get the first commandline argument passed in.

>>> from clint import arguments
>>> args = arguments.Args()
>>> args.get(0)

# if no argument was passed, get returns None

I want to store a configuration file.

>>> from clint import resources

>>> resources.init('Company', 'AppName')
>>> resources.user.write('config.ini', file_contents)

# OSX: '/Users/appuser/Library/Application Support/AppName/config.ini'
# Windows: 'C:\\Users\\appuser\\AppData\\Local\\Company\\AppName\\config.ini'
# Linux: '/home/appuser/.config/appname/config.ini'

I want to force color output even if stdout is not a TTY:

$ export CLINT_FORCE_COLOR=1

I want to ask for input.

>>> from clint.textui import prompt, validators
>>> path = prompt.query('Installation Path', default='/usr/local/bin/', validators=[validators.PathValidator()])

Installation

To install clint, simply:

$ pip install clint

Or, if you absolutely must:

$ easy_install clint

But, you really shouldn't do that.

License:

ISC License.

Copyright (c) 2011, Kenneth Reitz <[email protected]>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Contribute

If you'd like to contribute, simply fork the repository, commit your changes to the master branch (or branch off of it), and send a pull request. Make sure you add yourself to AUTHORS.

Roadmap

  • Unittests
  • Sphinx Documentation
Comments
  • 256-color terminal support

    256-color terminal support

    Very nice project, I've been pondering abut something like this for a while, and existing Python console support projects seem to have died a quiet death.

    A small feature request: Most terminals these days support 256 color (gnome, konsole, even old xterm/mrxvt). It'd be awesome if you could use these colors in Clint (for example, by setting colors as RGB and choosing the closest color). We're now in 2011 and 8-color text is old-fashioned :)

    I might get around to implementing this myself and submitting a patch. I have code for this in one of my other projects. (As for lists of R/G/B values, and/or color names, IPython could be an inspiration as it has a module for it)

    Feature Request 
    opened by laanwj 27
  • Use args module if installed, clint.packages.args otherwise

    Use args module if installed, clint.packages.args otherwise

    If args is installed (via setup.py install for example):

    >>> from clint import args
    >>> args
    <module 'args' from '/Users/lothiraldan/.virtualenvs/clint/lib/python2.7/site-packages/args.pyc'>
    

    If args is not installed:

    >>> from clint import args
    >>> args
    <module 'clint.packages.args' from 'clint/packages/args/__init__.pyc'>
    

    Hope it help. PS: Waiting for a new release.

    opened by Lothiraldan 9
  • PyPi package

    PyPi package

    Is the PyPi package (clint2 0.3.2 or clint 0.3.1) up to date? Neither package supports the expected_size arg in textui.progress.bar, though it appears to be in the current version of the code.

    opened by jastrauckas 8
  • IPython loses completion.

    IPython loses completion.

    If I open up IPython and import clint (or a submodule), completion stops working; e.g. if I press the 'up' button, it prints '^[[A' ; 'tab' inserts an actual tab.

    opened by Chris2048 8
  • Use print() function to fix install on python 3

    Use print() function to fix install on python 3

    clint 0.3.2 can't be installed on python 3.3 because of this print statement.

    Downloading/unpacking clint
      Running setup.py egg_info for package clint
        Traceback (most recent call last):
          File "<string>", line 16, in <module>
          File "/home/simon/lib/virtualenvs/clint/build/clint/setup.py", line 12, in <module>
            import clint
          File "./clint/__init__.py", line 22, in <module>
            from . import textui
          File "./clint/textui/__init__.py", line 17, in <module>
            from . import prompt
          File "./clint/textui/prompt.py", line 33
            print prompt
                       ^
        SyntaxError: invalid syntax
        Complete output from command python setup.py egg_info:
        Traceback (most recent call last):
    
      File "<string>", line 16, in <module>
    
      File "/home/simon/lib/virtualenvs/clint/build/clint/setup.py", line 12, in <module>
    
        import clint
    
      File "./clint/__init__.py", line 22, in <module>
    
        from . import textui
    
      File "./clint/textui/__init__.py", line 17, in <module>
    
        from . import prompt
    
      File "./clint/textui/prompt.py", line 33
    
        print prompt
    
                   ^
    
    SyntaxError: invalid syntax
    
    
    opened by saimn 7
  • rjust and ljust has wrong offset

    rjust and ljust has wrong offset

    >>> print "{}".format(colored.red("hello")).rjust(12)
    hello
    >>> print "{}".format(colored.red("hello")).rjust(20)
         hello
    >>> print "{}".format("hello").rjust(20)
                   hello
    
    opened by eproxus 7
  • data files installed in the wrong location

    data files installed in the wrong location

    The fix for issue 22 introduced a new problem. The data files are now installed in the top folder of the environment.

    To reproduce do:

    $ virtualenv-2.6 --distribute venv
    New python executable in venv/bin/python2.6
    ...
    $ cd venv/
    $ bin/pip install clint
    Downloading/unpacking clint
      Running setup.py egg_info for package clint
    Installing collected packages: clint
      Running setup.py install for clint
        warning: install_data: setup script did not provide a directory for 'README.rst' -- installing right in '/opt/tmp/venv'
        warning: install_data: setup script did not provide a directory for 'HISTORY.rst' -- installing right in '/opt/tmp/venv'
    Successfully installed clint
    Cleaning up...
    $ ls
    HISTORY.rst README.rst  bin     include     lib
    

    distutils even warns about this. In my case my own readme/history files are overwritten by this.

    I think to solve the issue you had, you just want to use a MANIFEST.in which will tell distutils to include the files in the sdist. There's no need to actually install them on the target system. If you want to install them as well, I'd use setuptools/distribute include_package_data option (http://packages.python.org/distribute/setuptools.html#including-data-files).

    opened by hannosch 7
  • Current repo is broken? (2012 Nov 15)

    Current repo is broken? (2012 Nov 15)

    After running into the broken colour on Windows problem which is apparently fixed in code but not in the current release (#75) I thought I'd download what is current from github (https://github.com/kennethreitz/clint/archive/develop.zip), but that seems to be broken completely:

    B:\code\clint>python setup.py
    Traceback (most recent call last):
      File "setup.py", line 12, in <module>
        import clint
      File "B:\code\clint\clint\__init__.py", line 21, in <module>
        from arguments import *
    ImportError: No module named arguments
    

    And it appears I'm not the only one, https://readthedocs.org/projects/clint/ says the builds have been failing for the last 7 weeks with a similar error:

    Exception occurred:
      File "/var/build/user_builds/clint/checkouts/latest/clint/__init__.py", line 21, in <module>
        from arguments import *
    ImportError: No module named arguments
    
    opened by maphew 6
  • Issue#145 textui.prompt.yn

    Issue#145 textui.prompt.yn

    issue #145 Hello , I'm not sure about what author exactly wanted this function do However , I try to fixed the boolean return value in textui.prompt.yn()function I agree issue #145 concerned about the output is more close to users' thoughts Testing code as issue #145

    from clint.textui import prompt
    
    for d in range(3):
        print(prompt.yn("Yes?"))
    
    for y in range(3):
        print(prompt.yn("Yes? default=y", default="y"))
    
    for n in range(3):
        print(prompt.yn("Yes? default=n", default="n"))
    
    • Before , output changed when no as default section
    Yes? default=n [y/N] y
    False
    Yes? default=n [y/N] n
    True
    Yes? default=n [y/N]
    False
    
    • After
    Yes? default=n [y/N] y
    True
    Yes? default=n [y/N] n
    False
    Yes? default=n [y/N] 
    False
    
    • The yn function's return value is now defined as
    yes  ->  return True
    
    no   ->  return False
    
    NULL string -> return True if default is 'y' else False
    
    opened by tz70s 5
  • Args integration

    Args integration

    clint.arguments was your inspiration for args module it seems... So just updating clint to reference it and reduce code duplication.

    Also i think i may want the flags capabilities in legit.

    opened by barberj 5
  • 0.3.2 release

    0.3.2 release

    I personnaly need some news features of clint in one of my project and wait for a new release of clint in order to release it. Is it planned for soon?

    opened by Lothiraldan 5
  • comparison using is/is not with string literal rasises SyntaxWarning

    comparison using is/is not with string literal rasises SyntaxWarning

    https://github.com/kennethreitz-archive/clint/blob/9d3693d644b8587d985972b6075d970096f6439e/clint/textui/prompt.py#L69

    This line uses 'is not' to compare variable with string literal. This should be '=' and in python 3.8 and later raises following warning.

    SyntaxWarning: "is not" with a literal. Did you mean "!="?

    opened by ijiraq 0
  • Change

    Change "is not" to "!=" to silence warning

    Running this code gives the following warning:

    /opt/homebrew/Cellar/gitless/0.8.8_7/libexec/lib/python3.9/site-packages/clint/textui/prompt.py:68: SyntaxWarning: "is not" with a literal. Did you mean "!="?
      if prompt[-1] is not ' ':
    
    opened by lalaithion 2
  • Replace identity check with equality check

    Replace identity check with equality check

    Due to the python 3.8 update, the compiler now raises a SyntaxWarning if it founds an identity check(is, is not) with a certain literal. This pr addresses that.

    opened by RushanKhan1 0
  • Documentation please

    Documentation please

    I really want learn to use clint! But, I don't seem to be able to find any reliable documentation. I think the world's CLI should have the world's best documentation¯_(ツ)_/¯

    But, jokes aside, I would be really grateful for some official documentation or at least some pointers on where to begin.

    EDIT: If possible can any of the viewers, help me?

    Thanks in advance!!

    opened by gr8-pro 0
  • Progress update

    Progress update

    changed string formatting to .format() which is way faster. added optional unit to add to your progress bar. e.g 10/100 MB. added a show_percent option for those that want their progress bar to show percentage as well as progress/expected size. added a progress bar with percent template.

    opened by mars-academy 0
Python composable command line interface toolkit

$ click_ Click is a Python package for creating beautiful command line interfaces in a composable way with as little code as necessary. It's the "Comm

The Pallets Projects 13.3k Dec 31, 2022
Library for building powerful interactive command line applications in Python

Python Prompt Toolkit prompt_toolkit is a library for building powerful interactive command line applications in Python. Read the documentation on rea

prompt-toolkit 8.1k Dec 30, 2022
Corgy allows you to create a command line interface in Python, without worrying about boilerplate code

corgy Elegant command line parsing for Python. Corgy allows you to create a command line interface in Python, without worrying about boilerplate code.

Jayanth Koushik 7 Nov 17, 2022
prompt_toolkit is a library for building powerful interactive command line applications in Python.

Python Prompt Toolkit prompt_toolkit is a library for building powerful interactive command line applications in Python. Read the documentation on rea

prompt-toolkit 8.1k Jan 4, 2023
Command line animations based on the state of the system

shell-emotions Command line animations based on the state of the system for Linux or Windows 10 The ascii animations were created using a modified ver

Simon Malave 63 Nov 12, 2022
Cleo allows you to create beautiful and testable command-line interfaces.

Cleo Create beautiful and testable command-line interfaces. Cleo is mostly a higher level wrapper for CliKit, so a lot of the components and utilities

Sébastien Eustace 984 Jan 2, 2023
Color text streams with a polished command line interface

colout(1) -- Color Up Arbitrary Command Output Synopsis colout [-h] [-r RESOURCE] colout [-g] [-c] [-l min,max] [-a] [-t] [-T DIR] [-P DIR] [-d COLORM

nojhan 1.1k Dec 21, 2022
Pythonic command line arguments parser, that will make you smile

docopt creates beautiful command-line interfaces Video introduction to docopt: PyCon UK 2012: Create *beautiful* command-line interfaces with Python N

null 7.7k Dec 30, 2022
A CLI tool to build beautiful command-line interfaces with type validation.

Piou A CLI tool to build beautiful command-line interfaces with type validation. It is as simple as from piou import Cli, Option cli = Cli(descriptio

Julien Brayere 310 Dec 7, 2022
A minimal and ridiculously good looking command-line-interface toolkit

Proper CLI Proper CLI is a Python package for creating beautiful, composable, and ridiculously good looking command-line-user-interfaces without havin

Juan-Pablo Scaletti 2 Dec 22, 2022
sane is a command runner made simple.

sane is a command runner made simple.

Miguel M. 22 Jan 3, 2023
Cement is an advanced Application Framework for Python, with a primary focus on CLI

Cement Framework Cement is an advanced Application Framework for Python, with a primary focus on Command Line Interfaces (CLI). Its goal is to introdu

Data Folk Labs, LLC 1.1k Dec 31, 2022
Clint is a module filled with a set of awesome tools for developing commandline applications.

Clint: Python Command-line Interface Tools Clint is a module filled with a set of awesome tools for developing commandline applications. C ommand L in

Kenneth Reitz Archive 82 Dec 28, 2022
A simple terminal Christmas tree made with Python

Python Christmas Tree A simple CLI Christmas tree made with Python Installation Just clone the repository and run $ python terminal_tree.py More opti

Francisco B. 64 Dec 27, 2022
Simple cross-platform colored terminal text in Python

Colorama Makes ANSI escape character sequences (for producing colored terminal text and cursor positioning) work under MS Windows. PyPI for releases |

Jonathan Hartley 3k Jan 1, 2023
Rich is a Python library for rich text and beautiful formatting in the terminal.

Rich 中文 readme • lengua española readme • Läs på svenska Rich is a Python library for rich text and beautiful formatting in the terminal. The Rich API

Will McGugan 41.4k Jan 2, 2023
emoji terminal output for Python

Emoji Emoji for Python. This project was inspired by kyokomi. Example The entire set of Emoji codes as defined by the unicode consortium is supported

Taehoon Kim 1.6k Jan 2, 2023
Python and tab completion, better together.

argcomplete - Bash tab completion for argparse Tab complete all the things! Argcomplete provides easy, extensible command line tab completion of argum

Andrey Kislyuk 1.1k Jan 8, 2023
Python library that measures the width of unicode strings rendered to a terminal

Introduction This library is mainly for CLI programs that carefully produce output for Terminals, or make pretend to be an emulator. Problem Statement

Jeff Quast 305 Dec 25, 2022