This file is indexed.

/usr/share/doc/python-gitlab/html/api-usage.html is in python-gitlab-doc 1:1.3.0-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Getting started with the API &#8212; python-gitlab 1.3.0 documentation</title>
    <link rel="stylesheet" href="_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '1.3.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Switching to GitLab API v4" href="switching-to-v4.html" />
    <link rel="prev" title="gitlab CLI usage" href="cli.html" /> 
  </head>
  <body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="switching-to-v4.html" title="Switching to GitLab API v4"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="cli.html" title="gitlab CLI usage"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">python-gitlab 1.3.0 documentation</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="getting-started-with-the-api">
<h1>Getting started with the API<a class="headerlink" href="#getting-started-with-the-api" title="Permalink to this headline"></a></h1>
<p>python-gitlab supports both GitLab v3 and v4 APIs.</p>
<p>v3 being deprecated by GitLab, its support in python-gitlab will be minimal.
The development team will focus on v4.</p>
<p>v4 is the default API used by python-gitlab since version 1.3.0.</p>
<div class="section" id="gitlab-gitlab-class">
<h2><code class="docutils literal"><span class="pre">gitlab.Gitlab</span></code> class<a class="headerlink" href="#gitlab-gitlab-class" title="Permalink to this headline"></a></h2>
<p>To connect to a GitLab server, create a <code class="docutils literal"><span class="pre">gitlab.Gitlab</span></code> object:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">gitlab</span>

<span class="c1"># private token or personal token authentication</span>
<span class="n">gl</span> <span class="o">=</span> <span class="n">gitlab</span><span class="o">.</span><span class="n">Gitlab</span><span class="p">(</span><span class="s1">&#39;http://10.0.0.1&#39;</span><span class="p">,</span> <span class="n">private_token</span><span class="o">=</span><span class="s1">&#39;JVNSESs8EwWRx5yDxM5q&#39;</span><span class="p">)</span>

<span class="c1"># oauth token authentication</span>
<span class="n">gl</span> <span class="o">=</span> <span class="n">gitlab</span><span class="o">.</span><span class="n">Gitlab</span><span class="p">(</span><span class="s1">&#39;http://10.0.0.1&#39;</span><span class="p">,</span> <span class="n">oauth_token</span><span class="o">=</span><span class="s1">&#39;my_long_token_here&#39;</span><span class="p">)</span>

<span class="c1"># username/password authentication (for GitLab &lt;&lt; 10.2)</span>
<span class="n">gl</span> <span class="o">=</span> <span class="n">gitlab</span><span class="o">.</span><span class="n">Gitlab</span><span class="p">(</span><span class="s1">&#39;http://10.0.0.1&#39;</span><span class="p">,</span> <span class="n">email</span><span class="o">=</span><span class="s1">&#39;jdoe&#39;</span><span class="p">,</span> <span class="n">password</span><span class="o">=</span><span class="s1">&#39;s3cr3t&#39;</span><span class="p">)</span>

<span class="c1"># anonymous gitlab instance, read-only for public resources</span>
<span class="n">gl</span> <span class="o">=</span> <span class="n">gitlab</span><span class="o">.</span><span class="n">Gitlab</span><span class="p">(</span><span class="s1">&#39;http://10.0.0.1&#39;</span><span class="p">)</span>

<span class="c1"># make an API request to create the gl.user object. This is mandatory if you</span>
<span class="c1"># use the username/password authentication.</span>
<span class="n">gl</span><span class="o">.</span><span class="n">auth</span><span class="p">()</span>
</pre></div>
</div>
<p>You can also use configuration files to create <code class="docutils literal"><span class="pre">gitlab.Gitlab</span></code> objects:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">gl</span> <span class="o">=</span> <span class="n">gitlab</span><span class="o">.</span><span class="n">Gitlab</span><span class="o">.</span><span class="n">from_config</span><span class="p">(</span><span class="s1">&#39;somewhere&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;/tmp/gl.cfg&#39;</span><span class="p">])</span>
</pre></div>
</div>
<p>See the <a class="reference internal" href="cli.html#cli-configuration"><span class="std std-ref">Configuration</span></a> section for more information about
configuration files.</p>
<div class="section" id="note-on-password-authentication">
<h3>Note on password authentication<a class="headerlink" href="#note-on-password-authentication" title="Permalink to this headline"></a></h3>
<p>The <code class="docutils literal"><span class="pre">/session</span></code> API endpoint used for username/password authentication has
been removed from GitLab in version 10.2, and is not available on gitlab.com
anymore. Personal token authentication is the prefered authentication method.</p>
<p>If you need username/password authentication, you can use cookie-based
authentication. You can use the web UI form to authenticate, retrieve cookies,
and then use a custom <code class="docutils literal"><span class="pre">requests.Session</span></code> object to connect to the GitLab API.
The following code snippet demonstrates how to automate this:
<a class="reference external" href="https://gist.github.com/gpocentek/bd4c3fbf8a6ce226ebddc4aad6b46c0a">https://gist.github.com/gpocentek/bd4c3fbf8a6ce226ebddc4aad6b46c0a</a>.</p>
<p>See <a class="reference external" href="https://github.com/python-gitlab/python-gitlab/issues/380">issue 380</a>
for a detailed discussion.</p>
</div>
</div>
<div class="section" id="api-version">
<h2>API version<a class="headerlink" href="#api-version" title="Permalink to this headline"></a></h2>
<p><code class="docutils literal"><span class="pre">python-gitlab</span></code> uses the v4 GitLab API by default. Use the <code class="docutils literal"><span class="pre">api_version</span></code>
parameter to switch to v3:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">gitlab</span>

<span class="n">gl</span> <span class="o">=</span> <span class="n">gitlab</span><span class="o">.</span><span class="n">Gitlab</span><span class="p">(</span><span class="s1">&#39;http://10.0.0.1&#39;</span><span class="p">,</span> <span class="s1">&#39;JVNSESs8EwWRx5yDxM5q&#39;</span><span class="p">,</span> <span class="n">api_version</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">The python-gitlab API is not the same for v3 and v4. Make sure to read
<a class="reference internal" href="switching-to-v4.html#switching-to-v4"><span class="std std-ref">Switching to GitLab API v4</span></a> if you are upgrading from v3.</p>
</div>
</div>
<div class="section" id="managers">
<h2>Managers<a class="headerlink" href="#managers" title="Permalink to this headline"></a></h2>
<p>The <code class="docutils literal"><span class="pre">gitlab.Gitlab</span></code> class provides managers to access the GitLab resources.
Each manager provides a set of methods to act on the resources. The available
methods depend on the resource type.</p>
<p>Examples:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="c1"># list all the projects</span>
<span class="n">projects</span> <span class="o">=</span> <span class="n">gl</span><span class="o">.</span><span class="n">projects</span><span class="o">.</span><span class="n">list</span><span class="p">()</span>
<span class="k">for</span> <span class="n">project</span> <span class="ow">in</span> <span class="n">projects</span><span class="p">:</span>
    <span class="k">print</span><span class="p">(</span><span class="n">project</span><span class="p">)</span>

<span class="c1"># get the group with id == 2</span>
<span class="n">group</span> <span class="o">=</span> <span class="n">gl</span><span class="o">.</span><span class="n">groups</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="k">for</span> <span class="n">group</span> <span class="ow">in</span> <span class="n">groups</span><span class="p">:</span>
    <span class="k">print</span><span class="p">()</span>

<span class="c1"># create a new user</span>
<span class="n">user_data</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;email&#39;</span><span class="p">:</span> <span class="s1">&#39;jen@foo.com&#39;</span><span class="p">,</span> <span class="s1">&#39;username&#39;</span><span class="p">:</span> <span class="s1">&#39;jen&#39;</span><span class="p">,</span> <span class="s1">&#39;name&#39;</span><span class="p">:</span> <span class="s1">&#39;Jen&#39;</span><span class="p">}</span>
<span class="n">user</span> <span class="o">=</span> <span class="n">gl</span><span class="o">.</span><span class="n">users</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">user_data</span><span class="p">)</span>
<span class="k">print</span><span class="p">(</span><span class="n">user</span><span class="p">)</span>
</pre></div>
</div>
<p>You can list the mandatory and optional attributes for object creation
with the manager’s <code class="docutils literal"><span class="pre">get_create_attrs()</span></code> method. It returns 2 tuples, the
first one is the list of mandatory attributes, the second one the list of
optional attribute:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="c1"># v4 only</span>
<span class="k">print</span><span class="p">(</span><span class="n">gl</span><span class="o">.</span><span class="n">projects</span><span class="o">.</span><span class="n">get_create_attrs</span><span class="p">())</span>
<span class="p">((</span><span class="s1">&#39;name&#39;</span><span class="p">,),</span> <span class="p">(</span><span class="s1">&#39;path&#39;</span><span class="p">,</span> <span class="s1">&#39;namespace_id&#39;</span><span class="p">,</span> <span class="o">...</span><span class="p">))</span>
</pre></div>
</div>
<p>The attributes of objects are defined upon object creation, and depend on the
GitLab API itself. To list the available information associated with an object
use the python introspection tools for v3, or the <code class="docutils literal"><span class="pre">attributes</span></code> attribute for
v4:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">project</span> <span class="o">=</span> <span class="n">gl</span><span class="o">.</span><span class="n">projects</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>

<span class="c1"># v3</span>
<span class="k">print</span><span class="p">(</span><span class="nb">vars</span><span class="p">(</span><span class="n">project</span><span class="p">))</span>
<span class="c1"># or</span>
<span class="k">print</span><span class="p">(</span><span class="n">project</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">)</span>

<span class="c1"># v4</span>
<span class="k">print</span><span class="p">(</span><span class="n">project</span><span class="o">.</span><span class="n">attributes</span><span class="p">)</span>
</pre></div>
</div>
<p>Some objects also provide managers to access related GitLab resources:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="c1"># list the issues for a project</span>
<span class="n">project</span> <span class="o">=</span> <span class="n">gl</span><span class="o">.</span><span class="n">projects</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="n">issues</span> <span class="o">=</span> <span class="n">project</span><span class="o">.</span><span class="n">issues</span><span class="o">.</span><span class="n">list</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="section" id="gitlab-objects">
<h2>Gitlab Objects<a class="headerlink" href="#gitlab-objects" title="Permalink to this headline"></a></h2>
<p>You can update or delete a remote object when it exists locally:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="c1"># update the attributes of a resource</span>
<span class="n">project</span> <span class="o">=</span> <span class="n">gl</span><span class="o">.</span><span class="n">projects</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="n">project</span><span class="o">.</span><span class="n">wall_enabled</span> <span class="o">=</span> <span class="bp">False</span>
<span class="c1"># don&#39;t forget to apply your changes on the server:</span>
<span class="n">project</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>

<span class="c1"># delete the resource</span>
<span class="n">project</span><span class="o">.</span><span class="n">delete</span><span class="p">()</span>
</pre></div>
</div>
<p>Some classes provide additional methods, allowing more actions on the GitLab
resources. For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="c1"># star a git repository</span>
<span class="n">project</span> <span class="o">=</span> <span class="n">gl</span><span class="o">.</span><span class="n">projects</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="n">project</span><span class="o">.</span><span class="n">star</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="section" id="base-types">
<h2>Base types<a class="headerlink" href="#base-types" title="Permalink to this headline"></a></h2>
<p>The <code class="docutils literal"><span class="pre">gitlab</span></code> package provides some base types.</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">gitlab.Gitlab</span></code> is the primary class, handling the HTTP requests. It holds
the GitLab URL and authentication information.</li>
</ul>
<p>For v4 the following types are defined:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">gitlab.base.RESTObject</span></code> is the base class for all the GitLab v4 objects.
These objects provide an abstraction for GitLab resources (projects, groups,
and so on).</li>
<li><code class="docutils literal"><span class="pre">gitlab.base.RESTManager</span></code> is the base class for v4 objects managers,
providing the API to manipulate the resources and their attributes.</li>
</ul>
<p>For v3 the following types are defined:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">gitlab.base.GitlabObject</span></code> is the base class for all the GitLab v3 objects.
These objects provide an abstraction for GitLab resources (projects, groups,
and so on).</li>
<li><code class="docutils literal"><span class="pre">gitlab.base.BaseManager</span></code> is the base class for v3 objects managers,
providing the API to manipulate the resources and their attributes.</li>
</ul>
</div>
<div class="section" id="lazy-objects-v4-only">
<h2>Lazy objects (v4 only)<a class="headerlink" href="#lazy-objects-v4-only" title="Permalink to this headline"></a></h2>
<p>To avoid useless calls to the server API, you can create lazy objects. These
objects are created locally using a known ID, and give access to other managers
and methods.</p>
<p>The following exemple will only make one API call to the GitLab server to star
a project:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="c1"># star a git repository</span>
<span class="n">project</span> <span class="o">=</span> <span class="n">gl</span><span class="o">.</span><span class="n">projects</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">lazy</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>  <span class="c1"># no API call</span>
<span class="n">project</span><span class="o">.</span><span class="n">star</span><span class="p">()</span>  <span class="c1"># API call</span>
</pre></div>
</div>
</div>
<div class="section" id="pagination">
<h2>Pagination<a class="headerlink" href="#pagination" title="Permalink to this headline"></a></h2>
<p>You can use pagination to iterate over long lists. All the Gitlab objects
listing methods support the <code class="docutils literal"><span class="pre">page</span></code> and <code class="docutils literal"><span class="pre">per_page</span></code> parameters:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">ten_first_groups</span> <span class="o">=</span> <span class="n">gl</span><span class="o">.</span><span class="n">groups</span><span class="o">.</span><span class="n">list</span><span class="p">(</span><span class="n">page</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">per_page</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The first page is page 1, not page 0, except for project commits in v3 API.</p>
</div>
<p>By default GitLab does not return the complete list of items. Use the <code class="docutils literal"><span class="pre">all</span></code>
parameter to get all the items when using listing methods:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">all_groups</span> <span class="o">=</span> <span class="n">gl</span><span class="o">.</span><span class="n">groups</span><span class="o">.</span><span class="n">list</span><span class="p">(</span><span class="nb">all</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">all_owned_projects</span> <span class="o">=</span> <span class="n">gl</span><span class="o">.</span><span class="n">projects</span><span class="o">.</span><span class="n">owned</span><span class="p">(</span><span class="nb">all</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">python-gitlab will iterate over the list by calling the corresponding API
multiple times. This might take some time if you have a lot of items to
retrieve. This might also consume a lot of memory as all the items will be
stored in RAM. If you’re encountering the python recursion limit exception,
use <code class="docutils literal"><span class="pre">safe_all=True</span></code> instead to stop pagination automatically if the
recursion limit is hit.</p>
</div>
<p>With v4, <code class="docutils literal"><span class="pre">list()</span></code> methods can also return a generator object which will
handle the next calls to the API when required:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">items</span> <span class="o">=</span> <span class="n">gl</span><span class="o">.</span><span class="n">groups</span><span class="o">.</span><span class="n">list</span><span class="p">(</span><span class="n">as_list</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
<span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">items</span><span class="p">:</span>
    <span class="k">print</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">attributes</span><span class="p">)</span>
</pre></div>
</div>
<p>The generator exposes extra listing information as received by the server:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">current_page</span></code>: current page number (first page is 1)</li>
<li><code class="docutils literal"><span class="pre">prev_page</span></code>: if <code class="docutils literal"><span class="pre">None</span></code> the current page is the first one</li>
<li><code class="docutils literal"><span class="pre">next_page</span></code>: if <code class="docutils literal"><span class="pre">None</span></code> the current page is the last one</li>
<li><code class="docutils literal"><span class="pre">per_page</span></code>: number of items per page</li>
<li><code class="docutils literal"><span class="pre">total_pages</span></code>: total number of pages available</li>
<li><code class="docutils literal"><span class="pre">total</span></code>: total number of items in the list</li>
</ul>
</div>
<div class="section" id="sudo">
<h2>Sudo<a class="headerlink" href="#sudo" title="Permalink to this headline"></a></h2>
<p>If you have the administrator status, you can use <code class="docutils literal"><span class="pre">sudo</span></code> to act as another
user. For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">p</span> <span class="o">=</span> <span class="n">gl</span><span class="o">.</span><span class="n">projects</span><span class="o">.</span><span class="n">create</span><span class="p">({</span><span class="s1">&#39;name&#39;</span><span class="p">:</span> <span class="s1">&#39;awesome_project&#39;</span><span class="p">},</span> <span class="n">sudo</span><span class="o">=</span><span class="s1">&#39;user1&#39;</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="advanced-http-configuration">
<h2>Advanced HTTP configuration<a class="headerlink" href="#advanced-http-configuration" title="Permalink to this headline"></a></h2>
<p>python-gitlab relies on <code class="docutils literal"><span class="pre">requests</span></code> <code class="docutils literal"><span class="pre">Session</span></code> objects to perform all the
HTTP requests to the Gitlab servers.</p>
<p>You can provide your own <code class="docutils literal"><span class="pre">Session</span></code> object with custom configuration when
you create a <code class="docutils literal"><span class="pre">Gitlab</span></code> object.</p>
<div class="section" id="context-manager">
<h3>Context manager<a class="headerlink" href="#context-manager" title="Permalink to this headline"></a></h3>
<p>You can use <code class="docutils literal"><span class="pre">Gitlab</span></code> objects as context managers. This makes sure that the
<code class="docutils literal"><span class="pre">requests.Session</span></code> object associated with a <code class="docutils literal"><span class="pre">Gitlab</span></code> instance is always
properly closed when you exit a <code class="docutils literal"><span class="pre">with</span></code> block:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">gitlab</span><span class="o">.</span><span class="n">Gitlab</span><span class="p">(</span><span class="n">host</span><span class="p">,</span> <span class="n">token</span><span class="p">)</span> <span class="k">as</span> <span class="n">gl</span><span class="p">:</span>
    <span class="n">gl</span><span class="o">.</span><span class="n">projects</span><span class="o">.</span><span class="n">list</span><span class="p">()</span>
</pre></div>
</div>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">The context manager will also close the custom <code class="docutils literal"><span class="pre">Session</span></code> object you might
have used to build a <code class="docutils literal"><span class="pre">Gitlab</span></code> instance.</p>
</div>
</div>
<div class="section" id="proxy-configuration">
<h3>Proxy configuration<a class="headerlink" href="#proxy-configuration" title="Permalink to this headline"></a></h3>
<p>The following sample illustrates how to define a proxy configuration when using
python-gitlab:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">gitlab</span>
<span class="kn">import</span> <span class="nn">requests</span>

<span class="n">session</span> <span class="o">=</span> <span class="n">requests</span><span class="o">.</span><span class="n">Session</span><span class="p">()</span>
<span class="n">session</span><span class="o">.</span><span class="n">proxies</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">&#39;https&#39;</span><span class="p">:</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;https_proxy&#39;</span><span class="p">),</span>
    <span class="s1">&#39;http&#39;</span><span class="p">:</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;http_proxy&#39;</span><span class="p">),</span>
<span class="p">}</span>
<span class="n">gl</span> <span class="o">=</span> <span class="n">gitlab</span><span class="o">.</span><span class="n">gitlab</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">token</span><span class="p">,</span> <span class="n">api_version</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span> <span class="n">session</span><span class="o">=</span><span class="n">session</span><span class="p">)</span>
</pre></div>
</div>
<p>Reference:
<a class="reference external" href="http://docs.python-requests.org/en/master/user/advanced/#proxies">http://docs.python-requests.org/en/master/user/advanced/#proxies</a></p>
</div>
<div class="section" id="client-side-certificate">
<h3>Client side certificate<a class="headerlink" href="#client-side-certificate" title="Permalink to this headline"></a></h3>
<p>The following sample illustrates how to use a client-side certificate:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">gitlab</span>
<span class="kn">import</span> <span class="nn">requests</span>

<span class="n">session</span> <span class="o">=</span> <span class="n">requests</span><span class="o">.</span><span class="n">Session</span><span class="p">()</span>
<span class="n">s</span><span class="o">.</span><span class="n">cert</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;/path/to/client.cert&#39;</span><span class="p">,</span> <span class="s1">&#39;/path/to/client.key&#39;</span><span class="p">)</span>
<span class="n">gl</span> <span class="o">=</span> <span class="n">gitlab</span><span class="o">.</span><span class="n">gitlab</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">token</span><span class="p">,</span> <span class="n">api_version</span><span class="o">=</span><span class="mi">4</span><span class="p">,</span> <span class="n">session</span><span class="o">=</span><span class="n">session</span><span class="p">)</span>
</pre></div>
</div>
<p>Reference:
<a class="reference external" href="http://docs.python-requests.org/en/master/user/advanced/#client-side-certificates">http://docs.python-requests.org/en/master/user/advanced/#client-side-certificates</a></p>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Getting started with the API</a><ul>
<li><a class="reference internal" href="#gitlab-gitlab-class"><code class="docutils literal"><span class="pre">gitlab.Gitlab</span></code> class</a><ul>
<li><a class="reference internal" href="#note-on-password-authentication">Note on password authentication</a></li>
</ul>
</li>
<li><a class="reference internal" href="#api-version">API version</a></li>
<li><a class="reference internal" href="#managers">Managers</a></li>
<li><a class="reference internal" href="#gitlab-objects">Gitlab Objects</a></li>
<li><a class="reference internal" href="#base-types">Base types</a></li>
<li><a class="reference internal" href="#lazy-objects-v4-only">Lazy objects (v4 only)</a></li>
<li><a class="reference internal" href="#pagination">Pagination</a></li>
<li><a class="reference internal" href="#sudo">Sudo</a></li>
<li><a class="reference internal" href="#advanced-http-configuration">Advanced HTTP configuration</a><ul>
<li><a class="reference internal" href="#context-manager">Context manager</a></li>
<li><a class="reference internal" href="#proxy-configuration">Proxy configuration</a></li>
<li><a class="reference internal" href="#client-side-certificate">Client side certificate</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="cli.html"
                        title="previous chapter"><code class="docutils literal"><span class="pre">gitlab</span></code> CLI usage</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="switching-to-v4.html"
                        title="next chapter">Switching to GitLab API v4</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="_sources/api-usage.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="switching-to-v4.html" title="Switching to GitLab API v4"
             >next</a> |</li>
        <li class="right" >
          <a href="cli.html" title="gitlab CLI usage"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">python-gitlab 1.3.0 documentation</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2013-2018, Gauvain Pocentek, Mika Mäenpää.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.6.7.
    </div>
  </body>
</html>