Registry / devops / argbind

argbind

JSON →
library0.3.9pypypi✓ verified 35d ago

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.

devopsai-ml
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

import argbind
from argbind import bind # or use as decorator: @argbind.bind()
from argbind import parse_args # or: args = argbind.parse_args()
from argbind import scope # or: with argbind.scope(args):
from argbind import load_args # or: args = argbind.load_args('config.yaml')

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`).

import argbind @argbind.bind() def greet(name: str = 'World', excited: bool = False): """Greets the given name, optionally with excitement.""" message = f"Hello, {name}" if excited: message += "!" print(message) if __name__ == '__main__': # In a real CLI, this would parse sys.argv # For quickstart, simulate args or load from file # Example 1: Default execution print('--- Running with defaults ---') args_default = argbind.parse_args([]) # No CLI args provided with argbind.scope(args_default): greet() # Example 2: Override from simulated CLI args print('\n--- Running with CLI override ---') # Simulate `python your_script.py --greet.name Alice --greet.excited True` args_cli = argbind.parse_args(['--greet.name', 'Alice', '--greet.excited', 'True']) with argbind.scope(args_cli): greet() # Example 3: Load from a YAML file print('\n--- Running from YAML file ---') config_content = """ greet.name: Bob greet.excited: False """ with open('config.yaml', 'w') as f: f.write(config_content) args_yaml = argbind.load_args('config.yaml') with argbind.scope(args_yaml): greet() # Clean up (optional for quickstart, but good practice) import os os.remove('config.yaml')
argbind --version
Debug
Known footguns
gotchaBoolean 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.
gotchaPositional 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.
gotchaBound 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.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources