#Argparse

sumanthvepasumanthvepa
2025-05-18

Had an enjoyable afternoon building a custom to replace 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.

A custom command line parser with a simple API.

@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

sumanthvepasumanthvepa
2025-05-17

It's probably a case of , but I've been really unhappy with the 's 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

github.com/sumanthvepa/experim

Kevin Bowen :xfce:kevinbowen@fosstodon.org
2025-05-08

Migrated my user-space environement over to #Python 3.14.0b1 today.

Nice to see the majority of the packages I use work without issue, so far.

Plus, I get that all that pretty colored output from #argparse!

#EyeCandy #Terminal #CLI

Terminal output from a python script showing colored output on a help command

usage: create_gh_issue_bug.py [-h] [-f {django,drf,flask,fastapi,all}] [--version]

run gh commands on groups of projects ordered by framework.

options:
  -h, -help         show this help message and exit
  -f, --framework {django,drf, flask, fastapi, all}
                    specify a web framework group to run commands on (default: None)
  --version         show program's version number and exit
2025-04-24

Huh, there is really no way in #Python #argparse to say "print full help, not only usage when an error occurs"?

I mean, besides
```
parser = argparse.ArgumentParser()
parser.format_usage = parser.format_help
```
(or similar monstrosities)

2024-12-27

TIL: #Python's #argparse module cannot parse arguments that start with a dash. It always expects them to be a flag and then throws an error if that flag is not defined.

github.com/python/cpython/issu

My use case: I have a command with subparsers/subcommands, and I'd like one of these subcommands to just take all of argv that follows its name and pass it on to someplace else.

mycmd subcmd foo -bar --baz

subcmd.add_argument("args", nargs="*") doesn't work.

Guess I'll have to resort to a hack.

Hugo van Kemenadehugovk
2024-11-14

🎉 Please welcome @savannah as the newest member of the Python core team!

She has recently been doing lots of excellent work on the new JIT and giving argparse some long-overdue attention.

discuss.python.org/t/vote-to-p

Savannah is the 9th new team member so far this year, which is the most we've had since 2012 🚀

hugovk.github.io/python-core-d

Bar chart of new core developers by year.

Starting in 1989 with one, there were one or two new core devs per year in the 90s.

The 2000s had around 10 added per year.

The 2010s had around 5 per year.

2020 had 5 new, 2021 had 3, 2022 had 8, 2023 had 5, and this year has had 8 so far.
Sarfraaz Ahmedasarfraaz
2024-09-19

🎖 Atomic Habits for Software Professionals
Using Streamlit for your data visualisation
Python Data Analytics Study Guide
Using argparse in Python

Read more in the latest edition of MyVoD at: eepurl.com/iZb4lU
Subscribe for more at: bit.ly/MyVoyageOf_Discovery

2024-09-05

@mhd I was quite fond of Amiga #CLI syntax, which many did not consider a proper #Amiga subsystem because of #BCPL, but it allowed commands to pre-declare the arguments in a uniform, documented way similar to Python’s #argparse.

It’s actually handled by BCPL’s rdargs() function, documented in cl.cam.ac.uk/~mr10/bcplman.pdf (p68).

1/2

2024-06-12

TIL that #python #argparse can't support negative floating numbers as arguments. Like, the bug is closed RESOLVED, even though if you read through the actual resolution is WONTFIX.

They just decided that argparse (in the stdlib!) is too complex to update and we should use a different library. So now I have to port my app and in the meantime "can't resolve ticket, bug is upstream" is not very satisfying.

Validates #rustlang's strategy of keeping std small to avoid exactly this type of issue.

skribe 🇺🇦 :verified_mustard:skribe@aus.social
2024-02-28

Is there an obvious way for argparse to check if the source file and destination file are the same? ie. the user has accidentally inputted the source file twice?

This doesn't work:

if args.source_file == args.dest_file:
do something

#Python #Argparse #Noob

Todd A. Jacobs | Rubyisttodd_a_jacobs@ruby.social
2024-02-09

@davetron5000 @budu @pragprog Sorry it's out of print. Some tech books have a limited lifespan, although @OReillyMedia sometimes keeps "generally useful but potentially outdated" stuff available for a long time, e.g. I think they still have the original Ruby book from Matz available, which was written for #RubyLang 1.8 or 1.9 and isn't fully applicable to Ruby 3.2.2. 🤷

#CLI argument parsing can be challenging no matter what you use. #Fishshell #argparse has a lot of limitations cf. GNU #getopt.

2023-09-22

Is it me? Or is 's library overly difficult. It seems like something I would have designed. We can do better.

2023-08-03

#TIL : #fishshell #argparse

"
This command makes it easy for fish scripts and functions to handle arguments.
"

Example from docs:
```
function mybetterfunction
argparse h/help s/second -- $argv
or return

if set -ql _flag_help
echo "mybetterfunction [-h|--help] [-s|--second] [ARGUMENT ...]"
return 0
end

if set -ql _flag_second
echo $argv[2]
else
echo $argv[1]
echo $argv[3]
end
end
```

fishshell.com/docs/current/cmd

2023-06-20

If you’re using #Python’s #argparse module to parse CLI arguments and want to have `--foo` and `--no-foo` flags, check out `action=argparse.BooleanOptionalAction`, which automatically creates `--no-foo` for you: docs.python.org/3/library/argp

parser.add_argument('--foo', action=argparse.BooleanOptionalAction)

Requires 3.9 though. Simple solution for 3.8:

parser.add_argument('--foo', action='store_true')
parser.add_argument('--no-foo', dest='foo', action='store_false')
parser.set_defaults(foo=True)

ISOserverThatWon'tFederateMetaanubhav@hachyderm.io
2023-06-13

Client Info

Server: https://mastodon.social
Version: 2025.04
Repository: https://github.com/cyevgeniy/lmst