args
The 'args' library (version 0.1.0) by Kenneth Reitz is a minimalistic command-line argument parser designed to simplify access to arguments, flags, and assignments. Released in 2012, it provides a very basic interface for parsing command-line inputs. The library is considered abandoned, with its GitHub repository marked as an archive, and is no longer actively maintained. [2, 5]
Common errors
-
SyntaxError: Missing parentheses in call to 'print'
cause The library's examples and likely some internal logic are written using Python 2's `print` statement syntax, which is incompatible with Python 3's `print()` function.fixThis library is fundamentally Python 2. Using it in Python 3 requires either a Python 2 environment or a significant rewrite of the library to update `print` statements and other potential incompatibilities. It is generally recommended to use modern alternatives. -
AttributeError: 'module' object has no attribute 'some_named_argument'
cause The 'args' library does not parse named arguments (e.g., `--foo bar`) into directly accessible attributes like `args.foo`. It only provides broad categories like `args.all`, `args.flags`, `args.grouped`, and `args.assignments`. [2]fixAccess arguments via the provided collections (`args.all`, `args.flags`, `args.assignments`). For structured argument parsing with named arguments, use Python's built-in `argparse` module, which allows defining specific arguments and accessing them by name. [9, 11]
Warnings
- breaking The `args` library (v0.1.0) uses Python 2 `print` statements in its examples and internal logic. Running it directly on Python 3 will result in `SyntaxError` or other compatibility issues due to the `print` function change. The project is effectively Python 2 only.
- deprecated The `args` library is an archived project by Kenneth Reitz and has not been updated since 2012 (PyPI release) / 2018 (last GitHub activity). It is considered unmaintained and should not be used for new projects. [2, 5]
- gotcha The `args` library offers a very simplistic parsing model, unlike `argparse`. It does not support explicit argument definitions, types, default values, or subcommands. It categorizes arguments based on simple patterns (e.g., `--` for flags, `=` for assignments, `.txt` for files by default). [2]
Install
-
pip install args
Imports
- args
from args import ...
import args
Quickstart
import args
import sys
# Example usage for a script run as: python your_script.py arg1 --flag file.txt key=value
# Simulate command-line arguments for demonstration if run without actual CLI args
if len(sys.argv) == 1:
# Only if the script is run without arguments, use a simulated set
sys.argv.extend(['arg1', '--flag', 'file.txt', 'key=value'])
print(f'Arguments passed in: {args.all}')
print(f'Flags detected: {args.flags}')
print(f'Files detected: {args.files}')
print(f'NOT files detected: {args.not_files}')
print(f'Grouped Arguments: {args.grouped}')
print(f'Assignments detected: {args.assignments}')