Building CLI Tools with Python: Click, Typer, and argparse

Compare Click, Typer, and argparse for building Python CLI tools. Learn practical implementation, best practices, and choose the right library for your project based on complexity, type safety, and performance.

Technical news about AI, coding and all

Just released! 🚀

🐍 Python 3.15 alpha 3!

https://discuss.python.org/t/python-3-15-0-alpha-3/105325?u=hugovk

🔬 PEP 799: A new high-frequency statistical sampling profiler and dedicated profiling package
💬 PEP 686: Python now uses UTF-8 as the default encoding
🌊 PEP 782: A new PyBytesWriter C API to create a Python bytes object
🎨 Colour code snippets in argparse help: https://bsky.app/profile/savannah.dev/post/3m7svdqdeqs2x
⚠️ Better error messages

#Python #Python315 #CPython #release #PEP799 #PEP686 #PEP782 #argparse

Python 3.15.0 alpha 3

This is an early developer preview of Python 3.15 Major new features of the 3.15 series, compared to 3.14 Python 3.15 is still in development. This release, 3.15.0a3, is the third of seven planned alpha releases. Alpha releases are intended to make it easier to test the current state of new features and bug fixes and to test the release process. During the alpha phase, features may be added up until the start of the beta phase (2026-05-05) and, if necessary, may be modified or deleted up un...

Discussions on Python.org

🎨 Old news: I added colour to argparse CLI help in last month's Python 3.14.

⭐ New news: I just added colour to ruff and ty's help so they can catch up (uv already had colour).

#Python #CLI #argparse #ruff #ty #uv #colour

Pythonを避けてきた理由やNeovimが好きになれない理由も似たような感じです。保守的なもので……

Pythonは2系から3系への破壊的移行は言うに及ばず、最近でもgetoptみたいな基本的な機能でゴタゴタしていたりとか、後方互換性という考えは無いんだろうなと思うとちょっと使いたくない感じです (使いますけど)

【Python3.14】getoptとoptparseが非推奨でなくなった #argparse - Qiita https://qiita.com/rana_kualu/items/2ec43820e70cc5885e00

Neovimは最近会社のPCで使っていいことになって (気付いたのは10/22ですがいつから使えたのかは不明)、Windows 11 23H2にアップデートしたところEmacsの起動に30分近く掛かるように (原因はWindowd Defenderのせいだろうなと見当はついているのですが管理者権限がないと手出しできないため解決不能) なったこともあり渡りに船と乗り換えたのですが、Vimからの移行を意識していそうな割にはOptionの規定値がVimと違うもの (hlsearchとか) がちらほらあって戸惑っています。
規定値の説明は確かにhelpにはあるけれど、そのことについて事前に知る手段は特にないので使ってみたら予想外の動作をして驚いて調べて比較してようやく気付く、という感じで不親切な印象は拭えず。
Vimだったら規定値は変えずにdafaults.vimで対応するところだよなあと思ったり。後方互換性(ry

【Python3.14】getoptとoptparseが非推奨でなくなった - Qiita

Pythonにはコマンドライン引数をパースする標準モジュールがgetopt・optparse・argparseの3種類あります。 このうちoptparseは14年も前の2011/02/20にリリースされた3.2から非推奨になっています。 そしてgetoptは先日2024/1...

Qiita

So my side side project to print out help for ALL the commands and subcommands and so on for an #Argparse app. Although it will make best efforts for other commands.

`totalhelp pipx` -- seems to work.
`totalhelp llm` -- incredibly slow.

also has library version for

`my_command --totalhelp` and it shows all the help for all the commands.

https://pypi.org/project/totalhelp/0.1.0/

Client Challenge

Parámetros Línea de Comandos. Python

{ROOR} Revista On-line Occam's Razor
Python argparse help formatter that keeps new lines and doesn't break words (so URLs are preserved), but still wraps lines. Use with: `argparse.ArgumentParser(formatter_class=SmartFormatter)`

Python argparse help formatter that keeps new lines and doesn't break words (so URLs are preserved), but still wraps lines. Use with: `argparse.ArgumentParser(formatter_class=SmartFormatter)` -...

Gist
Had an enjoyable afternoon building a custom #cli #parser to replace #argparse in our internal tooling. I like its ease of use. But it is a custom parser and works only for my specific use case, but for use case it does more than argparse can and is simpler to use. #comandline #python

@sumanthvepa

argparse is maybe-okay for simple things, but I don't use it for pretty much anything anymore. Have you tried one of the other extant packages that provide higher-level, more-powerful option handling?

I use `click` extensively for complex multiple-command CLI tools.

#click #optparse #argparse #CLI

It's probably a case of #bikesheding, but I've been really unhappy with the #python 's #argparse library for a while now. It's okay for run of the mill tools, but fails for more complex command line tools that have subcommands and complex options like --no-except to negate an option.

This is my first cut writing a command line parser for a #cli

https://github.com/sumanthvepa/experiments/tree/develop/python/parse-dralithus-cmdline

experiments/python/parse-dralithus-cmdline at develop · sumanthvepa/experiments

Experiments is a repository of programming experiments that I written to explore various aspects of programming and technology - sumanthvepa/experiments

GitHub