p-ranav/argparse: one C++17 header, a chained add_argument API and a long list of argument modes
Argument Parser for Modern C++
At a glance
- What is it?
- p-ranav/argparse is a single-header command-line parser for C++17 under the MIT license. It reads a program's argv through chained add_argument calls, and its last release, v3.2, dates from 25 January 2025.
- Who is it for?
- Use p-ranav/argparse if you write a C++17 command-line tool and want to declare arguments with chained calls, drop in one header, and get subcommands, flags and help output without linking a library. Pass on it if your toolchain stops at C++14 or older, or if you need behaviour the README headings do not mention.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 52 days ago.
- What is it written in?
- Mainly C++, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- p-ranav/argparse3,570 ★ · +6
| Repository | 2026-11-03 | 2026-11-25 |
|---|---|---|
| p-ranav/argparse | 3.6k | 3.6k |
6 Stars in the last 22 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Include argparse.hpp and nothing else is linked
The project's highlights are three lines long: single header file, requires C++17, MIT license. There is no library to build and no object file to link. You add the header to your include path and write this line:
#include <argparse/argparse.hpp>The repository nonetheless ships build files for several systems: CMakeLists.txt, BUILD.bazel with WORKSPACE.bazel, conanfile.py and xmake.lua, plus packaging/ and a module/ directory. They exist for people who want the header delivered through a package manager or imported as a CMake target, and the README has a CMake Integration section and a Building, Installing, and Testing section for that route.
The C++17 requirement is a real cutoff. A codebase pinned to C++14 or C++11 cannot take this header as is. The primary language is C++ and the repository is not archived. The last push was on 5 October 2026, while the newest tagged release, v3.2, dates from 25 January 2025, after v3.1 on 17 July 2024 and v3.0 on 6 November 2023.
Arguments are declared by calling add_argument on a parser object
A program creates an ArgumentParser, optionally giving a version string as the second constructor argument, as in argparse::ArgumentParser program("libfoo", "1.9.0"). Third and fourth arguments control the default arguments, for example default_arguments::help followed by false, and the README points to its Default Arguments section for what those do.
After that, add_argument registers each argument. It takes a variadic list of names that belong together, so program.add_argument("-v", "--verbose") declares a short and a long spelling of one option in a single call. A name without a dash prefix is a positional argument, and a name starting with - or -- is optional.
Methods chain off add_argument. The positional example uses .help(...) and .scan<'i', int>(). The optional example uses .help, .default_value(false) and .implicit_value(true). Parsing is a call to program.parse_args(argc, argv) inside a try block, and the README catches std::exception, prints err.what(), prints the program object itself and returns 1.
scan converts a string argument to int before get reads it
Command-line arguments arrive as strings, and the README's first full example shows the conversion step. This is the exact program:
#include <argparse/argparse.hpp>
int main(int argc, char *argv[]) {
argparse::ArgumentParser program("program_name");
program.add_argument("square")
.help("display the square of a given integer")
.scan<'i', int>();
try {
program.parse_args(argc, argv);
}
catch (const std::exception& err) {
std::cerr << err.what() << std::endl;
std::cerr << program;
return 1;
}
auto input = program.get<int>("square");
std::cout << (input * input) << std::endl;
return 0;
}Running ./main 15 prints 225. The scan method turns user input into an integer, and program.get<int>("square") reads the stored value back with the type you ask for. The README also has a Converting to Numeric Types section for the other numeric cases. That the template takes a letter and a type means the format character and the C++ type are chosen together, so a mismatch is yours to avoid.
Optional arguments are flags once implicit_value is set
An optional argument starts with - or --, for instance --verbose or -a, and can sit anywhere in the input sequence. The README's example pairs .default_value(false) with .implicit_value(true). The default makes the value false when the option is absent, so running without --verbose raises no error. The implicit value says the option takes no operand, and giving --verbose sets it to true. The check is program["--verbose"] == true.
Because that pair is common, the README adds a shorthand called flag(), which it says is the same as default_value(false).implicit_value(true).
The table of contents lists a further set of optional-argument behaviours, each with its own section: requiring an optional argument, accessing one without a default value, deciding whether the user supplied a value, joining values of repeated optional arguments, repeating an argument to increase a value, and a mutually exclusive group. Samples such as required_optional_argument.cpp, is_used.cpp, joining_repeated_optional_arguments.cpp and repeating_argument_to_increase_value.cpp in samples/ correspond to those headings.
Subcommands, parent parsers and parse_known_args cover larger tools
Beyond flags and positionals, the README's contents list the features a bigger tool needs. Subcommands have their own section and a sample, subcommands.cpp. Parent Parsers let arguments be shared. Getting Argument and Subparser Instances covers retrieving those objects after setup. Parse Known Args and Gathering Remaining Arguments handle input the parser was not told about, with parse_known_args.cpp and gathering_remaining_arguments.cpp as samples.
A section is devoted to the -- separator. Another covers Negative Numbers, which matters because a leading dash is otherwise the mark of an optional argument, and the samples include negative_numbers.cpp.
There are smaller knobs as well. Hidden arguments and aliases, using ArgumentParser in a bool context, custom prefix characters and custom assignment characters each get a section, with custom_prefix_characters.cpp and custom_assignment_characters.cpp in samples/. Under Further Examples the README also shows restricting the set of values for an argument and the option=value syntax.
Help output is built from help strings, a description and an epilog
Every add_argument call can carry a .help(...) string, and the parser prints itself with std::cerr << program. The README's catch blocks print the program object after an error, so a mistyped command line ends in the error text followed by the generated usage.
Separate sections cover Printing Help and Adding a description and an epilog to help, and the sample description_epilog_metavar.cpp shows description, epilog and metavar together. A section on Advanced usage formatting follows the further examples.
The README's excerpt does not show the exact layout of the generated help, so it is worth running a sample to see column alignment and wrapping before you depend on it. Version output works through the optional second constructor argument, as in the libfoo 1.9.0 example. The README does not state what the program prints in response.
Where it sits next to Python's argparse and other C++ parsers
The name and the add_argument call recall Python's standard-library argparse module, but this is a separate C++ project and nothing in the README claims compatibility. A reader porting a Python script should expect different details, such as scan<'i', int>() for type conversion in place of a type= argument.
Other C++ options include Boost.Program_options, which belongs to the Boost libraries, and CLI11, another header-oriented parser. The practical difference for p-ranav/argparse is its footprint: one header, no linking, C++17 required, and a declaration style where each argument is a chained expression. The README makes no comparison with either, so claims about speed or compile time would have no source here.
The checks that matter are the ones the README gives you. Build the samples in samples/ with your compiler, since the repository includes a samples/CMakeLists.txt and a samples/BUILD.bazel, and read the Supported Toolchains section for the compiler versions the project lists.
Storing values straight into variables and copying parsers
Two sections cover mechanics a reader meets after the first program. Storing values into variables is one: the anchor is #store-into, so an argument can write its parsed value into a variable you own instead of being read back through get.
The Developer Notes section has a Copying and Moving subsection. The README excerpt does not reproduce its rules, so anyone planning to return a parser from a function or keep one in a container should read that subsection first.
On the tooling side, the repository carries .clang-format and .clang-tidy, a clang_format.bash helper, a .travis.yml and a CONTRIBUTING.md. Tests live in test/, and tools/ holds supporting scripts. The README has a Contributing section pointing at that process.
Editorial conclusion
Use p-ranav/argparse if you write a C++17 command-line tool and want to declare arguments with chained calls, drop in one header, and get subcommands, flags and help output without linking a library. Pass on it if your toolchain stops at C++14 or older, or if you need behaviour the README headings do not mention. Before committing, build the closest file in samples/ against your compiler, since the README lists a Supported Toolchains section you should check against your own.
Frequently asked questions
What is p-ranav/argparse?
It is an argument parser for modern C++, delivered as a single header file that requires C++17 and carries an MIT license. You include argparse/argparse.hpp and declare arguments with add_argument.
How do you install p-ranav/argparse?
The README's Quick Start says to include argparse.hpp and you are good to go. Build files for CMake, Bazel, Conan and xmake are in the repository for people who want package-manager or target-based use.
Which C++ standard does p-ranav/argparse need?
It requires C++17. The README's highlights list this next to the single-header layout and the MIT license.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/p-ranav-argparse)Star history chart for your README
[](https://hysenlabs.com/projects/p-ranav-argparse)Was this useful?