Skip to content

Commit

Permalink
add fire
Browse files Browse the repository at this point in the history
  • Loading branch information
baniasbaabe committed Nov 18, 2024
1 parent d88ad55 commit c10df78
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions book/cooltools/Chapter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2379,6 +2379,56 @@
"async def hello(request: Request):\n",
" return {\"response\":\"Hello\"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create CLI out of any Python Object with `fire`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Transform any Python object into a CLI with `fire`.\n",
"\n",
"`fire` is a neat library for turn your Python object into a CLI and to make the transition between Python and Bash easier."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install fire"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# hello.py\n",
"import fire\n",
"\n",
"def hello(name=\"World\"):\n",
" return \"Hello %s!\" % name\n",
"\n",
"if __name__ == '__main__':\n",
" fire.Fire(hello)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!python hello.py --name=David"
]
}
],
"metadata": {
Expand Down

0 comments on commit c10df78

Please sign in to comment.