Click

Python 可合成的命令行接口工具包。(Python composable command line interface toolkit)

Github星跟蹤圖

$ click_

Click 是一个 Python 包,可以用尽可能少的代码以可组合的方式创建漂亮的命令行界面。它是 "命令行界面创建工具包"。它的可配置性很高,但开箱即有合理的默认值。

它的目的是让编写命令行工具的过程变得快速而有趣,同时也防止因无法实现预定的CLI API而造成的任何挫折感。

Click 的特性表现在三个方面:

  • 命令的任意嵌套。
  • 自动生成帮助页面。
  • 支持在运行时懒惰加载子命令。

安装

使用pip进行安装和更新。

$ pip install -U click

一个简单的示例

import click
@click.command()
@click.option("--count", default=1, help="Number of greetings.")
@click.option("--name", prompt="Your name", help="The person to greet.")
def hello(count, name):
    """Simple program that greets NAME for a total of COUNT times."""
    for _ in range(count):
        click.echo(f"Hello, {name}!")
if __name__ == '__main__':
    hello()
$ python hello.py --count=3
Your name: Click
Hello, Click!
Hello, Click!
Hello, Click!

捐献

Pallets 组织开发并支持Click和其他流行的软件包。为了发展贡献者和用户的社区,让维护者有更多的时间投入到项目中,请今天就捐款

链接


主要指標

概覽
名稱與所有者pallets/click
主編程語言Python
編程語言Python (語言數: 2)
平台Linux, Mac, Windows
許可證BSD 3-Clause "New" or "Revised" License
所有者活动
創建於2014-04-24 09:52:19
推送於2025-06-02 03:32:38
最后一次提交
發布數62
最新版本名稱8.2.1 (發布於 2025-05-20 19:10:46)
第一版名稱0.1 (發布於 )
用户参与
星數16.5k
關注者數183
派生數1.4k
提交數2.7k
已啟用問題?
問題數1648
打開的問題數106
拉請求數831
打開的拉請求數19
關閉的拉請求數356
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?

$ 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 "Command
Line Interface Creation Kit". It's highly configurable but comes with
sensible defaults out of the box.

It aims to make the process of writing command line tools quick and fun
while also preventing any frustration caused by the inability to
implement an intended CLI API.

Click in three points:

  • Arbitrary nesting of commands
  • Automatic help page generation
  • Supports lazy loading of subcommands at runtime

Installing

Install and update using pip_:

.. code-block:: text

$ pip install click

Click supports Python 3.4 and newer, Python 2.7, and PyPy.

.. _pip: https://pip.pypa.io/en/stable/quickstart/

A Simple Example

What does it look like? Here is an example of a simple Click program:

.. code-block:: python

import click

@click.command()
@click.option("--count", default=1, help="Number of greetings.")
@click.option("--name", prompt="Your name",
              help="The person to greet.")
def hello(count, name):
    """Simple program that greets NAME for a total of COUNT times."""
    for _ in range(count):
        click.echo("Hello, %s!" % name)

if __name__ == '__main__':
    hello()

And what it looks like when run:

.. code-block:: text

$ python hello.py --count=3
Your name: Click
Hello, Click!
Hello, Click!
Hello, Click!

The Pallets organization develops and supports Click and other popular
packages. In order to grow the community of contributors and users, and
allow the maintainers to devote more time to the projects, please donate today_.

.. _please donate today: https://palletsprojects.com/donate