python-click/README.rst

81 lines
2 KiB
ReStructuredText
Raw Normal View History

2018-09-06 20:55:10 +02:00
\$ click\_
==========
Click is a Python package for creating beautiful command line interfaces
2019-01-07 17:51:19 +01:00
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
2018-09-06 20:55:10 +02:00
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:
2019-01-07 17:51:19 +01:00
- Arbitrary nesting of commands
- Automatic help page generation
- Supports lazy loading of subcommands at runtime
2018-09-06 20:55:10 +02:00
Installing
----------
Install and update using `pip`_:
.. code-block:: text
2020-07-21 08:23:42 +02:00
$ pip install -U click
2018-09-06 20:55:10 +02:00
2021-10-10 03:31:57 +02:00
.. _pip: https://pip.pypa.io/en/stable/getting-started/
2018-09-06 20:55:10 +02:00
A Simple Example
----------------
.. code-block:: python
import click
2020-07-21 08:23:42 +02:00
2018-09-06 20:55:10 +02:00
@click.command()
2019-01-07 17:51:19 +01:00
@click.option("--count", default=1, help="Number of greetings.")
2020-07-21 08:23:42 +02:00
@click.option("--name", prompt="Your name", help="The person to greet.")
2018-09-06 20:55:10 +02:00
def hello(count, name):
"""Simple program that greets NAME for a total of COUNT times."""
2019-01-07 17:51:19 +01:00
for _ in range(count):
2020-07-21 08:23:42 +02:00
click.echo(f"Hello, {name}!")
2018-09-06 20:55:10 +02:00
if __name__ == '__main__':
hello()
.. code-block:: text
$ python hello.py --count=3
2019-01-07 17:51:19 +01:00
Your name: Click
Hello, Click!
Hello, Click!
Hello, Click!
2018-09-06 20:55:10 +02:00
Donate
------
2019-01-07 17:51:19 +01:00
The Pallets organization develops and supports Click and other popular
packages. In order to grow the community of contributors and users, and
2018-09-06 20:55:10 +02:00
allow the maintainers to devote more time to the projects, `please
donate today`_.
.. _please donate today: https://palletsprojects.com/donate
Links
-----
2020-07-21 08:23:42 +02:00
- Documentation: https://click.palletsprojects.com/
2021-10-10 03:31:57 +02:00
- Changes: https://click.palletsprojects.com/changes/
- PyPI Releases: https://pypi.org/project/click/
- Source Code: https://github.com/pallets/click
- Issue Tracker: https://github.com/pallets/click/issues
- Website: https://palletsprojects.com/p/click
- Twitter: https://twitter.com/PalletsTeam
- Chat: https://discord.gg/pallets