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

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 
  

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
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
A drop-in replacement for argparse that allows options to also be set via config files and/or environment variables.

ConfigArgParse Overview Applications with more than a handful of user-settable options are best configured through a combination of command line args,

null 634 Dec 22, 2022
A module for parsing and processing commands.

cmdtools A module for parsing and processing commands. Installation pip install --upgrade cmdtools-py install latest commit from GitHub pip install g

null 1 Aug 14, 2022
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 82 Dec 28, 2022
Fully Automated YouTube Channel ▶️with Added Extra Features.

Fully Automated Youtube Channel ▒█▀▀█ █▀▀█ ▀▀█▀▀ ▀▀█▀▀ █░░█ █▀▀▄ █▀▀ █▀▀█ ▒█▀▀▄ █░░█ ░░█░░ ░▒█░░ █░░█ █▀▀▄ █▀▀ █▄▄▀ ▒█▄▄█ ▀▀▀▀ ░░▀░░ ░▒█░░ ░▀▀▀ ▀▀▀░

sam-sepiol 249 Jan 2, 2023
A module filled with many useful functions and modules in various subjects.

Usefulpy Check out the Usefulpy site Usefulpy site is not always up to date Download and Import download and install with with pip download usefulpyth

Austin Garcia 1 Dec 28, 2021
Chess-commandline - Chess in the Command Line using the Chess Module Can detect Checkmates

chess-commandline Chess in the Command Line using the Chess Module Can detect Ch

Harry Hopkinson 1 Jan 10, 2022
This Telegram bot allows you to create direct links with pre-filled text to WhatsApp Chats

WhatsApp API Bot Telegram bot to create direct links with pre-filled text for WhatsApp Chats You can check our bot here. The bot is based on the API p

RobotTrick • רובוטריק 17 Aug 20, 2022
missing-pixel-filler is a python package that, given images that may contain missing data regions (like satellite imagery with swath gaps), returns these images with the regions filled.

Missing Pixel Filler This is the official code repository for the Missing Pixel Filler by SpaceML. missing-pixel-filler is a python package that, give

SpaceML 11 Jul 19, 2022
This is a repository filled with scripts that were made with Python, and designed to exploit computer systems.

PYTHON-EXPLOITATION This is a repository filled with scripts that were made with Python, and designed to exploit computer systems. Networking tcp_clin

Nathan Galindo 1 Oct 30, 2021
A Semi-Intelligent ChatBot filled with statistical and economical data for the Premier League.

MONEYBALL - ChatBot Module: 4006CEM, Class: B, Group: 5 Contributors: Jonas Djondo Roshan Kc Cole Samson Daniel Rodrigues Ihteshaam Naseer Kind remind

Jonas Djondo 1 Nov 18, 2021
Automatically download the cwru data set, and then divide it into training data set and test data set

Automatically download the cwru data set, and then divide it into training data set and test data set.自动下载cwru数据集,然后分训练数据集和测试数据集

null 6 Jun 27, 2022
Voxel Set Transformer: A Set-to-Set Approach to 3D Object Detection from Point Clouds (CVPR 2022)

Voxel Set Transformer: A Set-to-Set Approach to 3D Object Detection from Point Clouds (CVPR2022)[paper] Authors: Chenhang He, Ruihuang Li, Shuai Li, L

Billy HE 141 Dec 30, 2022
pyglet is a cross-platform windowing and multimedia library for Python, for developing games and other visually rich applications.

pyglet pyglet is a cross-platform windowing and multimedia library for Python, intended for developing games and other visually rich applications. It

null 1.3k Jan 1, 2023
Nasdaq Cloud Data Service (NCDS) provides a modern and efficient method of delivery for realtime exchange data and other financial information. This repository provides an SDK for developing applications to access the NCDS.

Nasdaq Cloud Data Service (NCDS) Nasdaq Cloud Data Service (NCDS) provides a modern and efficient method of delivery for realtime exchange data and ot

Nasdaq 8 Dec 1, 2022
Python commandline tool for remembering linux/terminal commands

ehh Remember linux commands Commandline tool for remembering linux/terminal commands. It stores your favorite commands in ~/ehh.json in your homedir a

null 56 Nov 10, 2022
Commandline Python app to Autodownload mediafire folders and files.

Commandline Python app to Autodownload mediafire folders and files.

Tharuk Renuja 3 May 12, 2022
Commandline script to interact with volkswagencarnet library

volkswagencarnet-client command line script to interact with volkswagencarnet library Table of Contents General Info Setup Usage Example Acknowledgeme

null 3 Jan 19, 2022
Zendesk Ticket Viewer is a lightweight commandline client for fetching and displaying tickets from a Zendesk account provided by the user

Zendesk Ticket Viewer is a lightweight commandline client for fetching and displaying tickets from a Zendesk account provided by the user.

Parthesh Soni 1 Jan 24, 2022