bucket_helper.cli_argparse module

Bucket Helper — argparse-based command-line interface.

Thin wrapper around the pure functions in bucket_helper.main that exposes the whole toolkit as subcommands under a single bucket-helper entry point. Written with argparse from the standard library so the CLI works out of the box on any Python install that has the package installed — no extra dependency required.

Every subcommand reads credentials from --config (path to a JSON / YAML file, or a folder holding one, or empty for env-only). Under the hood we call bucket_helper.credentials(), so the same precedence order (JSON → YAML → .env → environment) applies here as in the library.

Subcommands

  • upload — send a local file to S3 (auto-key if omitted)

  • download — fetch an S3 object to a local path

  • delete — delete an S3 object (idempotent)

  • exists — probe whether an S3 object exists (exit code 0/1)

  • list — list keys under a prefix in the default bucket

  • make-bucket— create a bucket (no-op if it already exists)

  • tempfile — generate a unique random key + public URL (no upload)

  • strip-path — normalise s3://bucket/key into the key part

Usage Example

>>> #   bucket-helper upload      --config s3_config.json --input local.txt --key folder/uploaded.txt
>>> #   bucket-helper download    --config s3_config.json --key folder/uploaded.txt --output local.txt
>>> #   bucket-helper delete      --config s3_config.json --key folder/uploaded.txt
>>> #   bucket-helper exists      --config s3_config.json --key folder/uploaded.txt
>>> #   bucket-helper list        --config s3_config.json --prefix folder/
>>> #   bucket-helper make-bucket --config s3_config.json --bucket new-bucket
>>> #   bucket-helper tempfile    --config s3_config.json --ext json --prefix runs
>>> #   bucket-helper strip-path  --config s3_config.json --address s3://my-bucket/path/to/obj

Author

Warith Harchaoui, Ph.D. — https://linkedin.com/in/warith-harchaoui/

bucket_helper.cli_argparse.build_parser()[source]

Assemble the top-level bucket-helper argument parser.

Returns:

Fully wired parser with every subcommand attached.

Return type:

argparse.ArgumentParser

bucket_helper.cli_argparse.main(argv=None)[source]

Entry point invoked by bucket-helper (see [project.scripts]).

Parameters:

argv (sequence of str, optional) – Arguments to parse. Defaults to sys.argv[1:] when None.

Returns:

Process exit code (0 on success).

Return type:

int