{"id":7942,"library":"argbind","title":"ArgBind","description":"ArgBind is a compact Python library designed to simplify the binding of function or class arguments to the command line or YAML configuration files. It offers a scoping mechanism similar to frameworks like Hydra and gin-config, enabling the creation of complex and well-documented command-line programs. The library is small, comprising only around 400 lines of code, and is particularly useful for configuring machine learning experiments and other applications that benefit from flexible argument management. Its current version is 0.3.9.","status":"active","version":"0.3.9","language":"en","source_language":"en","source_url":"https://github.com/pseeth/argbind/","tags":["CLI","argument parsing","configuration","YAML","decorator","automation"],"install":[{"cmd":"pip install argbind","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required for YAML configuration file parsing.","package":"pyyaml","optional":false},{"reason":"Used for parsing function docstrings to generate argument help messages.","package":"docstring-parser","optional":false}],"imports":[{"symbol":"argbind","correct":"import argbind"},{"symbol":"bind","correct":"from argbind import bind\n# or use as decorator: @argbind.bind()"},{"symbol":"parse_args","correct":"from argbind import parse_args\n# or: args = argbind.parse_args()"},{"symbol":"scope","correct":"from argbind import scope\n# or: with argbind.scope(args):"},{"symbol":"load_args","correct":"from argbind import load_args\n# or: args = argbind.load_args('config.yaml')"}],"quickstart":{"code":"import argbind\n\n@argbind.bind()\ndef greet(name: str = 'World', excited: bool = False):\n    \"\"\"Greets the given name, optionally with excitement.\"\"\"\n    message = f\"Hello, {name}\"\n    if excited:\n        message += \"!\"\n    print(message)\n\nif __name__ == '__main__':\n    # In a real CLI, this would parse sys.argv\n    # For quickstart, simulate args or load from file\n    \n    # Example 1: Default execution\n    print('--- Running with defaults ---')\n    args_default = argbind.parse_args([]) # No CLI args provided\n    with argbind.scope(args_default):\n        greet()\n\n    # Example 2: Override from simulated CLI args\n    print('\\n--- Running with CLI override ---')\n    # Simulate `python your_script.py --greet.name Alice --greet.excited True`\n    args_cli = argbind.parse_args(['--greet.name', 'Alice', '--greet.excited', 'True'])\n    with argbind.scope(args_cli):\n        greet()\n\n    # Example 3: Load from a YAML file\n    print('\\n--- Running from YAML file ---')\n    config_content = \"\"\"\ngreet.name: Bob\ngreet.excited: False\n\"\"\"\n    with open('config.yaml', 'w') as f:\n        f.write(config_content)\n\n    args_yaml = argbind.load_args('config.yaml')\n    with argbind.scope(args_yaml):\n        greet()\n\n    # Clean up (optional for quickstart, but good practice)\n    import os\n    os.remove('config.yaml')","lang":"python","description":"This quickstart demonstrates how to define a function with `argbind.bind()`, parse arguments (either defaults, command-line, or from a YAML file), and execute the bound function within an `argbind.scope` context. Arguments are prefixed with the function name (e.g., `--greet.name`)."},"warnings":[{"fix":"For arguments that need to be dynamically flippable between `True` and `False` from both YAML and CLI, define them as `int` (0 or 1) instead of `bool`. For example, use `--func.arg 0` or `--func.arg 1` on the command line.","message":"Boolean arguments overridden from a YAML file cannot be easily unset (flipped to `False`) from the command line. If a boolean is `True` in YAML, passing `--func.arg False` may not work as expected.","severity":"gotcha","affected_versions":"All versions up to 0.3.9"},{"fix":"Avoid saving positional arguments within `.yml` files. Instead, use `.yml` files exclusively for keyword arguments, and pass positional arguments directly via the command line when running the script.","message":"Positional arguments specified in a `.yml` configuration file will override any positional arguments provided directly on the command line. This can lead to unexpected behavior if a user expects CLI arguments to always take precedence for positional parameters.","severity":"gotcha","affected_versions":"All versions up to 0.3.9"},{"fix":"Ensure that any function decorated with `@argbind.bind()` has a unique name. If you have similarly named functions in different modules, consider refactoring or using distinct aliases if ArgBind supported them (which it does not explicitly mention).","message":"Bound function names must be unique across your entire application. ArgBind resolves function arguments by their immediate function name, not their fully qualified path or module.","severity":"gotcha","affected_versions":"All versions up to 0.3.9"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `pip install argbind` in your terminal to install the library.","cause":"The 'argbind' library has not been installed in your Python environment.","error":"ModuleNotFoundError: No module named 'argbind'"},{"fix":"Understand ArgBind's argument priority: explicit Python code arguments > command-line arguments > YAML file arguments > default keyword arguments. Check your calls and configurations for conflicts and remove redundant argument specifications.","cause":"This typically occurs when an argument is provided through multiple mechanisms (e.g., command line, YAML file, and direct function call) and their priority is not correctly understood, or a default value is conflicting.","error":"TypeError: func() got multiple values for keyword argument 'arg'"},{"fix":"Redefine the problematic boolean argument as an integer (`int`) in your function signature, using `0` for `False` and `1` for `True`. Then, specify the value on the command line as `--func.arg 0` or `--func.arg 1`.","cause":"ArgBind has a known behavior where a boolean argument set to `True` in a YAML file cannot be overridden back to `False` using command-line arguments in certain scenarios.","error":"The boolean flag I'm passing on the command line isn't changing the value set in my YAML config."}]}