From c10df78db541925ea7dbaddc4631aa48fb174c7e Mon Sep 17 00:00:00 2001 From: baniasbaabe Date: Mon, 18 Nov 2024 19:15:45 +0100 Subject: [PATCH] add fire --- book/cooltools/Chapter.ipynb | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/book/cooltools/Chapter.ipynb b/book/cooltools/Chapter.ipynb index 6e466c6..3d5ea9c 100644 --- a/book/cooltools/Chapter.ipynb +++ b/book/cooltools/Chapter.ipynb @@ -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": {