# Deploy keys

### Reference

- v4 API:
  - `gitlab.v4.objects.DeployKey`
  - `gitlab.v4.objects.DeployKeyManager`
  - `gitlab.Gitlab.deploykeys`
- v3 API:
  - `gitlab.v3.objects.DeployKey`
  - `gitlab.v3.objects.DeployKeyManager`
  - `gitlab.Gitlab.deploykeys`
- GitLab API: https://docs.gitlab.com/ce/api/deploy_keys.html

### Examples

List the deploy keys:

    keys = gl.deploykeys.list()

Get a single deploy key:

    key = gl.deploykeys.get(key_id)

## Deploy keys for projects

Deploy keys can be managed on a per-project basis.

### Reference

- v4 API:
  - `gitlab.v4.objects.ProjectKey`
  - `gitlab.v4.objects.ProjectKeyManager`
  - `gitlab.v4.objects.Project.keys`
- v3 API:
  - `gitlab.v3.objects.ProjectKey`
  - `gitlab.v3.objects.ProjectKeyManager`
  - `gitlab.v3.objects.Project.keys`
  - `gitlab.Gitlab.project_keys`
- GitLab API: https://docs.gitlab.com/ce/api/deploy_keys.html

### Examples

List keys for a project:

    keys = project.keys.list()

Get a single deploy key:

    key = project.keys.get(key_id)

Create a deploy key for a project:

    key = project.keys.create({'title': 'jenkins key',
                               'key': open('/home/me/.ssh/id_rsa.pub').read()})

Delete a deploy key for a project:

    key = project.keys.list(key_id)
    # or
    key.delete()

Enable a deploy key for a project:

    project.keys.enable(key_id)

Disable a deploy key for a project:

    project_key.delete()  # v4
    project.keys.disable(key_id)  # v3