跳转到主要内容

GitLab API的Python封装

项目描述

https://github.com/python-gitlab/python-gitlab/workflows/Test/badge.svg https://badge.fury.io/py/python-gitlab.svg https://readthedocs.org/projects/python-gitlab/badge/?version=latest https://codecov.io/github/python-gitlab/python-gitlab/coverage.svg?branch=main https://img.shields.io/pypi/pyversions/python-gitlab.svg https://img.shields.io/gitter/room/python-gitlab/Lobby.svg https://img.shields.io/badge/code%20style-black-000000.svg https://img.shields.io/github/license/python-gitlab/python-gitlab

python-gitlab 是一个 Python 包,提供对 GitLab 服务器 API 的访问。

它支持 GitLab 的 v4 API,并提供一个 CLI 工具(gitlab)。

功能

python-gitlab 允许您

  • 编写 Python 代码来管理您的 GitLab 资源。

  • 向 GitLab API 传递任意参数。只需遵循 GitLab 文档了解可用的参数。

  • 通过使用低级 API 方法,在 GitLab 上任意端点可用时即可访问它们。

  • 使用持久性请求会话进行身份验证、代理和证书处理。

  • 处理网络和服务器错误时的智能重试,包括速率限制处理。

  • 灵活处理分页响应,包括延迟迭代器。

  • 在需要时自动对路径和参数进行 URL 编码。

  • 自动将一些复杂的数据结构转换为 API 属性类型

  • 从配置文件、环境变量和参数中合并配置。

安装

截至 4.0.0,python-gitlab 与 Python 3.8+ 兼容。

使用 pip 安装 python-gitlab 的最新稳定版本

$ pip install --upgrade python-gitlab

当前的开发版本可在 GitHub.comGitLab.com 上获得,可以直接从 git 仓库安装

$ pip install git+https://github.com/python-gitlab/python-gitlab.git

从 GitLab

$ pip install git+https://gitlab.com/python-gitlab/python-gitlab.git

使用 Docker 镜像

python-gitlab 提供基于 Alpine 和 Debian slim python 基础镜像 的两个 Docker 镜像。默认标签是 alpine,但您可以使用别名(见下文)显式使用。

alpine 镜像较小,但如果您遇到问题或需要带有 bash shell 的更完整的环境,例如在 CI 任务中,您可能希望使用基于 Debian 的 slim 标签(目前基于 -slim-bullseye)。

这些镜像已发布在 GitLab 注册表中,例如

  • registry.gitlab.com/python-gitlab/python-gitlab:latest(最新版本,alpine 别名)

  • registry.gitlab.com/python-gitlab/python-gitlab:alpine(最新 alpine)

  • registry.gitlab.com/python-gitlab/python-gitlab:slim-bullseye(最新 slim-bullseye)

  • registry.gitlab.com/python-gitlab/python-gitlab:v3.2.0(alpine 别名)

  • registry.gitlab.com/python-gitlab/python-gitlab:v3.2.0-alpine

  • registry.gitlab.com/python-gitlab/python-gitlab:v3.2.0-slim-bullseye

您可以直接从 GitLab 注册表运行 Docker 镜像

$ docker run -it --rm registry.gitlab.com/python-gitlab/python-gitlab:latest <command> ...

例如,获取 GitLab.com 上的项目(不进行身份验证)

$ docker run -it --rm registry.gitlab.com/python-gitlab/python-gitlab:latest project get --id gitlab-org/gitlab

您还可以挂载您自己的配置文件

$ docker run -it --rm -v /path/to/python-gitlab.cfg:/etc/python-gitlab.cfg registry.gitlab.com/python-gitlab/python-gitlab:latest <command> ...

在 GitLab CI 内部的使用

如果您想在 GitLab CI 中直接使用 Docker 镜像作为 image,您需要覆盖 entrypoint,如官方 GitLab 文档中所述

Job Name:
   image:
      name: registry.gitlab.com/python-gitlab/python-gitlab:latest
      entrypoint: [""]
   before_script:
      gitlab --version
   script:
      gitlab <command>

构建镜像

要从此存储库构建自己的镜像,请运行

$ docker build -t python-gitlab:latest .

运行您自己的镜像

$ docker run -it --rm python-gitlab:latest <command> ...

构建基于 Debian slim 的镜像

$ docker build -t python-gitlab:latest --build-arg PYTHON_FLAVOR=slim-bullseye .

错误报告

请在 https://github.com/python-gitlab/python-gitlab/issues 上报告错误和功能请求。

Gitter 社区聊天

我们有一个Gitter社区聊天群,可在https://gitter.im/python-gitlab/Lobby找到,您也可以通过下方的“打开聊天”按钮直接访问。

如果您有简单的问题,社区可能已经可以帮到您,无需您打开一个issue。如果您经常使用python-gitlab,我们也鼓励您加入并参与其中。您可能会发现新的想法和用例!

文档

CLI和API的完整文档可在readthedocs上找到。

构建文档

我们使用tox来管理我们的环境并构建文档

pip install tox
tox -e docs

贡献

有关对python-gitlab贡献的指南,请参阅CONTRIBUTING.rst

项目详情


发布历史 发布通知 | RSS订阅

下载文件

下载适用于您平台的应用程序文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

python_gitlab-4.12.2.tar.gz (484.6 kB 查看哈希值)

上传时间 源码

构建版本

python_gitlab-4.12.2-py3-none-any.whl (145.1 kB 查看哈希值)

上传时间 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页