# argparse

> CLI arguments parser. Native port of python's argparse.

Latest version **3.0.2** (published 2026-09-10) · PSF-2.0 license · 0 weekly downloads

## Install

```sh
npm install argparse
pnpm add argparse
yarn add argparse
bun add argparse
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2026-09-10 |
| First published | 2012-05-16 |
| Weekly downloads | 0 |
| License | PSF-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 173.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 512 |
| Maintainers | vitaly |
| Keywords | cli, parser, argparse, option, args |

## Links

- npm: https://www.npmjs.com/package/argparse
- Repository: https://github.com/nodeca/argparse
- Homepage: https://github.com/nodeca/argparse#readme
- Issues: https://github.com/nodeca/argparse/issues
- Funding: https://github.com/sponsors/puzrin
- npm.io page: https://npm.io/package/argparse

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 3.0.2 (latest) — 2026-09-10
- 3.0.1 — 2026-08-25
- 3.0.0 — 2026-07-14
- 2.0.1 — 2020-08-28
- 2.0.0 — 2020-08-14
- 1.0.10 — 2018-02-15
- 1.0.9 — 2016-09-29
- 1.0.8 — 2016-09-29
- 1.0.7 — 2016-03-17
- 1.0.6 — 2016-02-06
- 1.0.5 — 2016-02-05
- 1.0.4 — 2016-01-17
- 1.0.3 — 2015-10-27
- 1.0.2 — 2015-03-22
- 1.0.1 — 2015-02-20
- … 18 more at https://npm.io/package/argparse/versions

## README

argparse
========

[![CI](https://github.com/nodeca/argparse/actions/workflows/ci.yml/badge.svg)](https://github.com/nodeca/argparse/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/argparse.svg)](https://www.npmjs.org/package/argparse)

CLI arguments parser for node.js, with [sub-commands](https://docs.python.org/3.14/library/argparse.html#sub-commands) support. Port of python's [argparse](https://docs.python.org/3.14/library/argparse.html) (version [3.14.6](https://github.com/python/cpython/blob/v3.14.6/Lib/argparse.py)).

**Difference with original.**

- JS has no keyword arguments support.
  -  Pass options instead: `new ArgumentParser({ description: 'example', add_help: true })`.
- JS has no python's types `int`, `float`, ...
  - Use string-typed names: `.add_argument('-b', { type: 'int', help: 'help' })`.
- `%r` format specifier uses `require('util').inspect()`.

See the complete list of [differences from Python](./doc/port_difference.md).
Users upgrading from v2 should read the [migration guide](./doc/migrate_v2_to_v3.md).


Example
-------

Following code is a JS program that takes a list of integers and produces either the sum or the max:

```js
const { ArgumentParser } = require('argparse')

const parser = new ArgumentParser({ description: 'Process some integers.' })

let sum = ints => ints.reduce((a, b) => a + b)
let max = ints => ints.reduce((a, b) => a > b ? a : b)

parser.add_argument('integers', { metavar: 'N', type: 'int', nargs: '+',
                                  help: 'an integer for the accumulator' })
parser.add_argument('--sum',    { dest: 'accumulate', action: 'store_const',
                                  const: sum, default: max,
                                  help: 'sum the integers (default: find the max)' });

let args = parser.parse_args()
console.log(args.accumulate(args.integers))
```

Assuming the JS code above is saved into a file called prog.js, it can be run at the command line and provides useful help messages:

```
$ node prog.js -h
usage: prog.js [-h] [--sum] N [N ...]

Process some integers.

positional arguments:
  N           an integer for the accumulator

options:
  -h, --help  show this help message and exit
  --sum       sum the integers (default: find the max)
```

When run with the appropriate arguments, it prints either the sum or the max of the command-line integers:

```
$ node prog.js 1 2 3 4
4
$ node prog.js 1 2 3 4 --sum
10
```

If invalid arguments are passed in, it will issue an error:

```
$ node prog.js a b c
usage: prog.js [-h] [--sum] N [N ...]
prog.js: error: argument N: invalid 'int' value: 'a'
```

This is an example ported from Python. You can find detailed explanation [here](https://docs.python.org/3.14/library/argparse.html).


API docs
--------

Since this is a port with minimal divergence, there's no separate documentation.
Use original one instead, with notes about difference.

1. [Original doc](https://docs.python.org/3.14/library/argparse.html).
2. [Original tutorial](https://docs.python.org/3.14/howto/argparse.html).
3. [Differences from Python](./doc/port_difference.md).
4. [Migration from v2 to v3](./doc/migrate_v2_to_v3.md).

---
_Source: https://npm.io/package/argparse · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
