Applications

API for managing SonarQube applications.

Applications API for SonarQube SDK.

This module provides methods to manage SonarQube applications, which are collections of projects that can be analyzed together.

Example

Using the Applications API:

from sonarqube import SonarQubeClient

client = SonarQubeClient(base_url="...", token="...")

# Create an application
app = client.applications.create(
    name="My Application", key="my-app", visibility="private"
)

# Add a project to the application
client.applications.add_project(application="my-app", project="my-project")
class sonarqube.api.applications.ApplicationsAPI(client)[source]

Bases: BaseAPI

API for managing SonarQube applications.

Applications are collections of projects that can be analyzed together. This API provides methods to create, update, delete, and manage applications and their projects.

API_PATH

Base path for applications API (“/api/applications”).

Example

Using the applications API:

# Create an application
app = client.applications.create(name="My Application", key="my-app")

# Add a project
client.applications.add_project(application="my-app", project="my-project")

# Get application details
details = client.applications.show(application="my-app")
print(details.application.name)
Parameters:

client (HTTPClient)

add_project(application, project)[source]

Add a project to an application.

Requires ‘Administrator’ permission on the application and ‘Browse’ permission on the project.

Parameters:
  • application (str) – Application key.

  • project (str) – Project key.

Raises:
  • SonarQubeNotFoundError – If application or project not found.

  • SonarQubePermissionError – If lacking required permissions.

Return type:

None

Example

>>> client.applications.add_project(application="my-app", project="my-project")
create(name, description=None, key=None, visibility=None)[source]

Create a new application.

Requires ‘Administrator’ permission on the portfolio parent if it exists.

Parameters:
  • name (str) – Application name.

  • description (Optional[str], default: None) – Application description.

  • key (Optional[str], default: None) – Application key. If not provided, a key will be generated.

  • visibility (Optional[str], default: None) – Application visibility (public/private).

Return type:

ApplicationCreateResponse

Returns:

Response containing the created application.

Raises:
  • SonarQubeValidationError – If validation fails.

  • SonarQubePermissionError – If lacking required permissions.

Example

>>> app = client.applications.create(
...     name="My Application", key="my-app", visibility="private"
... )
>>> print(app.application.key)
'my-app'
create_branch(application, branch, project, project_branch=None)[source]

Create a new branch for an application.

Requires ‘Administrator’ permission on the application.

Parameters:
  • application (str) – Application key.

  • branch (str) – Branch name to create.

  • project (list[str]) – List of project keys to include in the branch.

  • project_branch (Optional[list[str]], default: None) – List of branch names for each project.

Raises:
  • SonarQubeValidationError – If validation fails.

  • SonarQubePermissionError – If lacking required permissions.

Return type:

None

Example

>>> client.applications.create_branch(
...     application="my-app",
...     branch="feature-x",
...     project=["project1", "project2"],
...     project_branch=["feature-x", "feature-x"],
... )
delete(application)[source]

Delete an application.

Requires ‘Administrator’ permission on the application.

Parameters:

application (str) – Application key.

Raises:
  • SonarQubeNotFoundError – If application not found.

  • SonarQubePermissionError – If lacking required permissions.

Return type:

None

Example

>>> client.applications.delete(application="my-app")
delete_branch(application, branch)[source]

Delete a branch from an application.

Requires ‘Administrator’ permission on the application.

Parameters:
  • application (str) – Application key.

  • branch (str) – Branch name to delete.

Raises:
  • SonarQubeNotFoundError – If application or branch not found.

  • SonarQubePermissionError – If lacking required permissions.

Return type:

None

Example

>>> client.applications.delete_branch(application="my-app", branch="feature-x")
remove_project(application, project)[source]

Remove a project from an application.

Requires ‘Administrator’ permission on the application.

Parameters:
  • application (str) – Application key.

  • project (str) – Project key.

Raises:
  • SonarQubeNotFoundError – If application or project not found.

  • SonarQubePermissionError – If lacking required permissions.

Return type:

None

Example

>>> client.applications.remove_project(application="my-app", project="my-project")
search(p=None, ps=None, q=None)[source]

Search for applications.

Requires ‘Browse’ permission on the application.

Parameters:
  • p (Optional[int], default: None) – Page number (1-based).

  • ps (Optional[int], default: None) – Page size (max 500).

  • q (Optional[str], default: None) – Search query for application name.

Return type:

ApplicationSearchResponse

Returns:

Response containing list of applications and paging info.

Example

>>> response = client.applications.search(q="my-app")
>>> for app in response.applications:
...     print(app.name)
search_projects(application, p=None, ps=None, q=None, selected=None)[source]

Search for projects in an application.

Requires ‘Browse’ permission on the application.

Parameters:
  • application (str) – Application key.

  • p (Optional[int], default: None) – Page number (1-based).

  • ps (Optional[int], default: None) – Page size (max 500).

  • q (Optional[str], default: None) – Search query for project name.

  • selected (Optional[str], default: None) – Filter by selection (all, selected, deselected).

Return type:

ApplicationProjectsSearchResponse

Returns:

Response containing list of projects and paging info.

Example

>>> response = client.applications.search_projects(
...     application="my-app", q="backend"
... )
>>> for project in response.projects:
...     print(project.name)
set_tags(application, tags)[source]

Set tags on an application.

Requires ‘Administrator’ permission on the application.

Parameters:
  • application (str) – Application key.

  • tags (list[str]) – List of tags to set.

Raises:
  • SonarQubeNotFoundError – If application not found.

  • SonarQubePermissionError – If lacking required permissions.

Return type:

None

Example

>>> client.applications.set_tags(
...     application="my-app", tags=["team-a", "production"]
... )
show(application, branch=None)[source]

Get application details.

Requires ‘Browse’ permission on the application.

Parameters:
  • application (str) – Application key.

  • branch (Optional[str], default: None) – Branch name (optional).

Return type:

ApplicationShowResponse

Returns:

Response containing application details.

Raises:

SonarQubeNotFoundError – If application not found.

Example

>>> response = client.applications.show(application="my-app")
>>> print(response.application.name)
show_leak(application, branch=None)[source]

Get the leak period for an application.

Requires ‘Browse’ permission on the application.

Parameters:
  • application (str) – Application key.

  • branch (Optional[str], default: None) – Branch name (optional).

Return type:

dict[str, Any]

Returns:

Dictionary containing leak period information.

Example

>>> leak = client.applications.show_leak(application="my-app")
update(application, name, description=None)[source]

Update an application.

Requires ‘Administrator’ permission on the application.

Parameters:
  • application (str) – Application key.

  • name (str) – New application name.

  • description (Optional[str], default: None) – New application description.

Raises:
  • SonarQubeNotFoundError – If application not found.

  • SonarQubePermissionError – If lacking required permissions.

Return type:

None

Example

>>> client.applications.update(
...     application="my-app",
...     name="My Updated Application",
...     description="Updated description",
... )
update_branch(application, branch, name, project, project_branch=None)[source]

Update an application branch.

Requires ‘Administrator’ permission on the application.

Parameters:
  • application (str) – Application key.

  • branch (str) – Current branch name.

  • name (str) – New branch name.

  • project (list[str]) – List of project keys.

  • project_branch (Optional[list[str]], default: None) – List of branch names for each project.

Raises:
  • SonarQubeNotFoundError – If application or branch not found.

  • SonarQubePermissionError – If lacking required permissions.

Return type:

None

Example

>>> client.applications.update_branch(
...     application="my-app",
...     branch="feature-x",
...     name="feature-y",
...     project=["project1", "project2"],
... )

Models

Pydantic models for Applications API.

This module provides models for the /api/applications endpoints including creating, updating, and managing applications and their projects.

Example

Using application models:

from sonarqube.models.applications import Application, ApplicationCreateResponse

# Response from create endpoint
response = ApplicationCreateResponse(
    application=Application(
        key="my-app", name="My Application", visibility="private"
    )
)
class sonarqube.models.applications.ApplicationProject(**data)[source]

Bases: SonarQubeModel

A project within an application.

key

Project key.

name

Project name.

enabled

Whether the project is enabled.

selected

Whether the project is selected.

branch

Branch name (if branch-specific).

Example

>>> project = ApplicationProject(key="my-project", name="My Project", enabled=True)
Parameters:
key: str
name: str
enabled: Optional[bool]
selected: Optional[bool]
branch: Optional[str]
model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'populate_by_name': True, 'str_strip_whitespace': True, 'use_enum_values': True, 'validate_by_alias': True, 'validate_by_name': True, 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class sonarqube.models.applications.ApplicationBranch(**data)[source]

Bases: SonarQubeModel

A branch within an application.

name

Branch name.

is_main

Whether this is the main branch.

Example

>>> branch = ApplicationBranch(name="main", isMain=True)
>>> print(branch.is_main)
True
Parameters:
name: str
is_main: bool
model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'populate_by_name': True, 'str_strip_whitespace': True, 'use_enum_values': True, 'validate_by_alias': True, 'validate_by_name': True, 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class sonarqube.models.applications.Application(**data)[source]

Bases: SonarQubeModel

A SonarQube application.

Applications are collections of projects that can be analyzed together.

key

Unique application key.

name

Application display name.

description

Application description.

visibility

Application visibility (public/private).

projects

List of projects in the application.

branches

List of branches in the application.

Example

>>> app = Application(key="my-app", name="My Application", visibility="private")
Parameters:
  • data (Any)

  • key (str)

  • name (str)

  • description (str | None)

  • visibility (str | None)

  • projects (list[ApplicationProject] | None)

  • branches (list[ApplicationBranch] | None)

key: str
name: str
description: Optional[str]
visibility: Optional[str]
projects: Optional[list[ApplicationProject]]
branches: Optional[list[ApplicationBranch]]
model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'populate_by_name': True, 'str_strip_whitespace': True, 'use_enum_values': True, 'validate_by_alias': True, 'validate_by_name': True, 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class sonarqube.models.applications.ApplicationCreateResponse(**data)[source]

Bases: SonarQubeModel

Response from creating an application.

application

The created application.

Example

>>> response = ApplicationCreateResponse(
...     application=Application(key="my-app", name="My App")
... )
Parameters:
  • data (Any)

  • application (Application)

application: Application
model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'populate_by_name': True, 'str_strip_whitespace': True, 'use_enum_values': True, 'validate_by_alias': True, 'validate_by_name': True, 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class sonarqube.models.applications.ApplicationShowResponse(**data)[source]

Bases: SonarQubeModel

Response from showing an application.

application

The application details.

Example

>>> response = client.applications.show(application="my-app")
>>> print(response.application.name)
Parameters:
  • data (Any)

  • application (Application)

application: Application
model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'populate_by_name': True, 'str_strip_whitespace': True, 'use_enum_values': True, 'validate_by_alias': True, 'validate_by_name': True, 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class sonarqube.models.applications.ApplicationSearchResponse(**data)[source]

Bases: SonarQubeModel

Response from searching applications.

paging

Paging information.

applications

List of applications.

Example

>>> response = client.applications.search(q="my-app")
>>> for app in response.applications:
...     print(app.name)
Parameters:
  • data (Any)

  • paging (Paging)

  • applications (list[Application])

paging: Paging
applications: list[Application]
model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'populate_by_name': True, 'str_strip_whitespace': True, 'use_enum_values': True, 'validate_by_alias': True, 'validate_by_name': True, 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class sonarqube.models.applications.ApplicationProjectsSearchResponse(**data)[source]

Bases: SonarQubeModel

Response from searching projects for an application.

paging

Paging information.

projects

List of projects.

Example

>>> response = client.applications.search_projects(application="my-app")
>>> for project in response.projects:
...     print(project.name)
Parameters:
  • data (Any)

  • paging (Paging)

  • projects (list[ApplicationProject])

paging: Paging
projects: list[ApplicationProject]
model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'populate_by_name': True, 'str_strip_whitespace': True, 'use_enum_values': True, 'validate_by_alias': True, 'validate_by_name': True, 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class sonarqube.models.applications.ApplicationBranchesResponse(**data)[source]

Bases: SonarQubeModel

Response from listing application branches.

branches

List of branches.

Example

>>> response = client.applications.list_branches(application="my-app")
>>> for branch in response.branches:
...     print(branch.name)
Parameters:
  • data (Any)

  • branches (list[Branch])

branches: list[Branch]
model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'populate_by_name': True, 'str_strip_whitespace': True, 'use_enum_values': True, 'validate_by_alias': True, 'validate_by_name': True, 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class sonarqube.models.applications.CreateBranchRequest(**data)[source]

Bases: SonarQubeModel

Request model for creating an application branch.

application

Application key.

branch

Branch name.

project

Project keys and branches mapping.

Example

>>> request = CreateBranchRequest(
...     application="my-app", branch="feature-x", project=["project1", "project2"]
... )
Parameters:
application: str
branch: str
project: list[str]
project_branch: Optional[list[str]]
model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'populate_by_name': True, 'str_strip_whitespace': True, 'use_enum_values': True, 'validate_by_alias': True, 'validate_by_name': True, 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].