Python Command-line Application Tools

Related tags

clint
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
Issues
  • ColoredString depends on stdout.isatty() being True

    ColoredString depends on stdout.isatty() being True

    If stdout is redirected to a file or /dev/null then puts_err can't show colors because ColoredString has a hardcoded check for stdout.

    Feature Request Bug - Verified 
    opened by verigak 10
  • 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
  • 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
  • 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
  • Try a reimplementation of clint.textui.core

    Try a reimplementation of clint.textui.core

    I tried to reimplement clint.textui.core in a more simpler way.

    Here is my proposition, hope it helps.

    opened by Lothiraldan 7
  • Created: Added .travis.yml

    Created: Added .travis.yml

    I looked this issue(https://github.com/kennethreitz/clint/issues/89). I created .travis.yml. Can you setting Travis CI?

    opened by futoase 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
  • Python 3.8 SyntaxWarning fix

    Python 3.8 SyntaxWarning fix

    Starting in Python 3.8, this happened:

    The compiler now produces a SyntaxWarning when identity checks (is and is not) are used with certain types of literals (e.g. strings, numbers). These can often work by accident in CPython, but are not guaranteed by the language spec. The warning advises users to use equality tests (== and !=) instead. (Contributed by Serhiy Storchaka in bpo-34850.)

    This patch takes the official advice and makes a tweak.

    opened by palewire 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 0
  • 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
  • Do not require bundled args module

    Do not require bundled args module

    Hi, the args module isn't used, it shouldn't be listed here.

    opened by sbraz 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
  • Adds BooleanValidator, FloatValidator, ListValidator

    Adds BooleanValidator, FloatValidator, ListValidator

    Using Clint in a personal project I felt the need for additional validators. These three rose to the top of the pack.

    Would be happy to add tests, though I don't see how those are being handled right now in the current repo.

    opened by brianmego 2
  • Hide progress after end

    Hide progress after end

    It would be nice to have a way to "hide" the progress message when it's finished, but show it while it's being completed (right now it's all-or-nothing).

    @kennethreitz

    opened by ghost 0
  • PyPi module update

    PyPi module update

    At the moment, the version available on Pypi is version 0.5.1 (dated 2015-08-25) Is it possible to generate a new version and to make it available on Pypi please ? Or let me know the process to make it :) Thx !

    opened by jcdevil 1
  • Update progress.py

    Update progress.py

    Added changes in bar function and Bar class to use in resume downloading.

    opened by mpmman 1
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.5k Oct 25, 2021
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 1k Oct 25, 2021
Python Command-line Application Tools

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 57 Oct 12, 2021
Typer, build great CLIs. Easy to code. Based on Python type hints.

Typer, build great CLIs. Easy to code. Based on Python type hints. Documentation: https://typer.tiangolo.com Source Code: https://github.com/tiangolo/

Sebastián Ramírez 6.5k Oct 22, 2021
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 Sep 28, 2021
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 991 Oct 22, 2021
Python Fire is a library for automatically generating command line interfaces (CLIs) from absolutely any Python object.

Python Fire Python Fire is a library for automatically generating command line interfaces (CLIs) from absolutely any Python object. Python Fire is a s

Google 20.3k Oct 24, 2021
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 30.4k Oct 24, 2021
sane is a command runner made simple.

sane is a command runner made simple.

Miguel M. 14 Jul 24, 2021
A thin, practical wrapper around terminal capabilities in Python

Blessings Coding with Blessings looks like this... from blessings import Terminal t = Terminal() print(t.bold('Hi there!')) print(t.bold_red_on_brig

Erik Rose 1.3k Oct 19, 2021
plotting in the terminal

bashplotlib plotting in the terminal what is it? bashplotlib is a python package and command line tool for making basic plots in the terminal. It's a

Greg Lamp 1.6k Oct 17, 2021
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 11.5k Oct 24, 2021
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 2.6k Oct 23, 2021
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 7.3k Oct 23, 2021
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 250 Oct 15, 2021
A fast, stateless http slash commands framework for scale. Built by the Crunchy bot team.

Roid ?? A fast, stateless http slash commands framework for scale. Built by the Crunchy bot team. ?? Installation You can install roid in it's default

Harrison Burt 7 Oct 17, 2021
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 61 Oct 21, 2021
Textual is a TUI (Text User Interface) framework for Python using Rich as a renderer.

Textual is a TUI (Text User Interface) framework for Python using Rich as a renderer. The end goal is to be able to rapidly create rich termin

Will McGugan 5.8k Oct 17, 2021
A cross platform package to do curses-like operations, plus higher level APIs and widgets to create text UIs and ASCII art animations

ASCIIMATICS Asciimatics is a package to help people create full-screen text UIs (from interactive forms to ASCII animations) on any platform. It is li

null 2.8k Oct 23, 2021