Skip to main content...
Python (or Go) for Automation
20 min

Day 29: Building a small CLI tool

From script to tool

A script you run with hardcoded values becomes a real tool once it accepts arguments, prints help text, and handles bad input gracefully. Python's argparse gets you there without extra dependencies.

A minimal CLI with argparse
import argparse

parser = argparse.ArgumentParser(description='Check service health')
parser.add_argument('url', help='URL to check')
parser.add_argument('--timeout', type=int, default=5)
args = parser.parse_args()

print(f'Checking {args.url} with {args.timeout}s timeout...')
Using it
python healthcheck.py https://example.com --timeout 10
python healthcheck.py --help   # argparse generates this for free

Key terms

argparse
Python's standard library module for parsing command-line arguments and auto-generating --help text.

What does argparse give you for free that hand-parsing sys.argv does not?

We use cookies

We use cookies to enhance your browsing experience, serve personalized content, and analyze our traffic. By clicking "Accept All", you consent to our use of cookies. Learn more

    Day 29: Building a small CLI tool | RBTechIconX