Snippets

You can store code snippets in Gitlab. Snippets can be attached to projects (see Snippets), but can also be detached.

Examples

List snippets woned by the current user:

snippets = gl.snippets.list()

List the public snippets:

public_snippets = gl.snippets.public()

Get a snippet:

snippet = gl.snippets.get(snippet_id)
# get the content
content = snippet.raw()

Warning

Blobs are entirely stored in memory unless you use the streaming feature. See the artifacts example.

Create a snippet:

snippet = gl.snippets.create({'title': 'snippet1',
                              'file_name': 'snippet1.py',
                              'content': open('snippet1.py').read()})

Update a snippet:

snippet.visibility_level = gitlab.Project.VISIBILITY_PUBLIC
snippet.save()

Delete a snippet:

gl.snippets.delete(snippet_id)
# or
snippet.delete()