---

title: GhApi details


keywords: fastai
sidebar: home_sidebar

summary: "Detailed information on the GhApi API"
description: "Detailed information on the GhApi API"
nb_path: "00_core.ipynb"
---
<!--

#################################################
### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ###
#################################################
# file to edit: 00_core.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 %}

    {% 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">
<p>You can set an environment variable named <a href="/core.html#GH_HOST"><code>GH_HOST</code></a> to override the default of <code>https://api.github.com</code> incase you are running <a href="https://github.com/enterprise">GitHub Enterprise</a>(GHE).  However, this library has not been tested on GHE, so proceed at your own risk.</p>

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

</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>
    {% endraw %}

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

</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 ">
<h2 id="GhApi" class="doc_header"><code>class</code> <code>GhApi</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/core.py#L87" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>GhApi</code>(<strong><code>owner</code></strong>=<em><code>None</code></em>, <strong><code>repo</code></strong>=<em><code>None</code></em>, <strong><code>token</code></strong>=<em><code>None</code></em>, <strong><code>debug</code></strong>=<em><code>None</code></em>, <strong><code>limit_cb</code></strong>=<em><code>None</code></em>, <strong>**<code>kwargs</code></strong>) :: <code>_GhObj</code></p>
</blockquote>

</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">
<h3 id="Access-by-path">Access by path<a class="anchor-link" href="#Access-by-path"> </a></h3>
</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="GhApi.__call__" class="doc_header"><code>GhApi.__call__</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/core.py#L99" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>GhApi.__call__</code>(<strong><code>path</code></strong>:<code>str</code>, <strong><code>verb</code></strong>:<code>str</code>=<em><code>None</code></em>, <strong><code>headers</code></strong>:<code>dict</code>=<em><code>None</code></em>, <strong><code>route</code></strong>:<code>dict</code>=<em><code>None</code></em>, <strong><code>query</code></strong>:<code>dict</code>=<em><code>None</code></em>, <strong><code>data</code></strong>=<em><code>None</code></em>)</p>
</blockquote>
<p>Call a fully specified <code>path</code> using HTTP <code>verb</code>, passing arguments to <code>fastcore.core.urlsend</code></p>

</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="n">api</span> <span class="o">=</span> <span class="n">GhApi</span><span class="p">()</span>
</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">
<p>You can call a <a href="/core.html#GhApi"><code>GhApi</code></a> object as a function, passing in the path to the endpoint, the HTTP verb, and any route, query parameter, or post data parameters as required.</p>

</div>
</div>
</div>
    {% 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">api</span><span class="p">(</span><span class="s1">&#39;/repos/</span><span class="si">{owner}</span><span class="s1">/</span><span class="si">{repo}</span><span class="s1">/git/ref/</span><span class="si">{ref}</span><span class="s1">&#39;</span><span class="p">,</span> <span class="s1">&#39;GET&#39;</span><span class="p">,</span> <span class="n">route</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span>
    <span class="n">owner</span><span class="o">=</span><span class="s1">&#39;fastai&#39;</span><span class="p">,</span> <span class="n">repo</span><span class="o">=</span><span class="s1">&#39;ghapi-test&#39;</span><span class="p">,</span> <span class="n">ref</span><span class="o">=</span><span class="s1">&#39;heads/master&#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_markdown rendered_html output_subarea output_execute_result">
<ul>
<li>ref: refs/heads/master</li>
<li>node_id: MDM6UmVmMzE1NzEyNTg4OnJlZnMvaGVhZHMvbWFzdGVy</li>
<li>url: <a href="https://api.github.com/repos/fastai/ghapi-test/git/refs/heads/master">https://api.github.com/repos/fastai/ghapi-test/git/refs/heads/master</a></li>
<li>object: <ul>
<li>sha: 4fabc2fb4686c8b742511247372c5bc9f5a788df</li>
<li>type: commit</li>
<li>url: <a href="https://api.github.com/repos/fastai/ghapi-test/git/commits/4fabc2fb4686c8b742511247372c5bc9f5a788df">https://api.github.com/repos/fastai/ghapi-test/git/commits/4fabc2fb4686c8b742511247372c5bc9f5a788df</a></li>
</ul>
</li>
</ul>

</div>

</div>

</div>
</div>

</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="GhApi.__getitem__" class="doc_header"><code>GhApi.__getitem__</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/core.py#L118" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>GhApi.__getitem__</code>(<strong><code>k</code></strong>)</p>
</blockquote>
<p>Lookup and call an endpoint by path and verb (which defaults to 'GET')</p>

</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">
<p>You can access endpoints by indexing into the object. When using the API this way, you do not need to specify what type of parameter (route, query, or post data) is being used. This is, therefore, the same call as above:</p>

</div>
</div>
</div>
    {% 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">api</span><span class="p">[</span><span class="s1">&#39;/repos/</span><span class="si">{owner}</span><span class="s1">/</span><span class="si">{repo}</span><span class="s1">/git/ref/</span><span class="si">{ref}</span><span class="s1">&#39;</span><span class="p">](</span><span class="n">owner</span><span class="o">=</span><span class="s1">&#39;fastai&#39;</span><span class="p">,</span> <span class="n">repo</span><span class="o">=</span><span class="s1">&#39;ghapi-test&#39;</span><span class="p">,</span> <span class="n">ref</span><span class="o">=</span><span class="s1">&#39;heads/master&#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_markdown rendered_html output_subarea output_execute_result">
<ul>
<li>ref: refs/heads/master</li>
<li>node_id: MDM6UmVmMzE1NzEyNTg4OnJlZnMvaGVhZHMvbWFzdGVy</li>
<li>url: <a href="https://api.github.com/repos/fastai/ghapi-test/git/refs/heads/master">https://api.github.com/repos/fastai/ghapi-test/git/refs/heads/master</a></li>
<li>object: <ul>
<li>sha: 4fabc2fb4686c8b742511247372c5bc9f5a788df</li>
<li>type: commit</li>
<li>url: <a href="https://api.github.com/repos/fastai/ghapi-test/git/commits/4fabc2fb4686c8b742511247372c5bc9f5a788df">https://api.github.com/repos/fastai/ghapi-test/git/commits/4fabc2fb4686c8b742511247372c5bc9f5a788df</a></li>
</ul>
</li>
</ul>

</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">
<h3 id="Rate-limits">Rate limits<a class="anchor-link" href="#Rate-limits"> </a></h3>
</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">
<p>GitHub has various <a href="https://docs.github.com/en/free-pro-team@latest/rest/overview/resources-in-the-rest-api#rate-limiting">rate limits</a> for their API. After each call, the response includes information about how many requests are remaining in the hourly quota. If you'd like to add alerts, or indications showing current quota usage, you can register a callback with <a href="/core.html#GhApi"><code>GhApi</code></a> by passing a callable to the <code>limit_cb</code> parameter. This callback will be called whenever the amount of quota used changes. It will be called with two arguments: the new quota remaining, and the total hourly quota.</p>

</div>
</div>
</div>
    {% 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="k">def</span> <span class="nf">_f</span><span class="p">(</span><span class="n">rem</span><span class="p">,</span><span class="n">quota</span><span class="p">):</span> <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Quota remaining: </span><span class="si">{</span><span class="n">rem</span><span class="si">}</span><span class="s2"> of </span><span class="si">{</span><span class="n">quota</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>

<span class="n">api</span> <span class="o">=</span> <span class="n">GhApi</span><span class="p">(</span><span class="n">limit_cb</span><span class="o">=</span><span class="n">_f</span><span class="p">)</span>
<span class="n">api</span><span class="p">[</span><span class="s1">&#39;/repos/</span><span class="si">{owner}</span><span class="s1">/</span><span class="si">{repo}</span><span class="s1">/git/ref/</span><span class="si">{ref}</span><span class="s1">&#39;</span><span class="p">](</span><span class="n">owner</span><span class="o">=</span><span class="s1">&#39;fastai&#39;</span><span class="p">,</span> <span class="n">repo</span><span class="o">=</span><span class="s1">&#39;ghapi-test&#39;</span><span class="p">,</span> <span class="n">ref</span><span class="o">=</span><span class="s1">&#39;heads/master&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">ref</span>
</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>Quota remaining: 4872 of 5000
</pre>
</div>
</div>

<div class="output_area">



<div class="output_text output_subarea output_execute_result">
<pre>&#39;refs/heads/master&#39;</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">
<p>You can always get the remaining quota from the <code>limit_rem</code> attribute:</p>

</div>
</div>
</div>
    {% 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">api</span><span class="o">.</span><span class="n">limit_rem</span>
</pre></div>

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

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

<div class="output_area">



<div class="output_text output_subarea output_execute_result">
<pre>&#39;4872&#39;</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">
<h2 id="Operations">Operations<a class="anchor-link" href="#Operations"> </a></h2>
</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">
<p>Instead of passing a path to <a href="/core.html#GhApi"><code>GhApi</code></a>, you will more often use the operation methods provided in the API's operation groups, which include documentation, signatures, and auto-complete.</p>
<p>If you provide <code>owner</code> and/or <code>repo</code> to the constructor, they will be automatically inserted into any calls which use them (except when calling <a href="/core.html#GhApi"><code>GhApi</code></a> as a function). You can also pass any other arbitrary keyword arguments you like to have them used as defaults for any relevant calls.</p>
<p>You must include a GitHub API token if you need to access any authenticated endpoints. If don't pass the <code>token</code> param, then your <code>GITHUB_TOKEN</code> environment variable will be used, if available.</p>

</div>
</div>
</div>
    {% 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">api</span> <span class="o">=</span> <span class="n">GhApi</span><span class="p">(</span><span class="n">owner</span><span class="o">=</span><span class="s1">&#39;fastai&#39;</span><span class="p">,</span> <span class="n">repo</span><span class="o">=</span><span class="s1">&#39;ghapi-test&#39;</span><span class="p">,</span> <span class="n">token</span><span class="o">=</span><span class="n">token</span><span class="p">)</span>
</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">
<h3 id="Operation-groups">Operation groups<a class="anchor-link" href="#Operation-groups"> </a></h3>
</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">
<p>The following groups of endpoints are provided, which you can list at any time along with a link to documentation for all endpoints in that group, by displaying the <a href="/core.html#GhApi"><code>GhApi</code></a> object:</p>

</div>
</div>
</div>
    {% 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">api</span>
</pre></div>

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

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

<div class="output_area">


<div class="output_markdown rendered_html output_subarea output_execute_result">
<ul>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/actions">actions</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/activity">activity</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/apps">apps</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/billing">billing</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/checks">checks</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/code-scanning">code_scanning</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/codes-of-conduct">codes_of_conduct</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/emojis">emojis</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/enterprise-admin">enterprise_admin</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/gists">gists</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/git">git</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/gitignore">gitignore</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/interactions">interactions</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/issues">issues</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/licenses">licenses</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/markdown">markdown</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/meta">meta</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/migrations">migrations</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/oauth-authorizations">oauth_authorizations</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/orgs">orgs</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/projects">projects</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls">pulls</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/rate-limit">rate_limit</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/reactions">reactions</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/repos">repos</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/scim">scim</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/search">search</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/secret-scanning">secret_scanning</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/teams">teams</a></li>
<li><a href="https://docs.github.com/en/free-pro-team@latest/rest/reference/users">users</a></li>
</ul>

</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="n">api</span><span class="o">.</span><span class="n">codes_of_conduct</span>
</pre></div>

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

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

<div class="output_area">


<div class="output_markdown rendered_html output_subarea output_execute_result">
<ul>
<li><a href="https://docs.github.com/v3/codes_of_conduct/#get-all-codes-of-conduct">codes-of-conduct.get_all_codes_of_conduct</a>(): <em>Get all codes of conduct</em></li>
<li><a href="https://docs.github.com/v3/codes_of_conduct/#get-a-code-of-conduct">codes-of-conduct.get_conduct_code</a>(key): <em>Get a code of conduct</em></li>
<li><a href="https://docs.github.com/v3/codes_of_conduct/#get-the-code-of-conduct-for-a-repository">codes-of-conduct.get_for_repo</a>(): <em>Get the code of conduct for a repository</em></li>
</ul>

</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">
<h3 id="Calling-endpoints">Calling endpoints<a class="anchor-link" href="#Calling-endpoints"> </a></h3>
</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">
<p>The GitHub API's endpoint names generally start with a verb like "get", "list", "delete", "create", etc, followed <code>_</code>, then by a noun such as "ref", "webhook", "issue", etc.</p>
<p>Each endpoint has a different signature, which you can see by using <kbd>Shift</kbd>-<kbd>Tab</kbd> in Jupyter, or by just printing the endpoint object (which also shows a link to the GitHub docs):</p>

</div>
</div>
</div>
    {% 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="nb">print</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">repos</span><span class="o">.</span><span class="n">create_webhook</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_stdout output_text">
<pre>repos.create_webhook(name: str = None, config: dict = None, events: list = [&#39;push&#39;], active: bool = True)
https://docs.github.com/rest/reference/repos#create-a-repository-webhook
</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">
<p>Displaying an endpoint object in Jupyter also provides a formatted summary and link to the official GitHub documentation:</p>

</div>
</div>
</div>
    {% 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">api</span><span class="o">.</span><span class="n">repos</span><span class="o">.</span><span class="n">create_webhook</span>
</pre></div>

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

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

<div class="output_area">


<div class="output_markdown rendered_html output_subarea output_execute_result">
<p><a href="https://docs.github.com/rest/reference/repos#create-a-repository-webhook">repos.create_webhook</a>(name, config, events, active): <em>Create a repository webhook</em></p>

</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">
<p>Endpoint objects are called using standard Python method syntax:</p>

</div>
</div>
</div>
    {% 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">ref</span> <span class="o">=</span> <span class="n">api</span><span class="o">.</span><span class="n">git</span><span class="o">.</span><span class="n">get_ref</span><span class="p">(</span><span class="s1">&#39;heads/master&#39;</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">ref</span><span class="o">.</span><span class="n">object</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="s1">&#39;commit&#39;</span><span class="p">)</span>
</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">
<p>Information about the endpoint are available as attributes:</p>

</div>
</div>
</div>
    {% 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">api</span><span class="o">.</span><span class="n">git</span><span class="o">.</span><span class="n">get_ref</span><span class="o">.</span><span class="n">path</span><span class="p">,</span><span class="n">api</span><span class="o">.</span><span class="n">git</span><span class="o">.</span><span class="n">get_ref</span><span class="o">.</span><span class="n">verb</span>
</pre></div>

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

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

<div class="output_area">



<div class="output_text output_subarea output_execute_result">
<pre>(&#39;/repos/fastai/ghapi-test/git/ref/{ref}&#39;, &#39;get&#39;)</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">
<p>You can get a list of all endpoints available in a group, along with a link to documentation for each, by viewing the group:</p>

</div>
</div>
</div>
    {% 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">api</span><span class="o">.</span><span class="n">git</span>
</pre></div>

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

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

<div class="output_area">


<div class="output_markdown rendered_html output_subarea output_execute_result">
<ul>
<li><a href="https://docs.github.com/rest/reference/git#create-a-blob">git.create_blob</a>(content, encoding): <em>Create a blob</em></li>
<li><a href="https://docs.github.com/rest/reference/git#get-a-blob">git.get_blob</a>(file_sha): <em>Get a blob</em></li>
<li><a href="https://docs.github.com/rest/reference/git#create-a-commit">git.create_commit</a>(message, tree, parents, author, committer, signature): <em>Create a commit</em></li>
<li><a href="https://docs.github.com/rest/reference/git#get-a-commit">git.get_commit</a>(commit_sha): <em>Get a commit</em></li>
<li><a href="https://docs.github.com/rest/reference/git#list-matching-references">git.list_matching_refs</a>(ref, per_page, page): <em>List matching references</em></li>
<li><a href="https://docs.github.com/rest/reference/git#get-a-reference">git.get_ref</a>(ref): <em>Get a reference</em></li>
<li><a href="https://docs.github.com/rest/reference/git#create-a-reference">git.create_ref</a>(ref, sha, key): <em>Create a reference</em></li>
<li><a href="https://docs.github.com/rest/reference/git#update-a-reference">git.update_ref</a>(ref, sha, force): <em>Update a reference</em></li>
<li><a href="https://docs.github.com/rest/reference/git#delete-a-reference">git.delete_ref</a>(ref): <em>Delete a reference</em></li>
<li><a href="https://docs.github.com/rest/reference/git#create-a-tag-object">git.create_tag</a>(tag, message, object, type, tagger): <em>Create a tag object</em></li>
<li><a href="https://docs.github.com/rest/reference/git#get-a-tag">git.get_tag</a>(tag_sha): <em>Get a tag</em></li>
<li><a href="https://docs.github.com/rest/reference/git#create-a-tree">git.create_tree</a>(tree, base_tree): <em>Create a tree</em></li>
<li><a href="https://docs.github.com/rest/reference/git#get-a-tree">git.get_tree</a>(tree_sha, recursive): <em>Get a tree</em></li>
</ul>

</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">
<p>For "list" endpoints, the noun will be a plural form, e.g.:</p>

</div>
</div>
</div>
    {% 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">hooks</span> <span class="o">=</span> <span class="n">api</span><span class="o">.</span><span class="n">repos</span><span class="o">.</span><span class="n">list_webhooks</span><span class="p">()</span>
<span class="n">test_eq</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">hooks</span><span class="p">),</span> <span class="mi">0</span><span class="p">)</span>
</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">
<p>You can pass dicts, lists, etc. directly, where they are required for GitHub API endpoints:</p>

</div>
</div>
</div>
    {% 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">url</span> <span class="o">=</span> <span class="s1">&#39;https://example.com&#39;</span>
<span class="n">cfg</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">url</span><span class="o">=</span><span class="n">url</span><span class="p">,</span> <span class="n">content_type</span><span class="o">=</span><span class="s1">&#39;json&#39;</span><span class="p">,</span> <span class="n">secret</span><span class="o">=</span><span class="s1">&#39;XXX&#39;</span><span class="p">)</span>
<span class="n">hook</span> <span class="o">=</span> <span class="n">api</span><span class="o">.</span><span class="n">repos</span><span class="o">.</span><span class="n">create_webhook</span><span class="p">(</span><span class="n">config</span><span class="o">=</span><span class="n">cfg</span><span class="p">,</span> <span class="n">events</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;ping&#39;</span><span class="p">])</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">hook</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">url</span><span class="p">,</span> <span class="n">url</span><span class="p">)</span>
</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">
<p>Let's confirm that our new webhook has been created:</p>

</div>
</div>
</div>
    {% 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">hooks</span> <span class="o">=</span> <span class="n">api</span><span class="o">.</span><span class="n">repos</span><span class="o">.</span><span class="n">list_webhooks</span><span class="p">()</span>
<span class="n">test_eq</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">hooks</span><span class="p">),</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">hooks</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">events</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;ping&#39;</span><span class="p">])</span>
</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">
<p>Finally, we can delete our new webhook:</p>

</div>
</div>
</div>
    {% 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">api</span><span class="o">.</span><span class="n">repos</span><span class="o">.</span><span class="n">delete_webhook</span><span class="p">(</span><span class="n">hooks</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">id</span><span class="p">)</span>
</pre></div>

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

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

<div class="output_area">


<div class="output_markdown rendered_html output_subarea output_execute_result">

</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">
<h3 id="Convenience-functions">Convenience functions<a class="anchor-link" href="#Convenience-functions"> </a></h3>
</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="date2gh" class="doc_header"><code>date2gh</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/core.py#L127" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>date2gh</code>(<strong><code>dt</code></strong>:<code>datetime</code>)</p>
</blockquote>
<p>Convert <code>dt</code> (which is assumed to be in UTC time zone) to a format suitable for GitHub API operations</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">
<p>The GitHub API assumes that dates will be in a specific string format. <a href="/core.html#date2gh"><code>date2gh</code></a> converts Python standard <code>datetime</code> objects to that format. For instance, to find issues opened in the 'fastcore' repo in the last 4 weeks:</p>

</div>
</div>
</div>
    {% 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">dt</span> <span class="o">=</span> <span class="n">date2gh</span><span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">utcnow</span><span class="p">()</span> <span class="o">-</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">weeks</span><span class="o">=</span><span class="mi">4</span><span class="p">))</span>
<span class="n">issues</span> <span class="o">=</span> <span class="n">GhApi</span><span class="p">(</span><span class="s1">&#39;fastai&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">issues</span><span class="o">.</span><span class="n">list_for_repo</span><span class="p">(</span><span class="n">repo</span><span class="o">=</span><span class="s1">&#39;fastcore&#39;</span><span class="p">,</span> <span class="n">since</span><span class="o">=</span><span class="n">dt</span><span class="p">)</span>
<span class="nb">len</span><span class="p">(</span><span class="n">issues</span><span class="p">)</span>
</pre></div>

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

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

<div class="output_area">



<div class="output_text output_subarea output_execute_result">
<pre>2</pre>
</div>

</div>

</div>
</div>

</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="gh2date" class="doc_header"><code>gh2date</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/core.py#L132" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>gh2date</code>(<strong><code>dtstr</code></strong>:<code>str</code>)</p>
</blockquote>
<p>Convert date string <code>dtstr</code> received from a GitHub API operation to a UTC <code>datetime</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">created</span> <span class="o">=</span> <span class="n">issues</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">created_at</span>
<span class="nb">print</span><span class="p">(</span><span class="n">created</span><span class="p">,</span> <span class="s1">&#39;-&gt;&#39;</span><span class="p">,</span> <span class="n">gh2date</span><span class="p">(</span><span class="n">created</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_stdout output_text">
<pre>2020-12-28T12:52:59Z -&gt; 2020-12-28 12:52:59
</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">
<h3 id="Preview-endpoints">Preview endpoints<a class="anchor-link" href="#Preview-endpoints"> </a></h3>
</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">
<p>GitHub's preview API functionality requires a special header to be passed to enable it. This is added automatically for you.</p>

</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="print_summary" class="doc_header"><code>print_summary</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/core.py#L137" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>print_summary</code>(<strong><code>req</code></strong>:<code>Request</code>)</p>
</blockquote>
<p>Print <code>Request.summary</code> with the token (if any) removed</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">
<p>You can set the <code>debug</code> attribute to any callable to intercept all requests, for instance to print <code>Request.summary</code>. <a href="/core.html#print_summary"><code>print_summary</code></a> is provided for this purpose. Using this, we can see the preview header that is added for preview functionality, e.g.</p>

</div>
</div>
</div>
    {% 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">api</span><span class="o">.</span><span class="n">debug</span><span class="o">=</span><span class="n">print_summary</span>
<span class="n">api</span><span class="o">.</span><span class="n">codes_of_conduct</span><span class="o">.</span><span class="n">get_all_codes_of_conduct</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">api</span><span class="o">.</span><span class="n">debug</span><span class="o">=</span><span class="kc">None</span>
</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>{&#39;data&#39;: None,
 &#39;full_url&#39;: &#39;https://api.github.com/codes_of_conduct&#39;,
 &#39;headers&#39;: {&#39;Accept&#39;: &#39;application/vnd.github.scarlet-witch-preview+json&#39;},
 &#39;method&#39;: &#39;GET&#39;}
</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">
<h2 id="Convenience-methods">Convenience methods<a class="anchor-link" href="#Convenience-methods"> </a></h2>
</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">
<p>There are some multi-step processes in the GitHub API that <a href="/core.html#GhApi"><code>GhApi</code></a> provide convenient wrappers for. The methods currently available are shown below; do not hesitate to <a href="https://github.com/fastai/ghapi-test/issues">create an issue</a> or pull request if there are other processes that you'd like to see supported better.</p>

</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">
<h3 id="Releases">Releases<a class="anchor-link" href="#Releases"> </a></h3>
</div>
</div>
</div>
    {% 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="GhApi.upload_file" class="doc_header"><code>GhApi.upload_file</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/core.py#L149" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>GhApi.upload_file</code>(<strong><code>rel</code></strong>, <strong><code>fn</code></strong>)</p>
</blockquote>
<p>Upload <code>fn</code> to endpoint for release <code>rel</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="GhApi.create_release" class="doc_header"><code>GhApi.create_release</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/core.py#L158" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>GhApi.create_release</code>(<strong><code>tag_name</code></strong>, <strong><code>branch</code></strong>=<em><code>'master'</code></em>, <strong><code>name</code></strong>=<em><code>None</code></em>, <strong><code>body</code></strong>=<em><code>''</code></em>, <strong><code>draft</code></strong>=<em><code>False</code></em>, <strong><code>prerelease</code></strong>=<em><code>False</code></em>, <strong><code>files</code></strong>=<em><code>None</code></em>)</p>
</blockquote>
<p>Wrapper for <a href="/core.html#GhApi.repos.create_release"><code>GhApi.repos.create_release</code></a> which also uploads <code>files</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">
<p>Creating a release and attaching files to it is normally a multi-stage process, so <code>create_release</code> wraps this up for you. It takes the same arguments as <code>repos.create_release</code>, along with <code>files</code>, which can contain a single file name, or a list of file names to upload to your release:</p>

</div>
</div>
</div>
    {% 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">rel</span> <span class="o">=</span> <span class="n">api</span><span class="o">.</span><span class="n">create_release</span><span class="p">(</span><span class="s1">&#39;0.0.1&#39;</span><span class="p">,</span> <span class="n">files</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;docs/index.html&#39;</span><span class="p">])</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">rel</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s1">&#39;v0.0.1&#39;</span><span class="p">)</span>
</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="n">rels</span> <span class="o">=</span> <span class="n">api</span><span class="o">.</span><span class="n">repos</span><span class="o">.</span><span class="n">list_releases</span><span class="p">()</span>
<span class="n">test_eq</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">rels</span><span class="p">),</span> <span class="mi">1</span><span class="p">)</span>
</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">
<p>We can check that our file has been uploaded; GitHub refers to them as "assets":</p>

</div>
</div>
</div>
    {% 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">assets</span> <span class="o">=</span> <span class="n">api</span><span class="o">.</span><span class="n">repos</span><span class="o">.</span><span class="n">list_release_assets</span><span class="p">(</span><span class="n">rels</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">id</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">assets</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s1">&#39;index.html&#39;</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">assets</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">content_type</span><span class="p">,</span> <span class="s1">&#39;text/html&#39;</span><span class="p">)</span>
</pre></div>

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

</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="GhApi.delete_release" class="doc_header"><code>GhApi.delete_release</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/core.py#L142" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>GhApi.delete_release</code>(<strong><code>release</code></strong>)</p>
</blockquote>
<p>Delete a release and its associated tag</p>

</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">
<h3 id="Branches-and-tags">Branches and tags<a class="anchor-link" href="#Branches-and-tags"> </a></h3>
</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="GhApi.list_tags" class="doc_header"><code>GhApi.list_tags</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/core.py#L169" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>GhApi.list_tags</code>(<strong><code>prefix</code></strong>:<code>str</code>=<em><code>''</code></em>)</p>
</blockquote>
<p>List all tags, optionally filtered to those starting with <code>prefix</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">
<p>With no <code>prefix</code>, all tags are listed.</p>

</div>
</div>
</div>
    {% 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">test_eq</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">list_tags</span><span class="p">()),</span> <span class="mi">1</span><span class="p">)</span>
</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">
<p>Using the full tag name will return just that tag.</p>

</div>
</div>
</div>
    {% 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">test_eq</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">list_tags</span><span class="p">(</span><span class="n">rel</span><span class="o">.</span><span class="n">tag_name</span><span class="p">)),</span> <span class="mi">1</span><span class="p">)</span>
</pre></div>

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

</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="GhApi.list_branches" class="doc_header"><code>GhApi.list_branches</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/core.py#L175" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>GhApi.list_branches</code>(<strong><code>prefix</code></strong>:<code>str</code>=<em><code>''</code></em>)</p>
</blockquote>
<p>List all branches, optionally filtered to those starting with <code>prefix</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">
<p>Branches can be listed in the exactly the same way as tags.</p>

</div>
</div>
</div>
    {% 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">test_eq</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">list_branches</span><span class="p">(</span><span class="s1">&#39;master&#39;</span><span class="p">)),</span> <span class="mi">1</span><span class="p">)</span>
</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">
<p>We can delete our release and confirm that it is removed:</p>

</div>
</div>
</div>
    {% 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">api</span><span class="o">.</span><span class="n">delete_release</span><span class="p">(</span><span class="n">rels</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">test_eq</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">repos</span><span class="o">.</span><span class="n">list_releases</span><span class="p">()),</span> <span class="mi">0</span><span class="p">)</span>
</pre></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="GhApi.create_branch_empty" class="doc_header"><code>GhApi.create_branch_empty</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/core.py#L185" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>GhApi.create_branch_empty</code>(<strong><code>branch</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="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">ref</span> <span class="o">=</span> <span class="n">api</span><span class="o">.</span><span class="n">create_branch_empty</span><span class="p">(</span><span class="s2">&quot;testme&quot;</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">list_branches</span><span class="p">(</span><span class="s1">&#39;testme&#39;</span><span class="p">)),</span> <span class="mi">1</span><span class="p">)</span>
</pre></div>

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

</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="GhApi.delete_tag" class="doc_header"><code>GhApi.delete_tag</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/core.py#L191" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>GhApi.delete_tag</code>(<strong><code>tag</code></strong>:<code>str</code>)</p>
</blockquote>
<p>Delete a tag</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="GhApi.delete_branch" class="doc_header"><code>GhApi.delete_branch</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/core.py#L197" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>GhApi.delete_branch</code>(<strong><code>branch</code></strong>:<code>str</code>)</p>
</blockquote>
<p>Delete a branch</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">api</span><span class="o">.</span><span class="n">delete_branch</span><span class="p">(</span><span class="s1">&#39;testme&#39;</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">list_branches</span><span class="p">(</span><span class="s1">&#39;testme&#39;</span><span class="p">)),</span> <span class="mi">0</span><span class="p">)</span>
</pre></div>

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

</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="GhApi.get_branch" class="doc_header"><code>GhApi.get_branch</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/core.py#L203" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>GhApi.get_branch</code>(<strong><code>branch</code></strong>=<em><code>None</code></em>)</p>
</blockquote>

</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">
<h3 id="Content-(git-files)">Content (git files)<a class="anchor-link" href="#Content-(git-files)"> </a></h3>
</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="GhApi.list_files" class="doc_header"><code>GhApi.list_files</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/core.py#L209" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>GhApi.list_files</code>(<strong><code>branch</code></strong>=<em><code>None</code></em>)</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="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">files</span> <span class="o">=</span> <span class="n">api</span><span class="o">.</span><span class="n">list_files</span><span class="p">()</span>
<span class="n">files</span><span class="p">[</span><span class="s1">&#39;README.md&#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_markdown rendered_html output_subarea output_execute_result">
<ul>
<li>path: README.md</li>
<li>mode: 100644</li>
<li>type: blob</li>
<li>sha: 9b33a4362dda251455f7e4d99554467d1e6ba024</li>
<li>size: 66</li>
<li>url: <a href="https://api.github.com/repos/fastai/ghapi-test/git/blobs/9b33a4362dda251455f7e4d99554467d1e6ba024">https://api.github.com/repos/fastai/ghapi-test/git/blobs/9b33a4362dda251455f7e4d99554467d1e6ba024</a></li>
</ul>

</div>

</div>

</div>
</div>

</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="GhApi.get_content" class="doc_header"><code>GhApi.get_content</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/core.py#L216" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>GhApi.get_content</code>(<strong><code>path</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="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">readme</span> <span class="o">=</span> <span class="n">api</span><span class="o">.</span><span class="n">get_content</span><span class="p">(</span><span class="s1">&#39;README.md&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">decode</span><span class="p">()</span>
<span class="k">assert</span> <span class="s1">&#39;ghapi&#39;</span> <span class="ow">in</span> <span class="n">readme</span>
</pre></div>

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

</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="GhApi.update_contents" class="doc_header"><code>GhApi.update_contents</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/core.py#L222" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>GhApi.update_contents</code>(<strong><code>path</code></strong>, <strong><code>message</code></strong>=<em><code>None</code></em>, <strong><code>content</code></strong>=<em><code>None</code></em>, <strong><code>sha</code></strong>=<em><code>None</code></em>, <strong><code>branch</code></strong>=<em><code>None</code></em>, <strong><code>committer</code></strong>=<em><code>None</code></em>, <strong><code>author</code></strong>=<em><code>None</code></em>)</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="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">res</span> <span class="o">=</span> <span class="n">api</span><span class="o">.</span><span class="n">update_contents</span><span class="p">(</span>
    <span class="n">path</span><span class="o">=</span><span class="s1">&#39;README.md&#39;</span><span class="p">,</span>
    <span class="n">message</span><span class="o">=</span><span class="s2">&quot;Update README&quot;</span><span class="p">,</span>
    <span class="n">content</span><span class="o">=</span><span class="n">readme</span><span class="o">+</span><span class="s2">&quot;foobar&quot;</span>
<span class="p">)</span>
<span class="n">res</span><span class="o">.</span><span class="n">content</span><span class="o">.</span><span class="n">size</span>
</pre></div>

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

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

<div class="output_area">



<div class="output_text output_subarea output_execute_result">
<pre>72</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="n">readme</span> <span class="o">=</span> <span class="n">api</span><span class="o">.</span><span class="n">get_content</span><span class="p">(</span><span class="s1">&#39;README.md&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">decode</span><span class="p">()</span>
<span class="k">assert</span> <span class="s1">&#39;foobar&#39;</span> <span class="ow">in</span> <span class="n">readme</span>
<span class="n">api</span><span class="o">.</span><span class="n">update_contents</span><span class="p">(</span><span class="s1">&#39;README.md&#39;</span><span class="p">,</span> <span class="s2">&quot;Revert README&quot;</span><span class="p">,</span> <span class="n">content</span><span class="o">=</span><span class="n">readme</span><span class="p">[:</span><span class="o">-</span><span class="mi">6</span><span class="p">]);</span>
</pre></div>

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

</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="GhApi.enable_pages" class="doc_header"><code>GhApi.enable_pages</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/core.py#L232" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>GhApi.enable_pages</code>(<strong><code>branch</code></strong>=<em><code>None</code></em>, <strong><code>path</code></strong>=<em><code>'/'</code></em>)</p>
</blockquote>
<p>Enable or update pages for a repo to point to a <code>branch</code> and <code>path</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">
<p><code>branch</code> is set to the default branch if <code>None</code>. <code>path</code> must be <code>/docs</code> or <code>/</code>.</p>

</div>
</div>
</div>
    {% 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">res</span> <span class="o">=</span> <span class="n">api</span><span class="o">.</span><span class="n">enable_pages</span><span class="p">(</span><span class="n">branch</span><span class="o">=</span><span class="s1">&#39;new-branch&#39;</span><span class="p">,</span> <span class="n">path</span><span class="o">=</span><span class="s1">&#39;/&#39;</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">res</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">branch</span><span class="p">,</span> <span class="s1">&#39;new-branch&#39;</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">res</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">path</span><span class="p">,</span> <span class="s1">&#39;/&#39;</span><span class="p">)</span>
<span class="n">api</span><span class="o">.</span><span class="n">repos</span><span class="o">.</span><span class="n">delete_pages_site</span><span class="p">()</span>
<span class="n">api</span><span class="o">.</span><span class="n">delete_branch</span><span class="p">(</span><span class="s1">&#39;new-branch&#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_markdown rendered_html output_subarea output_execute_result">

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

</div>
 

