> ## Documentation Index
> Fetch the complete documentation index at: https://docs.paradime.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Admin client: git repository

> Read a workspace's git repository and deploy key, connect a repository, check access and rotate the deploy key from Python with paradime.admin.git.

`paradime.admin.git` reads how a workspace reaches its git repository, connects a repository, and manages the workspace's deploy key. For the GraphQL operations, see [Git repositories](https://docs.paradime.io/developers/graphql-api/admin-api/git-repositories).

> [!NOTE]
>
> **Prerequisites**
>
> * These operations are part of the Enterprise plan. On other plans, they raise `AdminPlanUpgradeRequiredException`.
> * Your API key needs the **Git repository admin** capability group.
> * The admin client of the `paradime-io` package. See [Admin client](https://docs.paradime.io/developers/python-sdk/modules/admin/index).

The examples on this page use this client:

```python theme={"system"}
from paradime import Paradime

paradime = Paradime(api_endpoint="API_ENDPOINT", api_secret="prdm_cmp_...", workspace_uid="WORKSPACE_UID")
```

## Get the repository and deploy key

Reads the workspace's git repository, how Paradime reaches it, and the workspace's deploy key. When the workspace has no deploy key yet, a key with the **Git repository admin** group creates the first one.

**workspace\_uid** `Optional[str]` (default: None)

The workspace to read, for a company API key.

**Returns** `Optional[GitRepository]`

The repository, or `None` when the server returned none.

```python theme={"system"}
repository = paradime.admin.git.get_repository()
print(repository.state)
print(repository.deploy_key.public_key)  # add this key to the repository with write access
```

## Connect a repository

Connects the workspace's repository. Sending the same input again changes nothing and starts no job. Pass one of three connection inputs:

* `DeployKeyConnectionInput`: Paradime clones and pushes with the workspace's deploy key. Add the key to the repository with write access first. With `validate_repository=True` (the default), the clone, the `dbt_project.yml` check, the production sync and the editor restart run in a job.
* `GitHubAppConnectionInput`: through the Paradime GitHub App. See [Connect through the GitHub App](https://docs.paradime.io/products/settings/git-repositories/connect-with-github-app.md).
* `GitLabAppConnectionInput`: through the company's GitLab connection. See [Connect a GitLab repository](https://docs.paradime.io/integrations/gitlab/connect-a-repository.md).

The GitHub App and GitLab connections finish before the call returns.

**connection** `DeployKeyConnectionInput | GitHubAppConnectionInput | GitLabAppConnectionInput` *required*

How Paradime reaches the repository. See [Types](#types).

**workspace\_uid** `Optional[str]` (default: None)

The workspace to change, for a company API key.

**Returns** `ConnectGitRepositoryResult`

The repository now (`git_repository`) and, when the deploy key connects it with validation, the cloning job (`job`). Wait for the job with [`admin.jobs.wait`](https://docs.paradime.io/developers/python-sdk/modules/admin/jobs#wait-for-a-job). Its result is a `GitRepositoryConnectResult`.

```python theme={"system"}
from paradime.apis.admin.git.types import DeployKeyConnectionInput, GitProvider

result = paradime.admin.git.connect(
    DeployKeyConnectionInput(provider=GitProvider.GITHUB, uri="git@github.com:acme/analytics.git")
)
if result.job is not None:
    paradime.admin.jobs.wait(result.job.id)

print(paradime.admin.git.get_repository().state)  # CONNECTED
```

> [!WARNING]
>
> A workspace that already has a cloned repository refuses a different repository with `AdminConflictException`. Pass `force=True` in `DeployKeyConnectionInput` to replace it.

## Check repository access

Starts a job that checks the workspace's deploy key can push to a repository. Changes nothing. The job fails with `CONNECTION_TEST_FAILED` when the key can't push.

**uri** `str` *required*

The repository's SSH URI.

**workspace\_uid** `Optional[str]` (default: None)

The workspace to use, for a company API key.

**Returns** `AdminJob`

The job. Wait for it with `admin.jobs.wait`. Its result is a `GitRepositoryCheckResult`.

```python theme={"system"}
from paradime.apis.admin import AdminConnectionTestFailedException

job = paradime.admin.git.check_repository("git@github.com:acme/analytics.git")
try:
    paradime.admin.jobs.wait(job.id)
    print("The deploy key can push to the repository.")
except AdminConnectionTestFailedException as error:
    print(f"The deploy key can't push: {error.message}")
```

## Rotate the deploy key

Replaces the workspace's deploy key. Every call makes a new key.

**force** `bool` (default: False)

Rotate a key that the connected repository uses. Without it, that call raises `AdminConflictException`. Clone and push break until you add the new key to the repository.

**workspace\_uid** `Optional[str]` (default: None)

The workspace to change, for a company API key.

**Returns** `GitDeployKey`

The new deploy key.

```python theme={"system"}
key = paradime.admin.git.rotate_deploy_key(force=True)
print(key.public_key)
```

## Types

Import the models and enums from `paradime.apis.admin.git.types`.

**DeployKeyConnectionInput** `input`

**fields**

**provider** `GitProvider` *required*

The service hosting the repository: `GITHUB`, `GITLAB`, `BITBUCKET` or `AZURE_DEVOPS`.

**uri** `str` *required*

The repository's SSH URI, for example `git@github.com:org/repo.git`.

**dbt\_project\_dir** `Optional[str]`

The folder in the repository that holds `dbt_project.yml`. Leave it out when the file is at the repository's root.

**validate\_repository** `Optional[bool]`

Clone the repository now, in a job, and check `dbt_project.yml` (the default). With `False`, the repository is only saved, as `PENDING_VALIDATION`, until you add the deploy key to it. A workspace that already has a clone needs `True` to change.

**force** `Optional[bool]`

Replace a cloned repository with another one.

**GitHubAppConnectionInput** `input`

**fields**

**installation\_id** `Optional[str]`

An installation of the Paradime GitHub App that the company holds. Leave it and `repository_id` out to move the workspace's current repository to the App.

**repository\_id** `Optional[str]`

The repository's numeric GitHub id.

**GitLabAppConnectionInput** `input`

**fields**

**base\_url** `Optional[str]`

The GitLab connection's base URL. Leave it and `project_id` out to move the workspace's current repository to the connection.

**project\_id** `Optional[str]`

The project's numeric GitLab id.

**GitRepository** `model`

**fields**

**mode** `GitConnectionMode`

How Paradime reaches the repository: `SSH_DEPLOY_KEY`, `GITHUB_APP` or `GITLAB_APP`.

**state** `GitRepositoryState`

Where the repository is. See the states below.

**provider** `Optional[GitProvider]`

The service hosting the repository.

**uri** `Optional[str]`

The repository's SSH URI. `None` when no repository is connected.

**dbt\_project\_dir** `Optional[str]`

The folder that holds `dbt_project.yml`. `None` for the repository's root.

**is\_verified** `Optional[bool]`

Whether a clone of the repository succeeded.

**deploy\_key** `Optional[GitDeployKey]`

The workspace's deploy key. Its `public_key` is in OpenSSH format.

**github\_app** `Optional[GitHubAppRepository]`

The GitHub App connection: `installation_id`, `repository_id` and `repository_full_name`. `None` in other modes.

**gitlab\_app** `Optional[GitLabAppRepository]`

The GitLab connection: `project_id` and `project_path`. `None` in other modes.

**github\_app\_install\_url** `Optional[str]`

The page that installs the Paradime GitHub App for this workspace, for a workspace member to open in a browser.

`GitRepositoryState` values:

| State | Meaning |
| - | - |
| `NOT_CONNECTED` | No repository is connected yet. |
| `PENDING_USER_ACTION` | No repository is connected yet, and a GitHub App install request waits for an organization owner on GitHub. |
| `PENDING_VALIDATION` | The repository is saved but not cloned yet. Add the deploy key to it, then connect again with validation. |
| `CONNECTED` | The repository is cloned and in use. |
| `DEGRADED` | The GitHub App lost access to the repository, or its installation is suspended. |
| `DISCONNECTED` | The GitHub App installation was removed, and the workspace has no deploy key to fall back to. |


## Related topics

- [Admin client](https://docs.paradime.io/developers/python-sdk/modules/admin/index.md)
- [Admin client: jobs](https://docs.paradime.io/developers/python-sdk/modules/admin/jobs.md)
- [Git Repositories](https://docs.paradime.io/products/settings/git-repositories/index.md)
- [Admin client: setup status](https://docs.paradime.io/developers/python-sdk/modules/admin/setup-status.md)
- [Administration API: Git repositories](https://docs.paradime.io/developers/graphql-api/admin-api/git-repositories.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.