---

title: Common utils


keywords: fastai
sidebar: home_sidebar

summary: "A collection of utilities often used."
description: "A collection of utilities often used."
nb_path: "nbs/utils/common_utils.ipynb"
---
<!--

#################################################
### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ###
#################################################
# file to edit: nbs/utils/common_utils.ipynb
# command to build the docs after a change: nbdev_build_docs

-->

<div class="container" id="notebook-container">
        
    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Download">Download<a class="anchor-link" href="#Download"> </a></h2>
</div>
</div>
</div>
    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="wget_download" class="doc_header"><code>wget_download</code><a href="https://github.com/RecoHut-Projects/recohut/tree/master/recohut/utils/common_utils.py#L26" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>wget_download</code>(<strong><code>url</code></strong>, <strong><code>savepath</code></strong>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="download_url" class="doc_header"><code>download_url</code><a href="https://github.com/RecoHut-Projects/recohut/tree/master/recohut/utils/common_utils.py#L31" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>download_url</code>(<strong><code>url</code></strong>:<code>str</code>, <strong><code>folder</code></strong>:<code>str</code>, <strong><code>log</code></strong>:<code>bool</code>=<em><code>True</code></em>)</p>
</blockquote>
<p>Downloads the content of an URL to a specific folder.
Args:
    url (string): The url.
    folder (string): The folder.
    log (bool, optional): If :obj:<code>False</code>, will not print anything to the
        console. (default: :obj:<code>True</code>)</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">download_url</span><span class="p">(</span><span class="s1">&#39;https://files.grouplens.org/datasets/movielens/ml-1m.zip&#39;</span><span class="p">,</span>
             <span class="s1">&#39;./data/bronze&#39;</span><span class="p">)</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">

<div class="output_subarea output_stream output_stderr output_text">
<pre>Downloading https://files.grouplens.org/datasets/movielens/ml-1m.zip
</pre>
</div>
</div>

<div class="output_area">



<div class="output_text output_subarea output_execute_result">
<pre>&#39;./data/bronze/ml-1m.zip&#39;</pre>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">!</span>tree ./data
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">

<div class="output_subarea output_stream output_stdout output_text">
<pre>./data
└── bronze
    └── ml-1m.zip

1 directory, 1 file
</pre>
</div>
</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="o">!</span>tree --du -h -C ./data
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">

<div class="output_subarea output_stream output_stdout output_text">
<pre><span class="ansi-blue-intense-fg ansi-bold">./data</span>
├── [ 24M]  <span class="ansi-blue-intense-fg ansi-bold">bronze</span>
│   └── [ 24M]  <span class="ansi-blue-intense-fg ansi-bold">ml-1m</span>
│       ├── [167K]  movies.dat
│       ├── [ 23M]  ratings.dat
│       ├── [5.4K]  README
│       └── [131K]  users.dat
└── [3.0M]  <span class="ansi-blue-intense-fg ansi-bold">silver</span>
    └── [3.0M]  <span class="ansi-blue-intense-fg ansi-bold">ml-1m_min_rating0-min_uc5-min_sc5-splitleave_one_out</span>
        └── [3.0M]  dataset.pkl

  27M used in 4 directories, 5 files
</pre>
</div>
</div>

</div>
</div>

</div>
    {% endraw %}

<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<hr>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Extract">Extract<a class="anchor-link" href="#Extract"> </a></h2>
</div>
</div>
</div>
    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="extract_tar" class="doc_header"><code>extract_tar</code><a href="https://github.com/RecoHut-Projects/recohut/tree/master/recohut/utils/common_utils.py#L68" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>extract_tar</code>(<strong><code>path</code></strong>:<code>str</code>, <strong><code>folder</code></strong>:<code>str</code>, <strong><code>mode</code></strong>:<code>str</code>=<em><code>'r:gz'</code></em>, <strong><code>log</code></strong>:<code>bool</code>=<em><code>True</code></em>)</p>
</blockquote>
<p>Extracts a tar archive to a specific folder.
Args:
    path (string): The path to the tar archive.
    folder (string): The folder.
    mode (string, optional): The compression mode. (default: :obj:<code>"r:gz"</code>)
    log (bool, optional): If :obj:<code>False</code>, will not print anything to the
        console. (default: :obj:<code>True</code>)</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="extract_zip" class="doc_header"><code>extract_zip</code><a href="https://github.com/RecoHut-Projects/recohut/tree/master/recohut/utils/common_utils.py#L82" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>extract_zip</code>(<strong><code>path</code></strong>:<code>str</code>, <strong><code>folder</code></strong>:<code>str</code>, <strong><code>log</code></strong>:<code>bool</code>=<em><code>True</code></em>)</p>
</blockquote>
<p>Extracts a zip archive to a specific folder.
Args:
    path (string): The path to the tar archive.
    folder (string): The folder.
    log (bool, optional): If :obj:<code>False</code>, will not print anything to the
        console. (default: :obj:<code>True</code>)</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="extract_bz2" class="doc_header"><code>extract_bz2</code><a href="https://github.com/RecoHut-Projects/recohut/tree/master/recohut/utils/common_utils.py#L95" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>extract_bz2</code>(<strong><code>path</code></strong>:<code>str</code>, <strong><code>folder</code></strong>:<code>str</code>, <strong><code>log</code></strong>:<code>bool</code>=<em><code>True</code></em>)</p>
</blockquote>
<p>Extracts a bz2 archive to a specific folder.
Args:
    path (string): The path to the tar archive.
    folder (string): The folder.
    log (bool, optional): If :obj:<code>False</code>, will not print anything to the
        console. (default: :obj:<code>True</code>)</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="extract_gz" class="doc_header"><code>extract_gz</code><a href="https://github.com/RecoHut-Projects/recohut/tree/master/recohut/utils/common_utils.py#L110" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>extract_gz</code>(<strong><code>path</code></strong>:<code>str</code>, <strong><code>folder</code></strong>:<code>str</code>, <strong><code>log</code></strong>:<code>bool</code>=<em><code>True</code></em>)</p>
</blockquote>
<p>Extracts a gz archive to a specific folder.
Args:
    path (string): The path to the tar archive.
    folder (string): The folder.
    log (bool, optional): If :obj:<code>False</code>, will not print anything to the
        console. (default: :obj:<code>True</code>)</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

<div class="cell border-box-sizing text_cell rendered"><div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<hr>

</div>
</div>
</div>
</div>
 

