fire
A library for automatically generating command line interfaces.
Description
# Python Fire [](https://github.com/google/python-fire) _Python Fire is a library for automatically generating command line interfaces (CLIs) from absolutely any Python object._ - Python Fire is a simple way to create a CLI in Python. [[1]](docs/benefits.md#simple-cli) - Python Fire is a helpful tool for developing and debugging Python code. [[2]](docs/benefits.md#debugging) - Python Fire helps with exploring existing code or turning other people's code into a CLI. [[3]](docs/benefits.md#exploring) - Python Fire makes transitioning between Bash and Python easier. [[4]](docs/benefits.md#bash) - Python Fire makes using a Python REPL easier by setting up the REPL with the modules and variables you'll need already imported and created. [[5]](docs/benefits.md#repl) ## Installation To install Python Fire with pip, run: `pip install fire` To install Python Fire with conda, run: `conda install fire -c conda-forge` To install Python Fire from source, first clone the repository and then run: `python setup.py install` ## Basic Usage You can call `Fire` on any Python object:<br> functions, classes, modules, objects, dictionaries, lists, tuples, etc. They all work! Here's an example of calling Fire on a function. ```python import fire def hello(name="World"): return "Hello %s!" % name if __name__ == '__main__': fire.Fire(hello) ``` Then, from the command line, you can run: ```bash python hello.py # Hello World! python hello.py --name=David # Hello David! python hello.py --help # Shows usage information. ``` Here's an example of calling Fire on a class. ```python import fire class Calculator(object): """A simple calculator class.""" def double(self, number): return 2 * number if __name__ == '__main__': fire.Fire(Calculator) ``` Then, from the command line, you can run: ```bash python calculator.py double 10 # 20 python calculator.py double --number=15 # 30 ``` To learn how Fire behaves on functions, objects, dicts, lists, etc, and to learn about Fire's other features, see the [Using a Fire CLI page](docs/using-cli.md). For additional examples, see [The Python Fire Guide](docs/guide.md). ## Why is it called Fire? When you call `Fire`, it fires off (executes) your command. ## Where can I learn more? Please see [The Python Fire Guide](docs/guide.md). ## Reference | Setup | Command | Notes | :------ | :------------------ | :--------- | install | `pip install fire` | | Creating a CLI | Command | Notes | :--------------| :--------------------- | :--------- | import | `import fire` | | Call | `fire.Fire()` | Turns the current module into a Fire CLI. | Call | `fire.Fire(component)` | Turns `component` into a Fire CLI. | Using a CLI | Command | Notes | :---------------------------------------------- | :-------------------------------------- | :---- | [Help](docs/using-cli.md#help-flag) | `command --help` or `command -- --help` | | [REPL](docs/using-cli.md#interactive-flag) | `command -- --interactive` | Enters interactive mode. | [Separator](docs/using-cli.md#separator-flag) | `command -- --separator=X` | Sets the separator to `X`. The default separator is `-`. | [Completion](docs/using-cli.md#completion-flag) | `command -- --completion [shell]` | Generates a completion script for the CLI. | [Trace](docs/using-cli.md#trace-flag) | `command -- --trace` | Gets a Fire trace for the command. | [Verbose](docs/using-cli.md#verbose-flag) | `command -- --verbose` | _Note that these flags are separated from the Fire command by an isolated `--`._ ## License Licensed under the [Apache 2.0](https://github.com/google/python-fire/blob/master/LICENSE) License. ## Disclaimer This is not an official Google product.
Release History
| Version | Changes | Urgency | Date |
|---|---|---|---|
| 0.7.1 | Imported from PyPI (0.7.1) | Low | 4/21/2026 |
| v0.7.1 | ## What's Changed * Use Neutral theme for IPython Inspector, supporting newer IPython versions in https://github.com/google/python-fire/pull/588 * Call inspectutils.GetClassAttrsDict on component, not None in https://github.com/google/python-fire/pull/606 * Move to pyproject.toml, adding wheel support in pypi * Use ty in place of pytype * Update requirements @dependabot[bot] **Full Changelog**: https://github.com/google/python-fire/compare/v0.7.0...v0.7.1 | Low | 8/16/2025 |
| v0.7.0 | ## Notable in this release: * This release is the first to drop Python 2 support. For Python 2 users, use <= 0.6.0. * CI improvements from @Borda including dependabot and an expanded build matrix ## What's Changed * adding GH dependabot by @Borda in https://github.com/google/python-fire/pull/432 * Bump the pip group with 2 updates by @dependabot in https://github.com/google/python-fire/pull/491 * Update hypothesis requirement from <6.62.0 to <6.100.0 in /.github/scripts by @dependabot in | Low | 10/1/2024 |
| v0.6.0 | This is the last release supporting Python 2. Subsequent releases will be Python 3 only. The automatically generated release notes follow. ## What's Changed * Use literal dict to satisfy linter by @dbieber in https://github.com/google/python-fire/pull/430 * freeze CI requirements by @Borda in https://github.com/google/python-fire/pull/431 * Fix path to requirements.txt by @hugovk in https://github.com/google/python-fire/pull/433 * Fix deprecation warning: LICENSE is autodetected by @hugov | Low | 3/11/2024 |
| v0.5.0 | ## Changelist * Support for custom serializers with fire.Fire(serializer=your_serializer) #345 * Auto-generated help text now shows short arguments (e.g. -a) when appropriate #318 * Documentation improvements (#334, #399, #372, #383, #387) * Default values are now shown in help for kwonly arguments #414 * Completion script fix where previously completions might not show at all #336 ## Highlighted change: `fire.Fire(serialize=custom_serialize_fn)` #345 You can now pass a custom s | Low | 12/12/2022 |
| v0.4.0 | ## Changelist - Support for Python 3.8 and Python 3.9 - Argument types and defaults appear in help text - Support for asyncio coroutines - Support for modules and Python files with `python -m fire` - Keyword argument info from rst docstrings appears in help text - Bug fix for missing parts of multiline argument descriptions from Google and Numpy style docstrings. - Packaging of enum34 - Support functions even when they override getattr in non-standard ways. (e.g. supports BeautifulSoup) | Low | 1/22/2021 |
| v0.3.1 | Removes preexec_fn from pager subprocess call. Resolves #236. | Low | 4/7/2020 |
| v0.3.0 | ## Assorted Improvements in Python Fire v0.3.0 - Use Fire on third-party code without making any code changes: `python -m fire <module>` - Docstring parsing fix for all lines are blank f01aad347632791e3438c1a753e42a514520d690 - Improved parsing of numpy-style docstrings - #187 Expose built-in functions from the standard library (e.g. sin, cos) - #149 Support objects implementing \_\_getattr\_\_ - #205 Fix ctrl-C handling in help screens - Support functools.wraps and lru_cache decorated | Low | 3/24/2020 |
| v0.2.1 | Bug fixes - Improves robustness of docstring parser in the face of unexpected format docstrings. #183 | Low | 8/1/2019 |
| v0.2.0 | ## Python Fire v0.2.0 If you're new to Python Fire: 1) Welcome! 🎉 2) Fire automatically generates command line interfaces from _any_ Python object you give it. 🔥 e.g. You can call Fire on a function, as in this example (but you can also call Fire on _anything_ else: classes, objects, dicts, etc. -- they all work.) ``` def hello(name="World"): return "Hello %s!" % name fire.Fire(hello) ``` ``` hello.py --name=David # Hello David! ``` `pip install fire` to get started | Low | 7/26/2019 |
| v0.1.3 | This release has a few small improvements: - Do not treat arguments that start with '--' as strings [#99] - Fix for BinOps in args [#96] - six.u for Python 3 compatability in fuzz tests [#111] And a small packaging improvement: - Files in PyPi archive are world readable. [#107] | Low | 2/23/2018 |
| v0.1.2 | Improvements - IPython is fully optional! [#7] Now Fire's only dependency is six (the Python 2, 3 compatibility module) which is fairly light weight. If you use Fire without IPython, we call it "Fire Lite." Pun intended. - The command argument accepts lists [#53] fire.Fire's optional `command` argument now accepts either a sequence of arguments or a single string. Previously the `command` argument only accepted a string. - New mkdocs documentation We've started using mkdocs for | Low | 8/29/2017 |
| v0.1.1 | New Features - [The Python Fire Guide](https://github.com/google/python-fire/blob/master/doc/guide.md) is available - Support for annotations in functions - Support for keyword-only arguments in functions - Faster loading via lazy imports Bug Fixes - Serialize empty dictionaries - Serialize dictionaries with circular dependencies - Support non-comparable objects, numpy arrays, etc - Help for objects without source files - Completion scripts for top-level functions | Low | 5/21/2017 |
