Python Fire 是用于从任意 Python 对象自动生成命令行接口(CLI)的库。
- Python Fire 可简便地创建 CLI。 [1]
- Python Fire 对开发与调试 Python 程序大有帮助。 [2]
- Python Fire 有助于探索现有代码或将他人代码转为 CLI。 [3]
- Python Fire 便利了 Bash 与 Python 间的转换。 [4]
- Python Fire 通过用已导入或创建的模块及变量设置 Python REPL(交互式解释器)使其使用更简单。 [5]
安装(这就没必要翻译了吧……)
To install Python Fire with pip, run:
To install Python Fire with conda, run:
To install Python Fire from source, first clone the repository and then run:
基本使用
你可以对任何 Python object 调用 ,比如:<br>
functions、classes、modules、objects、dictionaries、lists、tuples 等等。
这都将运行!
这里有一个对 function 调用 Fire 的示例:
然后你可以在命令行中执行:
这里有一个对 class 调用 Fire 的示例:
然后你可以在命令行中执行:
想要学习 Fire 在 functions、objects、dicts、lists 等上的表现及其其他特性参见 Using a Fire CLI page.
想要查看更多的例子,参见The Python Fire Guide.
Why is it called Fire?
When you call , it fires off (executes) your command.
Where can I learn more?
Please see The Python Fire Guide.
Reference
Setup | Command | Notes |
---|---|---|
install |
|
Creating a CLI | Command | Notes |
---|---|---|
import |
| |
Call |
| Turns the current module into a Fire CLI. |
Call |
| Turns into a Fire CLI. |
Using a CLI | Command | Notes |
---|---|---|
Help | or
| |
REPL |
| Enters interactive mode. |
Separator |
| Sets the separator to . The default separator is . |
Completion |
| Generates a completion script for the CLI. |
Trace |
| Gets a Fire trace for the command. |
Verbose |
|
Note that these flags are separated from the Fire command by an isolated .
License
Licensed under the Apache 2.0 License.
Disclaimer
This is not an official Google product.
比argparse好用多了