
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Generate a nice command line interface for a list of functions or a module, leveraging your doc-strings and type annotations.
Never worry about your Argparser being out of sync with your code.
Try it with pip install func_argparse
.
In a 'hello.py' file:
"""Say hello or goodbye to the user."""
import func_argparse
def hello(user: str, times: int = None):
"""Say hello.
Arguments:
user: name of the user
"""
print(f"Hello {user}" * (1 if times is None else times))
def bye(user: str, see_you: float = 1.0):
"""Say goodbye."""
print(f"Goodbye {user}, see you in {see_you:.1f} days")
if __name__ == "__main__":
func_argparse.main()
From CLI:
$ python hello.py hello --user gwenzek
Hello gwenzek
$ python hello.py hello --user gwenzek --times 2
Hello gwenzekHello gwenzek
$ python hello.py bye --user gwenzek --see_you 12.345
Goodbye gwenzek, see you in 12.3 days
$ python hello.py hello -u gwenzek -t 1
Hello gwenzek
$ python hello.py --help
usage: hello.py [-h] {hello,bye} ...
Say hello or goodbye to the user.
positional arguments:
{hello,bye}
hello Say hello.
bye Say goodbye.
optional arguments:
-h, --help show this help message and exit
$ python hello.py bye --help
usage: hello.py bye [-h] -u USER [-s SEE_YOU]
optional arguments:
-h, --help show this help message and exit
-u USER, --user USER
-s SEE_YOU, --see_you SEE_YOU
(default=1.0)
func_argparse
generate classics argparse.Argparser
you can mix and match them with hand-written parsers.func_argparse.main()
create one CLI command by "public" function from a file / module.func_argparse.single_main(my_main)
if you only have one entry point in your file.a
will generate two flags: --a
and --no-a
.False
.a
will also be available with the flag -a
.a
will be used to extract the documentation for argument a
.
Spaces, dashes and columns will be stripped before displaying.__command
when using main
or multi_parser
.override
function.Here are other alternatives you might be interested in.
func_argparse
is built. Grants a very precise control on the CLI but is a bit verbose and prone to go out-of-sync with the code.All contributions are welcome.
Code formatting is enforced with isort
, black
.
Types annotations are required for the main module and checked with mypy
.
Tests are run with pytest
.
Run pip install ".[dev]"
to install the required modules
Run ./tools.sh all
to format your code and run mypy
and pytest
.
add_argument
to override
FAQs
Generate CLI ArgumentParser from a function signature.
We found that func-argparse demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.