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:
BaseAPIAPI 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:
- Raises:
SonarQubeNotFoundError – If application or project not found.
SonarQubePermissionError – If lacking required permissions.
- Return type:
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:
- 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:
- Raises:
SonarQubeValidationError – If validation fails.
SonarQubePermissionError – If lacking required permissions.
- Return type:
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:
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:
- Raises:
SonarQubeNotFoundError – If application or branch not found.
SonarQubePermissionError – If lacking required permissions.
- Return type:
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:
- Raises:
SonarQubeNotFoundError – If application or project not found.
SonarQubePermissionError – If lacking required permissions.
- Return type:
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:
- 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:
- 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:
- Raises:
SonarQubeNotFoundError – If application not found.
SonarQubePermissionError – If lacking required permissions.
- Return type:
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:
- 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:
- Return type:
- 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:
- Raises:
SonarQubeNotFoundError – If application not found.
SonarQubePermissionError – If lacking required permissions.
- Return type:
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:
- Raises:
SonarQubeNotFoundError – If application or branch not found.
SonarQubePermissionError – If lacking required permissions.
- Return type:
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:
SonarQubeModelA 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:
SonarQubeModelA 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
- 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:
SonarQubeModelA 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:
- 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:
SonarQubeModelResponse 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:
SonarQubeModelResponse 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:
SonarQubeModelResponse 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)
- 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:
SonarQubeModelResponse 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)
- 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:
SonarQubeModelResponse 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)
- 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:
SonarQubeModelRequest 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].