summaryrefslogtreecommitdiff
path: root/docs/api-usage.rst
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2018-02-05 14:21:14 +0100
committerGauvain Pocentek <gauvain@pocentek.net>2018-02-05 14:22:40 +0100
commitb4f03173f33ed8d214ddc20b4791ec11677f6bb1 (patch)
tree2bf8d58fff2068ace593c250e854eb9b4916f5cc /docs/api-usage.rst
parent29bd81336828b72a47673c76862cb4b532401766 (diff)
downloadgitlab-b4f03173f33ed8d214ddc20b4791ec11677f6bb1.tar.gz
Gitlab can be used as context manager
Fixes #371
Diffstat (limited to 'docs/api-usage.rst')
-rw-r--r--docs/api-usage.rst17
1 files changed, 17 insertions, 0 deletions
diff --git a/docs/api-usage.rst b/docs/api-usage.rst
index 3704591..5816b6d 100644
--- a/docs/api-usage.rst
+++ b/docs/api-usage.rst
@@ -274,6 +274,23 @@ HTTP requests to the Gitlab servers.
You can provide your own ``Session`` object with custom configuration when
you create a ``Gitlab`` object.
+Context manager
+---------------
+
+You can use ``Gitlab`` objects as context managers. This makes sure that the
+``requests.Session`` object associated with a ``Gitlab`` instance is always
+properly closed when you exit a ``with`` block:
+
+.. code-block:: python
+
+ with gitlab.Gitlab(host, token) as gl:
+ gl.projects.list()
+
+.. warning::
+
+ The context manager will also close the custom ``Session`` object you might
+ have used to build a ``Gitlab`` instance.
+
Proxy configuration
-------------------