Catalog npm
Back to packageRELEASE DETAILS

0.1.11

npm

argparse

Very powerful CLI arguments parser. Native port of argparse - python's options parsing library

argparseargsclioptionparser
Published7 Feb 2013
Direct dependencies3
Transitive dependenciesNot calculated

README

Current package documentation

argparse

CI NPM version

CLI arguments parser for node.js, with sub-commands support. Port of python's argparse (version 3.14.6).

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. Users upgrading from v2 should read the migration guide.

Example

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

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.

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.
  2. Original tutorial.
  3. Differences from Python.
  4. Migration from v2 to v3.

Downloads & popularity

28downloads
7-day window · source-reported counts20 Oct 2026
28140
2026-10-20: 28 · observed 2026-10-20T10:16:14.2149712Z
20 Oct20 Oct

npm · 1 observations shown. Missing days are unknown.

View observed values
Date / source periodValueObserved at
2026-10-20282026-10-20T10:16:14.2149712Z

Declared dependencies 3

Native requirements
3 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
underscore
Environment
{
  "local_name": "underscore",
  "alias": false,
  "peer_metadata": null
}
~1.4.3runtime
underscore.string
Environment
{
  "local_name": "underscore.string",
  "alias": false,
  "peer_metadata": null
}
~2.3.1runtime
mocha
Environment
{
  "local_name": "mocha",
  "alias": false,
  "peer_metadata": null
}
~1.8.1development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "c61031628629a24935badc7156714981d86ec819",
  "tarball": "https://registry.npmjs.org/argparse/-/argparse-0.1.11.tgz",
  "integrity": "sha512-Kqp2jpl2aFHoOZ6ejErEmFDA5IkhJoDSj/KvCyxd4kIRVVYr/I1R+PeukiWa0n0BtwisBioybafnjdSH3kRytg==",
  "signatures": [
    {
      "sig": "MEUCIAHzEXTPMVZWDDhS4inkje61IqYJs6k7Q3ZgMidDWn39AiEA5LohKSHdBSfnq3tgM40Wun4hyUBti6J8RruqKQjpdks=",
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
    }
  ]
}

Repository

PENDING
nodeca/argparse

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 08:26 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:f1e7bb83d86bcabb24c2c81ec7974cd6703d4a2603d47bfe7ee8fcde83c7c651

Other collected versions

3.0.315 Oct3.0.210 Sept3.0.125 Aug3.0.014 Jul2.0.128 Aug2.0.014 AugView all collected versions →