summaryrefslogtreecommitdiff
path: root/docs/gl_objects/packages.rst
blob: 93e0e9da47c7e460f9bf2a04a8f91edac1888f71 (plain)
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
########
Packages
########

Packages allow you to utilize GitLab as a private repository for a variety
of common package managers, as well as GitLab's generic package registry.

Project Packages
=====================

Reference
---------

* v4 API:

  + :class:`gitlab.v4.objects.ProjectPackage`
  + :class:`gitlab.v4.objects.ProjectPackageManager`
  + :attr:`gitlab.v4.objects.Project.packages`

* GitLab API: https://docs.gitlab.com/ee/api/packages.html#within-a-project

Examples
--------

List the packages in a project::

    packages = project.packages.list()

Filter the results by ``package_type`` or ``package_name`` ::

    packages = project.packages.list(package_type='pypi')

Get a specific package of a project by id::

    package = project.packages.get(1)

Delete a package from a project::

    package.delete()
    # or
    project.packages.delete(package.id)


Group Packages
===================

Reference
---------

* v4 API:

  + :class:`gitlab.v4.objects.GroupPackage`
  + :class:`gitlab.v4.objects.GroupPackageManager`
  + :attr:`gitlab.v4.objects.Group.packages`

* GitLab API: https://docs.gitlab.com/ee/api/packages.html#within-a-group

Examples
--------

List the packages in a group::

    packages = group.packages.list()

Filter the results by ``package_type`` or ``package_name`` ::

    packages = group.packages.list(package_type='pypi')


Project Package Files
=====================

Reference
---------

* v4 API:

  + :class:`gitlab.v4.objects.ProjectPackageFile`
  + :class:`gitlab.v4.objects.ProjectPackageFileManager`
  + :attr:`gitlab.v4.objects.ProjectPackage.package_files`

* GitLab API: https://docs.gitlab.com/ee/api/packages.html#list-package-files

Examples
--------

List package files for package in project::

    package = project.packages.get(1)
    package_files = package.package_files.list()

Delete a package file in a project::

    package = project.packages.get(1)
    file = package.package_files.list()[0]
    file.delete()


Generic Packages
================

You can use python-gitlab to upload and download generic packages.

Reference
---------

* v4 API:

  + :class:`gitlab.v4.objects.GenericPackage`
  + :class:`gitlab.v4.objects.GenericPackageManager`
  + :attr:`gitlab.v4.objects.Project.generic_packages`

* GitLab API: https://docs.gitlab.com/ee/user/packages/generic_packages

Examples
--------

Upload a generic package to a project::

    project = gl.projects.get(1, lazy=True)
    package = project.generic_packages.upload(
        package_name="hello-world",
        package_version="v1.0.0",
        file_name="hello.tar.gz",
        path="/path/to/local/hello.tar.gz"
    )

Download a project's generic package::

    project = gl.projects.get(1, lazy=True)
    package = project.generic_packages.download(
        package_name="hello-world",
        package_version="v1.0.0",
        file_name="hello.tar.gz",
    )

.. hint:: You can use the Packages API described above to find packages and
    retrieve the metadata you need download them.