Skip to main content

Quickstart

argcomb (argument combiner) is a simple utility that allows you to build complex command-line arguments in a modular fashion.

To install it:

pip install argcomb

Suppose we want to run the following combination of commands (e.g., if you're doing a hyperparameter sweep):

echo train --eta 0.1 --num-iters 5 --greedy
echo train --eta 0.1 --num-iters 5
echo train --eta 0.1 --num-iters 10 --greedy
echo train --eta 0.1 --num-iters 10

You can write the following argcomb program (called example1.py in this repo):

from argcomb import *

run(
    "echo", "train",
    arg("eta", 0.1),
    selarg(None, "num-iters", 5, 10),
    sel(None, [], arg("greedy")),
)

Here run takes a (hierarchical) list of arguments to be concatenated. Special functions like sel allow us to specify the selection/iteration over multiple possible values in place (as opposed to having a big for loop on the outside).

To run it:

# Actually executes the commands
python example1.py

# Print out the commands rather than execute them
python example1.py -n

We can also use environment variables (e.g., @mode) to parametrize the runs. For example:

from argcomb import *

run(
    "echo", "train",
    let_if_undefined("@mode", "slow"),  # Set default
    sel("@mode", {
        "fast": [arg("num-iters", 5), arg("greedy")],
        "slow": arg("num-iters", 10),
    }),
    arg("output", fmt("@mode.out")),
)

To run it:

python example.py             # slow (default)
python example.py @mode=fast  # fast

Development

Handy commands:

# Install environment
virtualenv -p python3.7 venv
venv/bin/pip install -r requirements.txt

# Format code (skip `example*.py`)
venv/bin/black -t py37 argcomb test_argcomb.py

# Do type checking
venv/bin/python -m mypy argcomb test_argcomb.py example*.py

# Run unit tests
venv/bin/python -m pytest test_argcomb.py

# Build PyPI package and deploy it
venv/bin/python setup.py sdist
venv/bin/twine upload dist/*

Release files for argcomb 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for argcomb 1.0.1
File Size Uploaded
argcomb-1.0.1.tar.gz 5.4 kB Details

Release files / argcomb-1.0.1.tar.gz

Download URL argcomb-1.0.1.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c5d884f80e3c2071f6d5b910960d666a16dbac5e7f3b5d6fd5b800ae0d78e77e
BLAKE2b-256 checksum
How to use checksums
de66e8fd90b282bc6153f89718967dd19d786485c9570b97b15a8dfc4337c8d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

Release history Release notifications | RSS feed

This release

1.0.1 This release

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page