Skip to content

Commit

Permalink
deploy: c10df78
Browse files Browse the repository at this point in the history
  • Loading branch information
baniasbaabe committed Nov 18, 2024
1 parent 07beefd commit 7f5bb35
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
50 changes: 50 additions & 0 deletions _sources/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
35 changes: 35 additions & 0 deletions book/cooltools/Chapter.html
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ <h2> Contents </h2>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#anonymize-pii-data-with-presidio">2.1.46. Anonymize PII Data with <code class="docutils literal notranslate"><span class="pre">presidio</span></code></a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#extract-skills-from-job-postings-with-skillner">2.1.47. Extract Skills from Job Postings with <code class="docutils literal notranslate"><span class="pre">skillner</span></code></a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#rate-limiting-fastapi-with-slowapi">2.1.48. Rate Limiting FastAPI with <code class="docutils literal notranslate"><span class="pre">slowapi</span></code></a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#create-cli-out-of-any-python-object-with-fire">2.1.49. Create CLI out of any Python Object with <code class="docutils literal notranslate"><span class="pre">fire</span></code></a></li>
</ul>
</nav>
</div>
Expand Down Expand Up @@ -1953,6 +1954,39 @@ <h2><span class="section-number">2.1.48. </span>Rate Limiting FastAPI with <code
</div>
</div>
</section>
<section id="create-cli-out-of-any-python-object-with-fire">
<h2><span class="section-number">2.1.49. </span>Create CLI out of any Python Object with <code class="docutils literal notranslate"><span class="pre">fire</span></code><a class="headerlink" href="#create-cli-out-of-any-python-object-with-fire" title="Permalink to this heading">#</a></h2>
<p>Transform any Python object into a CLI with <code class="docutils literal notranslate"><span class="pre">fire</span></code>.</p>
<p><code class="docutils literal notranslate"><span class="pre">fire</span></code> is a neat library for turn your Python object into a CLI and to make the transition between Python and Bash easier.</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span>!pip install fire
</pre></div>
</div>
</div>
</div>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># hello.py</span>
<span class="kn">import</span> <span class="nn">fire</span>

<span class="k">def</span> <span class="nf">hello</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">&quot;World&quot;</span><span class="p">):</span>
<span class="k">return</span> <span class="s2">&quot;Hello </span><span class="si">%s</span><span class="s2">!&quot;</span> <span class="o">%</span> <span class="n">name</span>

<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">&#39;__main__&#39;</span><span class="p">:</span>
<span class="n">fire</span><span class="o">.</span><span class="n">Fire</span><span class="p">(</span><span class="n">hello</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span>!python hello.py --name=David
</pre></div>
</div>
</div>
</div>
</section>
</section>

<script type="text/x-thebe-config">
Expand Down Expand Up @@ -2070,6 +2104,7 @@ <h2><span class="section-number">2.1.48. </span>Rate Limiting FastAPI with <code
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#anonymize-pii-data-with-presidio">2.1.46. Anonymize PII Data with <code class="docutils literal notranslate"><span class="pre">presidio</span></code></a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#extract-skills-from-job-postings-with-skillner">2.1.47. Extract Skills from Job Postings with <code class="docutils literal notranslate"><span class="pre">skillner</span></code></a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#rate-limiting-fastapi-with-slowapi">2.1.48. Rate Limiting FastAPI with <code class="docutils literal notranslate"><span class="pre">slowapi</span></code></a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#create-cli-out-of-any-python-object-with-fire">2.1.49. Create CLI out of any Python Object with <code class="docutils literal notranslate"><span class="pre">fire</span></code></a></li>
</ul>
</nav></div>

Expand Down
2 changes: 1 addition & 1 deletion searchindex.js

Large diffs are not rendered by default.

0 comments on commit 7f5bb35

Please sign in to comment.