Skip to main content

Nested arguments parser

Project description

nestargs

nestargs is a Python library that defines nested program arguments. It is based on argparse.

PyPI PyPI - Python Version Python Tests codecov pre-commit.ci status

Installation

pip install nestargs

Basic usage

Define program arguments in the same way as argparse. A nested structure can be represented by putting a dot in the program argument name.

import nestargs

parser = nestargs.NestedArgumentParser()

parser.add_argument("--apple.n", type=int)
parser.add_argument("--apple.price", type=float)

parser.add_argument("--banana.n", type=int)
parser.add_argument("--banana.price", type=float)

args = parser.parse_args(
    ["--apple.n=2", "--apple.price=1.5", "--banana.n=3", "--banana.price=3.5"]
)
# => NestedNamespace(apple=NestedNamespace(n=2, price=1.5), banana=NestedNamespace(n=3, price=3.5))

Let's take out only the program argument apple.

args.apple
# => NestedNamespace(n=2, price=1.5)

You can also get each value.

args.apple.price
# => 1.5

If you want a dictionary format, you can get it this way.

vars(args.apple)
# => {'n': 2, 'price': 1.5}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nestargs-1.0.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nestargs-1.0.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file nestargs-1.0.0.tar.gz.

File metadata

  • Download URL: nestargs-1.0.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for nestargs-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6dd9e5d8c7c1ec63b373f43d837a3d271e206b01527c4ca4eb98cb762573a562
MD5 f0ab8dd4e3ce120e4b452b2ab86af058
BLAKE2b-256 cd861b28a9cac2f02d6abdbf48552cb58da58d1aae24068ceee497a333b1a38b

See more details on using hashes here.

File details

Details for the file nestargs-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: nestargs-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for nestargs-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b44a405032ff6c39e66a3b17e80504a7c9eea70f230fd54334cef67bc14a4d8
MD5 1a5bf7adaebe473dc1ab72812401bd55
BLAKE2b-256 2c452d5587a1dec773ded35521f616ce9f8a322f73bbb5c220d6ccce518ef76d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page