For years, I’ve been writing Python scripts, everything from small utilities to automate repetitive work, for testing APIs, or to process data. And every time I wanted to make one of them accessible from the terminal, I ran into the same annoyance: argument parsing.
Sure, Python’s built-in argparse
works perfectly fine. But it’s verbose. Every time, I’d find myself writing a dozen lines of boilerplate just to pass a couple of arguments. If I wanted subcommands, things got messy fast.
So I did what every Python developer does: I started looking for “a better way.”
That’s when I stumbled across a small but surprisingly powerful library from Google called Fire.
And it completely changed the way I build CLIs.
What Is Google Fire?
Google Fire is a Python library that automatically generates command-line interfaces (CLIs) from any Python object, functions, classes, dictionaries, or even whole modules.
You don’t need to define command-line arguments manually.
You don’t need to handle type conversions.
You don’t even need to write a main()
function.
You just call fire.Fire()
, and your code instantly becomes a CLI.
Installation
Installing Fire is as simple as it gets:
pip install fire
No dependencies, no setup scripts, no configuration.

Stop guessing your financial route. PortfolioPilot.com is like Google Maps for your finances - guiding you step by step, from cutting fees to planning for retirement. Get personal financial advice today, free for 10 days, no credit card required.
Disclosure: PortfolioPilot is a technology product of Global Predictions Inc., an SEC registered investment adviser. Investing involves risk, including possible loss of principal. No guarantee of future results. Global Predictions does not provide tax advice. See full disclosures at globalpredictions.com/disclosures.
How Fire Works
Fire works by introspecting your Python objects.
When you call fire.Fire()
, it examines the function or class you pass in and exposes its attributes and methods as CLI commands.
For example:
- Each method of a class becomes a subcommand.
- Each parameter becomes a CLI argument.
- Keyword arguments (
def func(x=5)
) become optional flags.
So if you define:
def greet(name="world", excited=False):
msg = f"Hello, {name}!"
return msg.upper() if excited else msg
You can run it as:
python greet.py John
python greet.py John --excited True
and get:
Hello, John!
HELLO, JOHN!
Fire automatically detects the types of arguments and converts them when possible. It even understands nested structures, if your function returns a dictionary or an object, Fire lets you explore it interactively right from the command line.
Let's see the full script from the previous snippets:
import fire
def greet(name="world", excited=False):
msg = f"Hello, {name}!"
return msg.upper() if excited else msg
if __name__ == "__main__":
fire.Fire(greet)
If you enjoy practical Python content like this, check out my free developer resource pack here.
A More Realistic Example: Building a Quick Calculator
After that first “aha!” moment, I wanted to see how far I could push it.
What if I turned a class into a CLI?
This article is for subscribers only
To continue reading this article, just register your email and we will send you access.
Subscribe NowAlready have an account? Sign In