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.
- v4 API:
- GitLab API: https://docs.gitlab.com/ee/api/packages.html#within-a-project
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)
- v4 API:
- GitLab API: https://docs.gitlab.com/ee/api/packages.html#within-a-group
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')
- v4 API:
- GitLab API: https://docs.gitlab.com/ee/api/packages.html#list-package-files
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()
You can use python-gitlab to upload and download generic packages.
- v4 API:
- GitLab API: https://docs.gitlab.com/ee/user/packages/generic_packages
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.