gitmyhub

python-fire

Python ★ 28k updated 2mo ago

Python Fire is a library for automatically generating command line interfaces (CLIs) from absolutely any Python object.

Python Fire is a Google library that automatically turns any Python function, class, or object into a command-line tool with a single line of code, no argument parsing or boilerplate required.

Pythonsetup: easycomplexity 2/5

Python Fire is a library from Google that automatically turns any Python function, class, or object into a command-line tool with zero boilerplate. A CLI (command-line interface) is what lets you run a program from your terminal by typing a command with arguments — like python myscript.py --name=Alice. Normally, building a CLI requires writing argument parsing code. Fire eliminates that entirely.

The way it works: you write a regular Python function or class, then add one line — fire.Fire(your_function) — and Fire automatically generates a usable CLI for it. Arguments to the function become command-line flags, methods on a class become subcommands, and help text is generated automatically from docstrings. The README code examples show a hello function becoming a CLI where you can run python hello.py --name=David, and a Calculator class becoming a CLI where you run python calculator.py double 10.

Beyond just building tools, Fire is useful for debugging: you can launch an interactive REPL (an interactive Python session) from the command line with your module already loaded. It also supports shell tab completion and verbose tracing of commands.

You would use Python Fire when you want to quickly expose a Python script or class to the command line — for example, turning a utility script into a proper CLI tool in one line of code, or making it easy to experiment with functions interactively. It's a Python library installed via pip, licensed under Apache 2.0.

Where it fits