sonarqube.rest package

Submodules

sonarqube.rest.alm_integrations module

class sonarqube.rest.alm_integrations.SonarQubeAlmIntegrations(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

import_gitlab_project(almSetting, gitlabProjectId)

Only available on the professional edition

since 8.5 Import a GitLab project to SonarQube, creating a new project and configuring MR decoration Requires the ‘Create Projects’ permission

Parameters:
  • almSetting – ALM setting key
  • gitlabProjectId – GitLab project ID
Returns:

list_azure_projects(almSetting)

Only available on the professional edition

since 8.6 List Azure projects Requires the ‘Create Projects’ permission

Parameters:almSetting – ALM setting key
Returns:
list_bitbucketserver_projects(almSetting)

Only available on the professional edition

since 8.2 List the Bitbucket Server projects Requires the ‘Create Projects’ permission

Parameters:almSetting – ALM setting key
Returns:
search_azure_repos(almSetting, projectName=None, searchQuery=None)

Only available on the professional edition

since 8.6 Search the Azure repositories Requires the ‘Create Projects’ permission

Parameters:
  • almSetting – ALM setting key
  • projectName – Project name filter
  • searchQuery – Search query filter
Returns:

search_bitbucketclound_repos(almSetting, repositoryName=None, p=None, ps=None)

Only available on the professional edition

since 9.0 Search the Bitbucket Cloud repositories Requires the ‘Create Projects’ permission

Parameters:
  • almSetting – ALM setting key
  • repositoryName – Repository name filter
  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 100
Returns:

search_bitbucketserver_repos(almSetting, projectName=None, repositoryName=None)

Only available on the professional edition

since 8.2 Search the Bitbucket Server repositories with REPO_ADMIN access Requires the ‘Create Projects’ permission

Parameters:
  • almSetting – ALM setting key
  • projectName – Project name filter
  • repositoryName – Repository name filter
Returns:

search_gitlab_repos(almSetting, p=None, projectName=None, ps=None)

Only available on the professional edition

since 8.5 Search the GitLab projects. Requires the ‘Create Projects’ permission

Parameters:
  • almSetting – ALM setting key
  • p – 1-based page number
  • projectName – Project name filter
  • ps – Page size. Must be greater than 0 and less or equal than 500
Returns:

set_pat(almSetting, pat, username=None)

Only available on the professional edition

since 8.2 Set a Personal Access Token for the given ALM setting Only valid for Azure DevOps, Bitbucket Server & GitLab Alm Setting Requires the ‘Create Projects’ permission

Parameters:
  • almSetting – ALM setting key
  • pat – Personal Access Token
  • username – Username
Returns:

sonarqube.rest.alm_settings module

class sonarqube.rest.alm_settings.SonarQubeAlmSettings(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

count_binding(almSetting)

Only available on the professional edition

since 8.1 Count number of project bound to an ALM setting. Requires the ‘Administer System’ permission

Parameters:almSetting – ALM setting key
Returns:
create_azure(key, personalAccessToken, url)

Only available on the professional edition

since 8.1 Create Azure ALM instance Setting. Requires the ‘Administer System’ permission

Parameters:
  • key – Unique key of the Azure Devops instance setting
  • personalAccessToken – Azure Devops personal access token
  • url – Azure API URL
Returns:

create_bitbucket(key, personalAccessToken, url)

Only available on the professional edition

since 8.1 Create Bitbucket ALM instance Setting. Requires the ‘Administer System’ permission

Parameters:
  • key – Unique key of the Bitbucket instance setting
  • personalAccessToken – Bitbucket personal access token
  • url – BitBucket server API URL
Returns:

create_bitbucketcloud(clientId, clientSecret, key, workspace)

Only available on the professional edition

since 8.7 Configure a new instance of Bitbucket Cloud. Requires the ‘Administer System’ permission

Parameters:
  • clientId – Bitbucket Cloud Client ID
  • clientSecret – Bitbucket Cloud Client Secret
  • key – Unique key of the Bitbucket Cloud setting
  • workspace – Bitbucket Cloud workspace ID
Returns:

create_github(appId, clientId, clientSecret, key, privateKey, url)

Only available on the professional edition

since 8.1 Create GitHub ALM instance Setting. Requires the ‘Administer System’ permission

Parameters:
  • appId – GitHub App ID
  • clientId – GitHub App Client ID
  • clientSecret – GitHub App Client Secret
  • key – Unique key of the GitHub instance setting
  • privateKey – GitHub App private key
  • url – GitHub API URL
Returns:

create_gitlab(key, personalAccessToken, url)

Only available on the professional edition

since 8.1 Create GitLab ALM instance Setting. Requires the ‘Administer System’ permission

Parameters:
  • key – Unique key of the GitLab instance setting
  • personalAccessToken – GitLab personal access token
  • url – GitLab API URL
Returns:

delete(key)

Only available on the professional edition

since 8.1 Delete an ALM Settings. Requires the ‘Administer System’ permission

Parameters:key – ALM Setting key
Returns:
delete_binding(project)

Only available on the professional edition

since 8.1 Delete the ALM setting binding of a project. Requires the ‘Administer’ permission on the project

Parameters:project – Project key
Returns:
get_alm_setting(key)

Only available on the professional edition

get_binding(project)

Only available on the professional edition

SINCE 8.1 Get ALM binding of a given project. Requires the ‘Administer’ permission on the project

Parameters:project – Project key
Returns:
list(project=None)

Only available on the professional edition

since 8.1 List ALM setting available for a given project, sorted by ALM key Requires the ‘Administer project’ permission if the ‘project’ parameter is provided, requires the ‘Create Projects’ permission otherwise.

Parameters:project – Project key
Returns:
list_definitions()

Only available on the professional edition

since 8.1 List ALM Settings, sorted by created date. Requires the ‘Administer System’ permission

Returns:
set_azure_binding(almSetting, project, projectName, repositoryName, monorepo='false')

Only available on the professional edition

since 8.1 Bind a Azure DevOps ALM instance to a project. If the project was already bound to a previous Azure DevOps ALM instance, the binding will be updated to the new one.Requires the ‘Administer’ permission on the project

Parameters:
  • almSetting – Azure ALM setting key
  • project – SonarQube project key
  • projectName – Azure project name
  • repositoryName – Azure repository name
  • monorepo – Is this project part of a monorepo (since 8.7)
Returns:

set_bitbucket_binding(almSetting, project, repository, slug, monorepo='false')

Only available on the professional edition

since 8.1 Bind a Bitbucket ALM instance to a project. If the project was already bound to a previous Bitbucket ALM instance, the binding will be updated to the new one.Requires the ‘Administer’ permission on the project

Parameters:
  • almSetting – Bitbucket ALM setting key
  • project – Project key
  • repository – Bitbucket repository key
  • slug – Bitbucket repository slug
  • monorepo – Is this project part of a monorepo (since 8.7)
Returns:

set_bitbucketcloud_binding(almSetting, project, repository, monorepo='false')

Only available on the professional edition

since 8.7 Bind a Bitbucket Cloud setting to a project. If the project was already bound to a previous Bitbucket Cloud setting, the binding will be updated to the new one.Requires the ‘Administer’ permission on the project

Parameters:
  • almSetting – Bitbucket ALM setting key
  • project – Project key
  • repository – Bitbucket Cloud repository key
  • monorepo – Is this project part of a monorepo
Returns:

set_github_binding(almSetting, project, repository, summaryCommentEnabled='true', monorepo='false')

Only available on the professional edition

since 8.1 Bind a GitHub ALM instance to a project. If the project was already bound to a previous GitHub ALM instance, the binding will be updated to the new one.Requires the ‘Administer’ permission on the project

Parameters:
  • almSetting – GitHub ALM setting key
  • project – Project key
  • repository – GitHub Repository
  • summaryCommentEnabled – Enable/disable summary in PR discussion tab
  • monorepo – Is this project part of a monorepo (since 8.7)
Returns:

set_gitlab_binding(almSetting, project, repository, monorepo='false')

Only available on the professional edition

since 8.1 Bind a GitLab instance to a project. If the project was already bound to a previous Gitlab ALM instance, the binding will be updated to the new one.Requires the ‘Administer’ permission on the project

Parameters:
  • almSetting – GitLab ALM setting key
  • project – Project key
  • repository – GitLab project ID
  • monorepo – Is this project part of a monorepo (since 8.7)
Returns:

update_azure(key, personalAccessToken, url, newKey=None)

Only available on the professional edition

since 8.1 Update Azure ALM instance Setting. Requires the ‘Administer System’ permission

Parameters:
  • key – Unique key of the Azure instance setting
  • personalAccessToken – Azure Devops personal access token
  • url – Azure API URL
  • newKey – Optional new value for an unique key of the Azure Devops instance setting
Returns:

update_bitbucket(key, personalAccessToken, url, workspace, newKey=None)

Only available on the professional edition

since 8.7 Update Bitbucket ALM instance Setting. Requires the ‘Administer System’ permission

Parameters:
  • key – Unique key of the Bitbucket instance setting
  • personalAccessToken – Bitbucket personal access token
  • url – Bitbucket API URL
  • workspace – Bitbucket Cloud workspace ID
  • newKey – Optional new value for an unique key of the Bitbucket instance setting
Returns:

update_github(appId, clientId, clientSecret, key, privateKey, url, newKey=None)

Only available on the professional edition

since 8.1 Update GitHub ALM instance Setting. Requires the ‘Administer System’ permission

Parameters:
  • appId – GitHub API ID
  • clientId – GitHub App Client ID
  • clientSecret – GitHub App Client Secret
  • key – Unique key of the GitHub instance setting
  • privateKey – GitHub App private key
  • url – GitHub API URL
  • newKey – Optional new value for an unique key of the GitHub instance setting
Returns:

update_gitlab(key, personalAccessToken, url, newKey=None)

Only available on the professional edition

since 8.1 Update GitLab ALM instance Setting. Requires the ‘Administer System’ permission

Parameters:
  • key – Unique key of the GitLab instance setting
  • personalAccessToken – GitLab personal access token
  • url – GitLab API URL
  • newKey – Optional new value for an unique key of the GitLab instance setting
Returns:

validate(key)

Only available on the professional edition

since 8.6 Validate an ALM Setting by checking connectivity and permissions Requires the ‘Administer System’ permission

Parameters:key – Unique key of the ALM settings
Returns:
validate_binding(project)

Only available on the professional edition

since 9.0 Validate a project binding setting by checking connectivity and permissions Requires project ‘Browse’ permission

Parameters:project – Project key
Raises:ValidationError
Returns:

sonarqube.rest.analysis_cache module

class sonarqube.rest.analysis_cache.SonarQubeAnalysisCache(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

get_analysis_cache(project, branch=None)

Only available on the professional edition

since 9.4 Get the scanner’s cached data for a branch. Requires scan permission on the project. Data is returned gzipped if the corresponding ‘Accept-Encoding’ header is set in the request.

Parameters:
  • project – Project key
  • branch – Branch key. If not provided, main branch will be used.
Returns:

sonarqube.rest.applications module

class sonarqube.rest.applications.SonarQubeApplications(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube applications Operations

add_project(application, project)

Only available on the professional edition

SINCE 7.3 Add project to application.

Parameters:
  • application – Application key
  • project – Project key
Returns:

create_application(name, key=None, visibility=None, description=None)

Only available on the professional edition

SINCE 7.3 Create a new application.

Parameters:
  • description – Application description
  • key – Application key. A suitable key will be generated if not provided
  • name – Name of the Application.
  • visibility

    Whether the created project should be visible to everyone, or only specific user/groups. If no visibility is specified, the default project visibility of the organization will be used. Possible values are for:

    • private
    • public
Returns:

request response

create_branch(application, branch, project, projectBranch)

Only available on the professional edition

SINCE 7.3 Create a new branch on a given application.

Parameters:
  • application – Application key
  • branch – Branch name
  • project – Project keys.To set several values, the parameter must be called once for each value.
  • projectBranch – Project branches.To set main branch, provide an empty value. To set several values, the parameter must be called once for each value.
Returns:

delete_application(application)

Only available on the professional edition

SINCE 7.3 Delete an application definition.

Parameters:application – Application key
Returns:
delete_branch(application, branch)

Only available on the professional edition

SINCE 7.3 Delete a branch on a given application.

Parameters:
  • application – Application key
  • branch – Branch name
Returns:

remove_project(application, project)

Only available on the professional edition

SINCE 7.3 Remove project to application.

Parameters:
  • application – Application key
  • project – Project key
Returns:

set_tags(application, tags)

Only available on the professional edition

SINCE 8.3 Set tags on a application.

Parameters:tags – Comma-separated list of tags
Returns:
show_application(application, branch=None)

Only available on the professional edition

SINCE 7.3 Returns an application and its associated projects.

Parameters:
  • application – Application key
  • branch – Branch name
Returns:

update_application(application, name, description=None)

Only available on the professional edition

SINCE 7.3 Update an application.

Parameters:
  • application – Application key
  • name – New name for the application
  • description – New description for the application
Returns:

update_branch(application, branch, name, project, projectBranch)

Only available on the professional edition

SINCE 7.3 Update a branch on a given application.

Parameters:
  • application – Application key
  • branch – Branch name
  • name – New branch name
  • project – Project keys.To set several values, the parameter must be called once for each value.
  • projectBranch – Project branches.To set main branch, provide an empty value. To set several values, the parameter must be called once for each value.
Returns:

sonarqube.rest.audit_logs module

class sonarqube.rest.audit_logs.SonarQubeAuditLogs(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube audit logs Operations

download_audit_logs(from_date, to_date)

Available on all editions

since 9.1 Returns security related audits of this SonarQube instance.

Parameters:
  • from_date – Date in ISO 8601 datetime format (YYYY-MM-DDThh:mm:ss±hh:mm) from which the logs will be returned. Inclusive.
  • to_date – Date in ISO 8601 datetime format (YYYY-MM-DDThh:mm:ss±hh:mm) until which the logs will be returned. Inclusive.
Returns:

sonarqube.rest.auth module

class sonarqube.rest.auth.SonarQubeAuth(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube authentication Operations

authenticate_user(login, password)

Only available on the professional edition

SINCE 6.0 Authenticate a user.

Parameters:
  • login – Login of the user
  • password – Password of the user
Returns:

check_credentials()

Available on all editions

SINCE 3.3 Check credentials.

Returns:
logout_user()

Only available on the professional edition

SINCE 6.3 Logout a user.

Returns:

sonarqube.rest.ce module

class sonarqube.rest.ce.SonarQubeCe(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube ce Operations

Only available on the professional edition

SINCE 5.5 Returns CE activity related metrics.

Parameters:component – Key of the component (project) to filter on
Returns:
get_ce_analysis_status(component, branch=None, pullRequest=None)

Only available on the professional edition

Get last analysis status including warnings of a given component (usually a project).

Parameters:
  • branch – Branch key
  • component – Component key
  • pullRequest – Pull request id
Returns:

get_component_queue_and_current_tasks(component)

Only available on the professional edition

SINCE 5.2 Get the pending tasks, in-progress tasks and the last executed task of a given component (usually a project).

Parameters:component – Component key
Returns:
get_task(id, additionalFields=None)

Only available on the professional edition

SINCE 5.2 Give Compute Engine task details such as type, status, duration and associated component.

Parameters:
  • id – Id of task
  • additionalFields – Comma-separated list of the optional fields to be returned in response. Possible values are for: stacktrace,scannerContext,warnings
Returns:

search_tasks(component=None, componentId=None, maxExecutedAt=None, minSubmittedAt=None, onlyCurrents=None, p=None, ps=None, q=None, status=None, type=None)

Available on all editions

SINCE 5.2 Search for tasks.

Parameters:
  • component – Key of the component (project) to filter on (since 8.0)
  • componentId – Id of the component (project) to filter on
  • maxExecutedAt – Maximum date of end of task processing (inclusive)
  • minSubmittedAt – Minimum date of task submission (inclusive)
  • onlyCurrents – Filter on the last tasks (only the most recent finished task by project). default value is false.
  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 1000
  • q

    Limit search to:

    • component names that contain the supplied string
    • component keys that are exactly the same as the supplied string
    • task ids that are exactly the same as the supplied string

      Must not be set together with componentId

  • status

    Comma separated list of task statuses. Possible values are for:

    • SUCCESS
    • FAILED
    • CANCELED
    • PENDING
    • IN_PROGRESS

    default value is SUCCESS,FAILED,CANCELED

  • type – Task type. Possible values: * REPORT * ISSUE_SYNC * APP_REFRESH * PROJECT_EXPORT * PROJECT_IMPORT * VIEW_REFRESH
Returns:

sonarqube.rest.components module

class sonarqube.rest.components.SonarQubeComponents(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube components Operations

get_components_tree(component, branch=None, pullRequest=None, asc='true', p=None, ps=None, q=None, qualifiers=None, s='name', strategy='all')

Only available on the professional edition

SINCE 5.4 Navigate through components based on the chosen strategy. When limiting search with the q parameter, directories are not returned.

Parameters:
  • component – Base component key. The search is based on this component.
  • asc – Ascending sort. default value is true.
  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 500
  • branch – Branch key. Not available in the community edition.
  • pullRequest – Pull request id.Not available in the community edition.
  • q

    Limit search to:

    • component names that contain the supplied string
    • component keys that are exactly the same as the supplied string
:param qualifiers:Comma-separated list of component qualifiers. Filter the results with

the specified qualifiers. Possible values are:

  • BRC - Sub-projects
  • DIR - Directories
  • FIL - Files
  • TRK - Projects
  • UTS - Test Files
Parameters:
  • s – Comma-separated list of sort fields,Possible values are for: name, path, qualifier, and default value is name
  • strategy

    Strategy to search for base component descendants:

    • children: return the children components of the base component. Grandchildren components are not returned
    • all: return all the descendants components of the base component. Grandchildren are returned.
    • leaves: return all the descendant components (files, in general) which don’t have other children. They are the leaves of the component tree.

    default value is all.

Returns:

get_project_component_and_ancestors(component, branch=None, pullRequest=None)

Only available on the professional edition

SINCE 5.4 Returns a component (file, directory, project, view…) and its ancestors. The ancestors are ordered from the parent to the root project.

Parameters:
  • component – Component key
  • branch – Branch key. Not available in the community edition.
  • pullRequest – Pull request id. Not available in the community edition.
Returns:

search_components(qualifiers, organization=None, language=None, q=None, p=None, ps=None)

Only available on the professional edition

SINCE 6.3 Search for components

Parameters:
  • qualifiers

    Comma-separated list of component qualifiers. Filter the results with the specified qualifiers. Possible values are:

    • BRC - Sub-projects
    • DIR - Directories
    • FIL - Files
    • TRK - Projects
    • UTS - Test Files
  • organization – Organization key
  • language – Language key. If provided, only components for the given language are returned.
  • q

    Limit search to:

    • component names that contain the supplied string
    • component keys that are exactly the same as the supplied string
  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 500
Returns:

search_projects(f=None, asc='true', facets=None, filter=None, s='name', p=None, ps=None)

Only available on the professional edition

Search for projects

SINCE 6.2

Parameters:
  • f – Comma-separated list of the fields to be returned in response
  • asc – Ascending sort
  • facets – Comma-separated list of the facets to be computed. No facet is computed by default.
  • filter – Filter of projects on name, key, measure value, quality gate, language, tag or whether a project is a favorite or not.
  • s – Sort projects by numeric metric key, quality gate status (using ‘alert_status’), last analysis date (using ‘analysisDate’), or by project name.
  • p – page number
  • ps – Page size. Must be greater than 0 and less or equal than 500

sonarqube.rest.duplications module

class sonarqube.rest.duplications.SonarQubeDuplications(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube duplications Operations

get_duplications(key, branch=None, pullRequest=None)

Available on all editions

SINCE 4.4 Get duplications. Require Browse permission on file’s project

Parameters:
  • key – File key
  • branch – Branch key
  • pullRequest – Pull request id
Returns:

sonarqube.rest.editions module

class sonarqube.rest.editions.SonarQubeEditions(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

Manage SonarSource commercial editions

set_license(license)

Available on all editions

since 7.2 Set the license for enabling features of commercial editions. Require ‘Administer System’ permission.

Parameters:license
Returns:

sonarqube.rest.favorites module

class sonarqube.rest.favorites.SonarQubeFavorites(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube favorites Operations

add_component_to_favorites(component)

Only available on the professional edition

SINCE 6.3 Add a component (project, file etc.) as favorite for the authenticated user.

Parameters:component – Component key. Only components with qualifiers TRK, VW, SVW, APP, FIL, UTS are supported
Returns:
remove_component_from_favorites(component)

Only available on the professional edition

SINCE 6.3 Remove a component (project, directory, file etc.) as favorite for the authenticated user.

Parameters:component – Component key
Returns:
search_favorites(p=None, ps=None)

Available on all editions

SINCE 6.3 Search for the authenticated user favorites. :param p: page number. :param ps: Page size. Must be greater than 0 and less or equal than 500

Returns:

sonarqube.rest.hotspots module

class sonarqube.rest.hotspots.SonarQubeHotspots(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube Security Hotspots Operations

change_hotspots_status(hotspot, status, comment=None, resolution=None)

Only available on the professional edition

since 8.1 Change the status of a Security Hotpot. Requires the ‘Administer Security Hotspot’ permission.

Parameters:
  • hotspot – Key of the Security Hotspot
  • status – New status of the Security Hotspot.
  • comment – Comment text.
  • resolution – Resolution of the Security Hotspot when new status is REVIEWED, otherwise must not be set.
Returns:

search_hotspots(branch=None, hotspots=None, onlyMine=None, projectKey=None, p=None, ps=None, pullRequest=None, resolution=None, sinceLeakPeriod=None, status=None, cwe=None, files=None, inNewCodePeriod=None, owaspAsvsLevel=None, owaspTop10=None, sonarsourceSecurity=None)

Only available on the professional edition

SINCE 8.1 Search for security hotspots.

Parameters:
  • branch – Branch key. Not available in the community edition.
  • hotspots – Comma-separated list of Security Hotspot keys. This parameter is required unless projectKey is provided.
  • onlyMine

    If ‘projectKey’ is provided, returns only Security Hotspots assigned to the current user. Possible values are

    • true
    • false
    • yes
    • no
  • projectKey – Key of the project or application. This parameter is required unless hotspots is provided.
  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 500
  • pullRequest – Pull request id. Not available in the community edition.
  • resolution

    If ‘projectKey’ is provided and if status is ‘REVIEWED’, only Security Hotspots with the specified resolution are returned. Possible values are

    • FIXED
    • SAFE
  • sinceLeakPeriod

    If ‘%s’ is provided, only Security Hotspots created since the leak period are returned. Possible values are

    • true
    • false
    • yes
    • no
  • status

    If ‘projectKey’ is provided, only Security Hotspots with the specified status are returned. Possible values are

    • TO_REVIEW
    • REVIEWED
  • cwe – Comma-separated list of CWE numbers
  • files – Comma-separated list of files. Returns only hotspots found in those files
  • inNewCodePeriod – If ‘inNewCodePeriod’ is provided, only Security Hotspots created in the new code period are returned.
  • owaspAsvsLevel – Filters hotspots with lower or equal OWASP ASVS level to the parameter value. Should be used in combination with the ‘owaspAsvs-4.0’ parameter.
  • owaspTop10 – Comma-separated list of OWASP 2017 Top 10 lowercase categories.
  • sonarsourceSecurity – Comma-separated list of SonarSource security categories. Use ‘others’ to select issues not associated with any category
show(hotspot)

Only available on the professional edition

SINCE 8.1 Provides the details of a Security Hotspot.

Parameters:hotspot – Key of the Security Hotspot
Returns:

sonarqube.rest.issues module

class sonarqube.rest.issues.SonarQubeIssues(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube issues Operations

MAX_SEARCH_NUM = 100
get_issue(key)

Available on all editions

get_issue_changelog(issue)

Only available on the professional edition

SINCE 4.1 Display changelog of an issue.

Parameters:issue – Issue key
Returns:
get_issues_tags(project=None, branch=None, all=None, q=None, ps=None)

Only available on the professional edition

SINCE 5.1 List tags

Parameters:
  • project
  • branch – Branch key. since 9.2
  • all – Indicator to search for all tags or only for tags in the main branch of a project. since 9.2
  • q – Limit search to tags that contain the supplied string.
  • ps – Page size.
Returns:

issue_add_comment(issue, text)

Only available on the professional edition

SINCE 3.6 Add a comment.

Parameters:
  • issue – Issue key
  • text – Comment text
Returns:

request response

issue_assign(issue, assignee=None)

Available on all editions

SINCE 3.6 Assign/Unassign an issue

Parameters:
  • issue – Issue key
  • assignee – Login of the assignee. When not set, it will unassign the issue. Use ‘_me’ to assign to current user
Returns:

request response

issue_change_severity(issue, severity)

Only available on the professional edition

SINCE 3.6 Change severity.

Parameters:
  • issue – Issue key
  • severity

    New severity.Possible values are for:

    • INFO
    • MINOR
    • MAJOR
    • CRITICAL
    • BLOCKER
Returns:

request response

issue_delete_comment(comment)

Only available on the professional edition

SINCE 3.6 Delete a comment.

Parameters:comment – Comment key
Returns:request response
issue_do_transition(issue, transition)

Only available on the professional edition

SINCE 3.6 Do workflow transition on an issue. Requires authentication and Browse permission on project. The transitions ‘wontfix’ and ‘falsepositive’ require the permission ‘Administer Issues’. The transitions involving security hotspots require the permission ‘Administer Security Hotspot’.

Parameters:
  • issue – Issue key
  • transition

    Transition.Possible values are for:

    • confirm
    • unconfirm
    • reopen
    • resolve
    • falsepositive
    • wontfix
    • close
    • setinreview
    • resolveasreviewed
    • openasvulnerability
    • resetastoreview
Returns:

request response

issue_edit_comment(comment, text)

Only available on the professional edition

SINCE 3.6 Edit a comment.

Parameters:
  • comment – Comment key
  • text – Comment text
Returns:

request response

issue_set_tags(issue, tags=None)

Only available on the professional edition

SINCE 5.1 Set tags on an issue.

Parameters:
  • issue – Issue key
  • tags – Comma-separated list of tags. All tags are removed if parameter is empty or not set. such as: security,cwe,misra-c
Returns:

request response

issue_set_type(issue, type)

Only available on the professional edition

SINCE 5.5 Change type of issue, for instance from ‘code smell’ to ‘bug’.

Parameters:
  • issue – Issue key
  • type

    New type.Possible values are for:

    • CODE_SMELL
    • BUG
    • VULNERABILITY
    • SECURITY_HOTSPOT
Returns:

request response

issues_bulk_change(issues, add_tags=None, assign=None, comment=None, do_transition=None, remove_tags=None, sendNotifications=None, set_severity=None, set_type=None)

Only available on the professional edition

SINCE 3.7 Bulk change on issues.

Parameters:issues – Comma-separated list of issue keys

optional parameters: :param add_tags: Add tags.such as: security,java8 :param assign: To assign the list of issues to a specific user (login), or un-assign all the issues :param comment: To add a comment to a list of issues :param do_transition: Transition, Possible values are for:

  • confirm
  • unconfirm
  • reopen
  • resolve
  • falsepositive
  • wontfix
  • close
  • setinreview
  • resolveasreviewed
  • openasvulnerability
  • resetastoreview
Parameters:
  • remove_tags – Remove tags.such as: security,java8
  • sendNotifications – Possible values are for: true, false, yes, no. default value is false.
  • set_severity

    To change the severity of the list of issues. Possible values are for:

    • INFO
    • MINOR
    • MAJOR
    • CRITICAL
    • BLOCKER
  • set_type

    To change the type of the list of issues. Possible values are for:

    • CODE_SMELL
    • BUG
    • VULNERABILITY
    • SECURITY_HOTSPOT
Returns:

request response

reindex_issues(project)

Only available on the professional edition

SINCE 9.8 Reindex issues for a project.

Parameters:project – Project key
search_issues(organization=None, componentKeys=None, branch=None, pullRequest=None, additionalFields=None, asc='true', assigned=None, assignees=None, author=None, createdAfter=None, createdAt=None, createdBefore=None, createdInLast=None, cwe=None, facets=None, issues=None, languages=None, onComponentOnly='false', owaspTop10=None, p=None, ps=None, resolutions=None, resolved=None, rules=None, s=None, sansTop25=None, severities=None, sinceLeakPeriod='false', sonarsourceSecurity=None, statuses=None, tags=None, types=None, scopes=None, timeZone=None, codeVariants=None, inNewCodePeriod=None, owaspAsvsLevel=None)

Available on all editions

SINCE 3.6 Search for issues.

Parameters:
  • organization – Organization key
  • componentKeys – Comma-separated list of component keys. Retrieve issues associated to a specific list of components (and all its descendants). A component can be a portfolio, project, module, directory or file.
  • branch – Branch key.
  • pullRequest – Pull request id.
  • additionalFields

    Comma-separated list of the optional fields to be returned in response. Possible values are for:

    • _all
    • comments
    • languages
    • actionPlans
    • rules
    • transitions
    • actions
    • users
  • asc – Ascending sort. Possible values are for: true, false, yes, no.default value is true
  • assigned – To retrieve assigned or unassigned issues. Possible values are for: true, false, yes, no
  • assignees – Comma-separated list of assignee logins. The value ‘__me__’ can be used as a placeholder for user who performs the request
  • author – SCM accounts. To set several values, the parameter must be called once for each value.
  • componentKeys – Comma-separated list of component keys. Retrieve issues associated to a specific list of components (and all its descendants). A component can be a portfolio, project, module, directory or file.
  • createdAfter – To retrieve issues created after the given date (inclusive). Either a date (server timezone) or datetime can be provided. If this parameter is set, createdSince must not be set
  • createdBefore – To retrieve issues created before the given date (inclusive). Either a date (server timezone) or datetime can be provided.
  • createdAt – Datetime to retrieve issues created during a specific analysis
  • createdInLast – To retrieve issues created during a time span before the current time (exclusive). Accepted units are ‘y’ for year, ‘m’ for month, ‘w’ for week and ‘d’ for day. If this parameter is set, createdAfter must not be set.such as: 1m2w (1 month 2 weeks)
  • cwe – Comma-separated list of CWE identifiers. Use ‘unknown’ to select issues not associated to any CWE.
  • facets

    Comma-separated list of the facets to be computed. No facet is computed by default. Possible values are for:

    • projects
    • moduleUuids
    • fileUuids
    • assigned_to_me
    • severities
    • statuses
    • resolutions
    • rules
    • assignees
    • authors
    • author
    • directories
    • languages
    • tags
    • types
    • owaspTop10
    • sansTop25
    • cwe
    • createdAt
    • sonarsourceSecurity
  • issues – Comma-separated list of issue keys
  • languages – Comma-separated list of languages. such as: java,js
  • onComponentOnly – Return only issues at a component’s level, not on its descendants (modules, directories, files, etc). This parameter is only considered when componentKeys or componentUuids is set. Possible values are for: true, false, yes, no. default value is false.
  • owaspTop10 – Comma-separated list of OWASP Top 10 lowercase categories.
  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 500
  • resolutions

    Comma-separated list of resolutions.Possible values are for:

    • FALSE-POSITIVE
    • WONTFIX
    • FIXED
    • REMOVED
  • resolved – To match resolved or unresolved issues. Possible values are for: true, false, yes, no
  • rules – Comma-separated list of coding rule keys. Format is <repository>:<rule>.such as: squid:AvoidCycles
  • s

    Sort field. Possible values are for:

    • CREATION_DATE
    • UPDATE_DATE
    • CLOSE_DATE
    • ASSIGNEE
    • SEVERITY
    • STATUS
    • FILE_LINE
  • sansTop25

    Comma-separated list of SANS Top 25 categories. Possible values are for:

    • insecure-interaction
    • risky-resource
    • porous-defenses
  • severities

    Comma-separated list of severities.Possible values are for:

    • INFO
    • MINOR
    • MAJOR
    • CRITICAL
    • BLOCKER
  • sinceLeakPeriod – To retrieve issues created since the leak period.If this parameter is set to a truthy value, createdAfter must not be set and one component id or key must be provided. Possible values are for: true, false, yes, no. default value is false.
  • sonarsourceSecurity

    Comma-separated list of SonarSource security categories. Use ‘others’ to select issues not associated with any category。Possible values are for:

    • sql-injection
    • command-injection
    • path-traversal-injection
    • ldap-injection
    • xpath-injection
    • rce
    • dos
    • ssrf
    • csrf
    • xss
    • log-injection
    • http-response-splitting
    • open-redirect
    • xxe
    • object-injection
    • weak-cryptography
    • auth
    • insecure-conf
    • file-manipulation
    • others
  • statuses

    Comma-separated list of statuses.Possible values are for:

    • OPEN
    • CONFIRMED
    • REOPENED
    • RESOLVED
    • CLOSED
    • TO_REVIEW
    • IN_REVIEW
    • REVIEWED
  • tags – Comma-separated list of tags.such as: security,convention
  • types

    Comma-separated list of types.Possible values are for:

    • CODE_SMELL
    • BUG
    • VULNERABILITY
  • scopes – Comma-separated list of scopes. Available since 8.5
  • timeZone – To resolve dates passed to ‘createdAfter’ or ‘createdBefore’ (does not apply to datetime) and to compute creation date histogram
  • codeVariants – Comma-separated list of code variants.
  • inNewCodePeriod – To retrieve issues created in the new code period. If this parameter is set to a truthy value, createdAfter must not be set and one component uuid or key must be provided.
  • owaspAsvsLevel – Level of OWASP ASVS categories.
Returns:

search_scm_accounts(project, q=None, ps=None)

Only available on the professional edition

SINCE 5.1 Search SCM accounts which match a given query

Parameters:
  • project – Project key
  • q – Limit search to authors that contain the supplied string.
  • ps – Page size. Must be greater than 0 and less or equal than 100
Returns:

sonarqube.rest.languages module

class sonarqube.rest.languages.SonarQubeLanguages(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube languages Operations

get_supported_programming_languages(q=None)

Available on all editions

SINCE 5.1 List supported programming languages

Parameters:q – A pattern to match language keys/names against
Returns:

sonarqube.rest.measures module

class sonarqube.rest.measures.SonarQubeMeasures(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube measures Operations

get_component_tree_with_specified_measures(component, metricKeys, branch=None, pullRequest=None, asc='true', additionalFields=None, metricPeriodSort=None, metricSort=None, metricSortFilter='all', p=None, ps=None, q=None, s='name', qualifiers=None, strategy='all')

Only available on the professional edition

SINCE 5.4 Navigate through components based on the chosen strategy with specified measures. The baseComponentId or the component parameter must be provided.

Parameters:
  • component – Component key.
  • branch – Branch key.
  • pullRequest – Pull request id.
  • metricKeys – Comma-separated list of metric keys. Possible values are for: ncloc,complexity,violations
  • additionalFields – Comma-separated list of additional fields that can be returned in the response. Possible values are for: metrics,periods
  • asc – Ascending sort, Possible values are for: true, false, yes, no. default value is true.
  • metricPeriodSort – Sort measures by leak period or not ?. The ‘s’ parameter must contain the ‘metricPeriod’ value
  • metricSort – Metric key to sort by. The ‘s’ parameter must contain the ‘metric’ or ‘metricPeriod’ value. It must be part of the ‘metricKeys’ parameter
  • metricSortFilter

    Filter components. Sort must be on a metric. Possible values are:

    • all: return all components
    • withMeasuresOnly: filter out components that do not have a measure on the sorted metric

    default value is all.

  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 500
  • q

    Limit search to:

    • component names that contain the supplied string
    • component keys that are exactly the same as the supplied string
:param qualifiers:Comma-separated list of component qualifiers. Filter the results with

the specified qualifiers. Possible values are:

  • BRC - Sub-projects
  • DIR - Directories
  • FIL - Files
  • TRK - Projects
  • UTS - Test Files
Parameters:
  • s – Comma-separated list of sort fields,Possible values are for: name, path, qualifier, metric, metricPeriod. and default value is name
  • strategy

    Strategy to search for base component descendants:

    • children: return the children components of the base component. Grandchildren components are not returned
    • all: return all the descendants components of the base component. Grandchildren are returned.
    • leaves: return all the descendant components (files, in general) which don’t have other children. They are the leaves of the component tree.

    default value is all.

Returns:

get_component_with_specified_measures(component, metricKeys, branch=None, pullRequest=None, additionalFields=None)

Available on all editions

SINCE 5.4 Return component with specified measures.

Parameters:
  • component – Component key
  • branch – Branch key.
  • pullRequest – Pull request id.
  • additionalFields – Comma-separated list of additional fields that can be returned in the response. Possible values are for: metrics,periods
  • metricKeys – Comma-separated list of metric keys. Possible values are for: ncloc,complexity,violations
Returns:

search_measures_history(component, metrics, branch=None, pullRequest=None, from_date=None, to_date=None, p=None, ps=None)

Only available on the professional edition

SINCE 6.3 Search measures history of a component

Parameters:
  • component – Component key.
  • branch – Branch key.
  • pullRequest – Pull request id.
  • metrics – Comma-separated list of metric keys.Possible values are for: ncloc,coverage,new_violations
  • from_date – Filter measures created after the given date (inclusive). Either a date (server timezone) or datetime can be provided
  • to_date – Filter measures created before the given date (inclusive). Either a date (server timezone) or datetime can be provided
  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 500
Returns:

special_attributes_map = {'from_date': 'from', 'to_date': 'to'}

sonarqube.rest.metrics module

class sonarqube.rest.metrics.SonarQubeMetrics(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube metrics Operations

get_metrics_types()

Available on all editions

SINCE 5.2 List all available metric types.

Returns:
search_metrics(p=None, ps=None)

Available on all editions

SINCE 5.2 Search for metrics

Parameters:
  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 500
Returns:

sonarqube.rest.monitoring module

class sonarqube.rest.monitoring.SonarQubeMonitoring(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube monitoring Operations

get_monitoring_metrics()

Only available on the professional edition

since 9.3 Return monitoring metrics in Prometheus format. Support content type ‘text/plain’ (default) and ‘application/openmetrics-text’. this endpoint can be access using a Bearer token, that needs to be defined in sonar.properties with the ‘sonar.web.systemPasscode’ key.

Returns:

sonarqube.rest.new_code_periods module

class sonarqube.rest.new_code_periods.SonarQubeNewcodeperiods(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube new code periods Operations

list(project)

Only available on the professional edition

SINCE 8.0 List the New Code Periods for all branches in a project.

Parameters:project – Project key
Returns:
set(type, project=None, branch=None, value=None)

Only available on the professional edition

SINCE 8.0 Updates the setting for the New Code Period on different levels:

  • Project key must be provided to update the value for a project
  • Both project and branch keys must be provided to update the value for a branch
Parameters:
  • type – Type New code periods of the following types are allowed: * SPECIFIC_ANALYSIS - can be set at branch level only * PREVIOUS_VERSION - can be set at any level (global, project, branch) * NUMBER_OF_DAYS - can be set at any level (global, project, branch) * REFERENCE_BRANCH - can only be set for projects and branches
  • project – Project key
  • branch – Branch key
  • value – Value For each type, a different value is expected: * the uuid of an analysis, when type is SPECIFIC_ANALYSIS * no value, when type is PREVIOUS_VERSION * a number, when type is NUMBER_OF_DAYS * a string, when type is REFERENCE_BRANCH
Returns:

show(project=None, branch=None)

Only available on the professional edition

SINCE 8.0 Shows a setting for the New Code Period.

Parameters:
  • project – Project key
  • branch – Branch key
Returns:

unset(project=None, branch=None)

Only available on the professional edition

SINCE 8.0 Unset the New Code Period setting for a branch, project or global.

Parameters:
  • project – Project key
  • branch – Branch key
Returns:

sonarqube.rest.notifications module

class sonarqube.rest.notifications.SonarQubeNotifications(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube notifications Operations

add_notification_for_user(login, type, channel='EmailNotificationChannel', project=None)

Only available on the professional edition

SINCE 6.3 Add a notification for the authenticated user.

Parameters:
  • login – User login
  • type

    Notification type. Possible values are for:

    • Global notifications: CeReportTaskFailure, ChangesOnMyIssue, NewAlerts, SQ-MyNewIssues
    • Per project notifications: CeReportTaskFailure, ChangesOnMyIssue, NewAlerts, NewFalsePositiveIssue, NewIssues, SQ-MyNewIssues
  • channel – Channel through which the notification is sent. For example, notifications can be sent by email. default value is EmailNotificationChannel.
  • project – Project key
Returns:

get_user_notifications(login)

Only available on the professional edition

SINCE 6.3 List notifications of the authenticated user.

Parameters:login – User login
Returns:
remove_notification_for_user(login, type, channel='EmailNotificationChannel', project=None)

Only available on the professional edition

SINCE 6.3 Remove a notification for the authenticated user.

Parameters:
  • login – User login
  • type

    Notification type. Possible values are for:

    • Global notifications: CeReportTaskFailure, ChangesOnMyIssue, NewAlerts, SQ-MyNewIssues
    • Per project notifications: CeReportTaskFailure, ChangesOnMyIssue, NewAlerts, NewFalsePositiveIssue, NewIssues, SQ-MyNewIssues
  • channel – Channel through which the notification is sent. For example, notifications can be sent by email. default value is EmailNotificationChannel.
  • project – Project key
Returns:

sonarqube.rest.permissions module

class sonarqube.rest.permissions.SonarQubePermissions(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube permissions Operations

add_group_to_template(groupName, templateName, permission, organization=None)

Only available on the professional edition

SINCE 5.2 Add a group to a permission template.

Parameters:
  • groupName – Group name or ‘anyone’ (case insensitive)
  • templateName – Template name
  • permission

    Permission Possible values are for:

    • Possible values for project permissions admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
  • organization – Key of organization
Returns:

add_permission_to_group(groupName, permission, organization=None, projectKey=None)

Only available on the professional edition

SINCE 5.2 Add permission to a group. This service defaults to global permissions, but can be limited to project permissions by providing project key. The group name must be provided.

Parameters:
  • groupName – Group name or ‘anyone’ (case insensitive)
  • permission

    Permission. Possible values are for:

    • Possible values for global permissions: admin, profileadmin, gateadmin, scan, provisioning
    • Possible values for project permissions admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
  • organization – Key of organization
  • projectKey – Project key
Returns:

add_permission_to_user(login, permission, organization=None, projectKey=None)

Only available on the professional edition

SINCE 5.2 Add permission to a user. This service defaults to global permissions, but can be limited to project permissions by providing project key.

Parameters:
  • login – User login
  • permission

    Permission Possible values are for:

    • Possible values for global permissions: admin, profileadmin, gateadmin, scan, provisioning
    • Possible values for project permissions admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
  • organization – Key of organization
  • projectKey – Project key
Returns:

add_project_creator_to_template(templateName, permission, organization=None)

Only available on the professional edition

SINCE 6.0 Add a project creator to a permission template.

Parameters:
  • templateName – Template name
  • permission

    Permission Possible values are for:

    • Possible values for project permissions admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
  • organization – Key of organization
Returns:

add_user_to_template(login, templateName, permission, organization=None)

Only available on the professional edition

SINCE 5.2 Add a user to a permission template.

Parameters:
  • login – User login
  • templateName – Template name
  • permission

    Permission Possible values are for:

    • Possible values for project permissions admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
  • organization – Key of organization
Returns:

apply_template_to_project(templateName, projectKey, organization=None)

Only available on the professional edition

SINCE 5.2 Apply a permission template to one project.

Parameters:
  • templateName – Template name
  • projectKey – Project key
  • organization – Key of organization
Returns:

apply_template_to_projects(templateName, organization=None, projects=None, analyzedBefore=None, onProvisionedOnly='false', q=None, qualifiers='TRK')

Only available on the professional edition

SINCE 5.5 Apply a permission template to several projects.

Parameters:
  • templateName – Template name
  • organization – Key of organization
  • projects – Comma-separated list of project keys
  • analyzedBefore – Filter the projects for which last analysis is older than the given date (exclusive).
  • onProvisionedOnly – Filter the projects that are provisioned. Possible values are for: true or false. default value is false.
  • q

    Limit search to: Possible values are for:

    • project names that contain the supplied string
    • project keys that are exactly the same as the supplied string
  • qualifiers

    Comma-separated list of component qualifiers. Filter the results with the specified qualifiers. Possible values are:

    • TRK - Projects

    default value is TRK.

Returns:

create_template(name, organization=None, description=None, projectKeyPattern=None)

Only available on the professional edition

SINCE 5.2 Create a permission template.

Parameters:
  • name – Template name
  • organization – Key of organization
  • description – Template description
  • projectKeyPattern – Project key pattern. Must be a valid Java regular expression
Returns:

request response.

delete_template(templateName, organization=None)

Only available on the professional edition

SINCE 5.2 Delete a permission template.

Parameters:
  • templateName – Template name
  • organization – Key of organization
Returns:

get_groups_permissions(permission=None, projectKey=None, q=None, p=None, ps=None)

Only available on the professional edition

SINCE 5.2 Lists the groups with their permissions. This service defaults to global permissions, but can be limited to project permissions by providing project id or project key. This service defaults to all groups, but can be limited to groups with a specific permission by providing the desired permission.

Parameters:
  • permission

    Permission Possible values are for:

    • Possible values for global permissions: admin, profileadmin, gateadmin, scan, provisioning
    • Possible values for project permissions admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
  • projectKey – Project key
  • projectId – Project id
  • q – Limit search to group names that contain the supplied string
  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 500
Returns:

get_template(name, organization=None)

Only available on the professional edition

get_template_groups(templateId, permission=None, p=None, ps=None)

Only available on the professional edition

List of groups and their permissions for the specified template.

Parameters:
  • templateId – Id of permission template
  • permission – Possible values for project permissions admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 500

return: groups

get_template_users(templateId, permission=None, p=None, ps=None)

Only available on the professional edition

List of users and their permissions for the specified template.

Parameters:
  • templateId – Id of permission template
  • permission – Possible values for project permissions admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 500

return: users

get_users_permissions(permission=None, projectKey=None, q=None, p=None, ps=None)

Only available on the professional edition

SINCE 5.2 Lists the users with their permissions as individual users rather than through group affiliation. This service defaults to global permissions, but can be limited to project permissions by providing project id or project key. This service defaults to all users, but can be limited to users with a specific permission by providing the desired permission.

Parameters:
  • permission

    Permission Possible values are for:

    • Possible values for global permissions: admin, profileadmin, gateadmin, scan, provisioning
    • Possible values for project permissions admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
  • projectKey – Project key
  • q – Limit search to user names that contain the supplied string
  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 500
Returns:

remove_group_from_template(groupName, templateName, permission, organization=None)

Only available on the professional edition

SINCE 5.2 Remove a group from a permission template.

Parameters:
  • groupName – Group name or ‘anyone’ (case insensitive)
  • templateName – Template name
  • permission

    Permission Possible values are for:

    • Possible values for project permissions admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
  • organization – Key of organization
Returns:

remove_permission_from_group(groupName, permission, organization=None, projectKey=None)

Only available on the professional edition

SINCE 5.2 Remove a permission from a group. This service defaults to global permissions, but can be limited to project permissions by providing project key. The group name must be provided.

Parameters:
  • groupName – Group name or ‘anyone’ (case insensitive)
  • permission

    Permission Possible values are for:

    • Possible values for global permissions: admin, profileadmin, gateadmin, scan, provisioning
    • Possible values for project permissions admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
  • organization – Key of organization
  • projectKey – Project key
Returns:

remove_permission_from_user(login, permission, organization=None, projectKey=None)

Only available on the professional edition

SINCE 5.2 Remove permission from a user. This service defaults to global permissions, but can be limited to project permissions by providing project key.

Parameters:
  • login – User login
  • permission

    Permission Possible values are for:

    • Possible values for global permissions: admin, profileadmin, gateadmin, scan, provisioning
    • Possible values for project permissions admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
  • organization – Key of organization
  • projectKey – Project key
Returns:

remove_project_creator_from_template(templateName, permission, organization=None)

Only available on the professional edition

SINCE 6.0 Remove a project creator from a permission template.

Parameters:
  • templateName – Template name
  • permission

    Permission Possible values are for:

    • Possible values for project permissions admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
  • organization – Key of organization
Returns:

remove_user_from_template(login, templateName, permission, organization=None)

Only available on the professional edition

SINCE 5.2 Remove a user from a permission template.

Parameters:
  • login – User login
  • templateName – Template name
  • permission

    Permission Possible values are for:

    • Possible values for project permissions admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
  • organization – Key of organization
Returns:

search_templates(organization=None, q=None)

Only available on the professional edition

SINCE 5.2 List permission templates.

Parameters:
  • organization – Key of organization
  • q – Limit search to permission template names that contain the supplied string.
Returns:

defaultTemplates, permissionTemplates, permissions

set_default_template(templateName, organization=None, qualifier='TRK')

Only available on the professional edition

SINCE 5.2 Set a permission template as default.

Parameters:
  • templateName – Template name
  • organization – Key of organization
  • qualifier

    Project qualifier. Filter the results with the specified qualifier. Possible values are:

    • TRK - Projects

    default value is TRK.

Returns:

update_template(id, name=None, description=None, projectKeyPattern=None)

Only available on the professional edition

SINCE 5.2 Update a permission template.

Parameters:
  • id – Template id
  • name – Template name
  • description – Template description
  • projectKeyPattern – Project key pattern. Must be a valid Java regular expression
Returns:

request response

sonarqube.rest.plugins module

class sonarqube.rest.plugins.SonarQubePlugins(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube Plugins Operations

cancel_operation_pending_plugins()

Only available on the professional edition

SINCE 5.2 Cancels any operation pending on any plugin (install, update or uninstall)

Returns:
get_available_plugins()

Only available on the professional edition

SINCE 5.2 Get the list of all the plugins available for installation on the SonarQube instance, sorted by plugin name. Plugin information is retrieved from Update Center. Date and time at which Update Center was last refreshed is provided in the response. Update status values are:

  • COMPATIBLE: plugin is compatible with current SonarQube instance.
  • INCOMPATIBLE: plugin is not compatible with current SonarQube instance.
  • REQUIRES_SYSTEM_UPGRADE: plugin requires SonarQube to be upgraded before being installed.
  • DEPS_REQUIRE_SYSTEM_UPGRADE: at least one plugin on which the plugin is dependent requires SonarQube to be upgraded.
Returns:
get_available_update_plugins()

Only available on the professional edition

SINCE 5.2 Lists plugins installed on the SonarQube instance for which at least one newer version is available, sorted by plugin name. Each newer version is listed, ordered from the oldest to the newest, with its own update/compatibility status.Plugin information is retrieved from Update Center. Date and time at which Update Center was last refreshed is provided in the response. Update status values are: [COMPATIBLE, INCOMPATIBLE, REQUIRES_UPGRADE, DEPS_REQUIRE_UPGRADE].

Returns:
get_installed_plugins(f=None)

Only available on the professional edition

SINCE 5.2 Get the list of all the plugins installed on the SonarQube instance, sorted by plugin name.

Parameters:f

Comma-separated list of the additional fields to be returned in response. No additional field is returned by default. Possible values are:

  • category - category as defined in the Update Center. A connection to the Update Center is needed
Returns:
get_pending_plugins()

Only available on the professional edition

SINCE 5.2 Get the list of plugins which will either be installed or removed at the next startup of the SonarQube instance, sorted by plugin name.

Returns:
install_plugin(key)

Only available on the professional edition

SINCE 5.2 Installs the latest version of a plugin specified by its key. Plugin information is retrieved from Update Center.

Parameters:key – The key identifying the plugin to install
Returns:
uninstall_plugin(key)

Only available on the professional edition

SINCE 5.2 Uninstalls the plugin specified by its key.

Parameters:key – The key identifying the plugin to uninstall
Returns:
update_plugin(key)

Only available on the professional edition

SINCE 5.2 Updates a plugin specified by its key to the latest version compatible with the SonarQube instance. Plugin information is retrieved from Update Center.

Parameters:key – The key identifying the plugin to update
Returns:

sonarqube.rest.project_analyses module

class sonarqube.rest.project_analyses.SonarQubeProjectAnalyses(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube project analyses Operations

create_project_analysis_event(analysis, name, category='OTHER')

Only available on the professional edition

SINCE 6.3 Create a project analysis event.Only event of category ‘VERSION’ and ‘OTHER’ can be created.

Parameters:
  • analysis – Analysis key
  • name – Name
  • category

    Category. Possible values are for:

    • VERSION
    • OTHER

    default value is OTHER.

Returns:

request response

delete_project_analysis(analysis)

Available on all editions

SINCE 6.3 Delete a project analysis.

Parameters:analysis – Analysis key
Returns:
delete_project_analysis_event(event)

Only available on the professional edition

SINCE 6.3 Delete a project analysis event.Only event of category ‘VERSION’ and ‘OTHER’ can be deleted.

Parameters:event – Event key
Returns:
search_project_analyses_and_events(project, branch=None, category=None, from_date=None, to_date=None, p=None, ps=None)

Available on all editions

SINCE 6.3 Search a project analyses and attached events.

Parameters:
  • project – Project key
  • branch – Branch key
  • category

    Event category. Filter analyses that have at least one event of the category specified. Possible values are for:

    • VERSION
    • OTHER
    • QUALITY_PROFILE
    • QUALITY_GATE
    • DEFINITION_CHANGE
  • from_date – Filter analyses created after the given date (inclusive). Either a date (server timezone) or datetime can be provided
  • to_date – Filter analyses created before the given date (inclusive). Either a date (server timezone) or datetime can be provided
  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 500
Returns:

set_analysis_as_baseline_on_project(project, analysis, branch=None)

Only available on the professional edition

SINCE 7.7 DEPRECATED SINCE 8.0 Set an analysis as the baseline of the New Code Period on a project or a long-lived branch. This manually set baseline overrides the sonar.leak.period setting.

Parameters:
  • project – Project key
  • analysis – Analysis key
  • branch – Branch key
Returns:

special_attributes_map = {'from_date': 'from', 'to_date': 'to'}
unset_baseline_on_project(project, branch=None)

Only available on the professional edition

SINCE 7.7 DEPRECATED SINCE 8.0 Unset any manually-set New Code Period baseline on a project or a long-lived branch. Unsetting a manual baseline restores the use of the sonar.leak.period setting.

Parameters:
  • project – Project key
  • branch – Branch key
Returns:

update_project_analysis_event(event, name)

Only available on the professional edition

SINCE 6.3 Update a project analysis event. Only events of category ‘VERSION’ and ‘OTHER’ can be updated.

Parameters:
  • event – Event key
  • name – New name
Returns:

request response

sonarqube.rest.project_badges module

class sonarqube.rest.project_badges.SonarQubeProjectBadges(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube project badges Operations

generate_badge_for_project_measures(project, metric, branch=None, token=None)

Available on all editions

SINCE 7.1 Generate badge for project’s measure as an SVG.

Parameters:
  • project – Project or application key
  • branch – Long living branch key
  • metric

    Metric key, Possible values are for:

    • bugs
    • code_smells
    • coverage
    • duplicated_lines_density
    • ncloc
    • sqale_rating
    • alert_status
    • reliability_rating
    • security_rating
    • sqale_index
    • vulnerabilities
  • token – Security token
Returns:

generate_badge_for_project_quality_gate(project, branch=None, token=None)

Only available on the professional edition

SINCE 7.1 Generate badge for project’s quality gate as an SVG.

Parameters:
  • project – Project or application key
  • branch – Long living branch key
  • token – Security token
Returns:

generate_new_token_for_project_badge_access(project)

Only available on the professional edition

SINCE 9.2 Creates new token replacing any existing token for project badge access for private projects. This token can be used to authenticate with api/project_badges/quality_gate and api/project_badges/measure endpoints. Requires ‘Administer’ permission on the specified project.

Parameters:project – Project key
Returns:
retrieve_token_for_project_badge_access(project)

Only available on the professional edition

SINCE 9.2 Retrieve a token to use for project badge access for private projects. This token can be used to authenticate with api/project_badges/quality_gate and api/project_badges/measure endpoints. Requires ‘Browse’ permission on the specified project.

Parameters:project – Project or application key
Returns:

sonarqube.rest.project_branches module

class sonarqube.rest.project_branches.SonarQubeProjectBranches(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube project branches Operations

delete_project_branch(project, branch)

Only available on the professional edition

SINCE 6.6 Delete a non-main branch of a project.

Parameters:
  • project – Project key
  • branch – Name of the branch
Returns:

rename_project_branch(project, name)

Only available on the professional edition

SINCE 6.6 Rename the main branch of a project

Parameters:
  • project – Project key
  • name – New name of the main branch
Returns:

search_project_branches(project)

Available on all editions

SINCE 6.6 List the branches of a project.

Parameters:project – Project key
Returns:
set_automatic_deletion_protection_for_project_branch(project, branch, value)

Only available on the professional edition

SINCE 8.1 Protect a specific branch from automatic deletion. Protection can’t be disabled for the main branch.

Parameters:
  • project – Project key
  • branch – Branch key
  • value – Sets whether the branch should be protected from automatic deletion when it hasn’t been analyzed for a set period of time. Possible values are for: true or false, yes or no.
Returns:

sonarqube.rest.project_dump module

class sonarqube.rest.project_dump.SonarQubeProjectDump(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube Project export/import Operations

export_project_dump(key)

Available on all editions

SINCE 1.0 Triggers project dump so that the project can be copied to another SonarQube server (see api/project_dump/import).

Parameters:key
Returns:
import_project_dump(key)

Available on all editions

SINCE 1.0 Triggers the import of a project dump.

Parameters:key
Returns:

sonarqube.rest.project_pull_requests module

class sonarqube.rest.project_pull_requests.SonarQubeProjectPullRequests(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube project pull requests Operations

delete_project_pull_requests(project, pullRequest)

Only available on the professional edition

SINCE 7.1 Delete a pull request.

Parameters:
  • project – Project key
  • pullRequest – Pull request id
Returns:

search_project_pull_requests(project)

Only available on the professional edition

SINCE 7.1 List the pull requests of a project.

Parameters:project – Project key
Returns:

sonarqube.rest.project_tags module

class sonarqube.rest.project_tags.SonarQubeProjectTags(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube project tags Operations

search_project_tags(q=None, ps=None, p=None)

Available on all editions

SINCE 6.4 Search tags

Parameters:
  • q – Limit search to tags that contain the supplied string.
  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 100
Returns:

set_project_tags(project, tags)

Only available on the professional edition

SINCE 6.4 Set tags on a project.

Parameters:
  • project – Project key
  • tags – Comma-separated list of tags.Possible values are for: finance, offshore
Returns:

sonarqube.rest.projects module

class sonarqube.rest.projects.SonarQubeProjects(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube projects Operations

bulk_delete_projects(organization=None, analyzedBefore=None, onProvisionedOnly='false', projects=None, q=None, qualifiers='TRK')

Only available on the professional edition

SINCE 5.2 Delete one or several projects. At least one parameter is required among analyzedBefore, projects, projectIds (deprecated since 6.4) and q

Parameters:
  • organization – The key of the organization
  • analyzedBefore – Filter the projects for which last analysis is older than the given date (exclusive). Either a date (server timezone) or datetime can be provided.
  • onProvisionedOnly – Filter the projects that are provisioned. Possible values are for: true or false. default value is false.
  • projects – Comma-separated list of project keys
  • q
    Limit to:
    • component names that contain the supplied string
    • component keys that contain the supplied string
  • qualifiers

    Comma-separated list of component qualifiers. Filter the results with the specified qualifiers. Possible values are for:

    • TRK
    • VW
    • APP

    default value is TRK.

Returns:

create_project(project, name, organization=None, visibility=None, mainBranch=None)

Only available on the professional edition

SINCE 4.0 Create a project.

Parameters:
  • project – Key of the project
  • name – Name of the project. If name is longer than 500, it is abbreviated.
  • organization – The key of the organization
  • visibility

    Whether the created project should be visible to everyone, or only specific user/groups. If no visibility is specified, the default project visibility of the organization will be used. Possible values are for:

    • private
    • public
  • mainBranch – Key of the main branch of the project. If not provided, the default main branch key will be used. since 9.8
Returns:

request response

delete_project(project)

Only available on the professional edition

SINCE 5.2 Delete a project.

Parameters:project – Project key
Returns:
export_findings_for_project(project, branch=None, pullRequest=None)

Only available on the professional edition

SINCE 9.1 Export all findings (issues and hotspots) of a specific project branch.

Parameters:
  • project – Project key
  • branch – Branch key. When not specified, if no Pull Request key is defined either,

it will default to the main branch :param pullRequest: Pull Request key. When not specified, the branch data will be returned instead :return:

get_license_usage_for_project()

Only available on the professional edition

SINCE 9.4 Help admins to understand how the number of lines of code (used for licensing) is distributed between projects, i.e. how much each project affects the total number of lines of code. Returns the list of projects together with information about their usage, sorted by lines of code descending. Requires Administer System permission.

Returns:
get_project(key, organization=None)

Available on all editions

search_projects(organization=None, analyzedBefore=None, onProvisionedOnly='false', projects=None, p=None, ps=None, q=None, qualifiers='TRK')

Available on all editions

SINCE 6.3 Search for projects or views to administrate them.

Parameters:
  • organization – The key of the organization
  • analyzedBefore – Filter the projects for which last analysis is older than the given date (exclusive). Either a date (server timezone) or datetime can be provided.
  • onProvisionedOnly – Filter the projects that are provisioned. Possible values are for: true or false. default value is false.
  • projects – Comma-separated list of project keys
  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 500
  • q
    Limit search to:
    • component names that contain the supplied string
    • component keys that contain the supplied string
  • qualifiers

    Comma-separated list of component qualifiers. Filter the results with the specified qualifiers. Possible values are for:

    • TRK
    • VW
    • APP

    default value is TRK.

Returns:

special_attributes_map = {'new_project_key': 'to', 'previous_project_key': 'from'}
update_project_default_visibility(projectVisibility)

Only available on the professional edition

SINCE 6.4 Update the default visibility for new projects.

Parameters:projectVisibility – Default visibility for projects
Returns:
update_project_key(previous_project_key, new_project_key)

Only available on the professional edition

SINCE 6.1 Update a project or module key and all its sub-components keys.

Parameters:
  • previous_project_key – Project or module key
  • new_project_key – New component key
Returns:

update_project_visibility(project, visibility)

Only available on the professional edition

SINCE 6.4 Updates visibility of a project.

Parameters:
  • project – Project key
  • visibility – New visibility
Returns:

sonarqube.rest.qualitygates module

class sonarqube.rest.qualitygates.SonarQubeQualityGates(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube quality gates Operations

add_group_to_gate(gateName, groupName)

Only available on the professional edition

SINCE 9.2 Allow a group of users to edit a Quality Gate.

Parameters:
  • gateName – Quality Gate name
  • groupName – Group name or ‘anyone’ (case insensitive)
Returns:

add_user_to_gate(gateName, login)

Only available on the professional edition

SINCE 9.2 Allow a user to edit a Quality Gate.

Parameters:
  • gateName – Quality Gate name
  • login – User login
Returns:

copy_quality_gate(name, sourceName, organization=None)

Only available on the professional edition

SINCE 4.3 Copy a Quality Gate.

Parameters:
  • name – The name of the quality gate to create
  • sourceName – The name of the quality gate to copy. since 8.4
  • organization – Organization key. If no organization is provided, the default organization is used.
Returns:

create_condition_to_quality_gate(gateName, metric, error, op=None, organization=None)

Only available on the professional edition

SINCE 4.3 Add a new condition to a quality gate.

Parameters:
  • gateName – Name of the quality gate
  • metric

    Condition metric. Only metric of the following types are allowed:

    • INT
    • MILLISEC
    • RATING
    • WORK_DUR
    • FLOAT
    • PERCENT
    • LEVEL
  • error – Condition error threshold
  • op

    Condition operator Possible values are for:

    • LT = is lower than
    • GT = is greater than
  • organization – Organization key. If no organization is provided, the default organization is used.
Returns:

request response

create_quality_gate(name, organization=None)

Only available on the professional edition

SINCE 4.3 Create a Quality Gate.

Parameters:
  • name – The name of the quality gate to create
  • organization – Organization key. If no organization is provided, the default organization is used.
Returns:

request response

delete_condition_from_quality_gate(id, organization=None)

Only available on the professional edition

SINCE 4.3 Delete a condition from a quality gate.

Parameters:
  • id – Condition ID
  • organization – Organization key. If no organization is provided, the default organization is used.
Returns:

delete_quality_gate(name, organization=None)

Only available on the professional edition

SINCE 4.3 Delete a Quality Gate.

Parameters:
  • name – Name of the quality gate to delete. since 8.4
  • organization – Organization key. If no organization is provided, the default organization is used.
Returns:

get_project_qualitygates_status(projectKey=None, analysisId=None, branch=None, pullRequest=None)

Only available on the professional edition

SINCE 5.3 Get the quality gate status of a project or a Compute Engine task. return ‘ok’,’WARN’,’ERROR’ The NONE status is returned when there is no quality gate associated with the analysis. Returns an HTTP code 404 if the analysis associated with the task is not found or does not exist.

Parameters:
  • projectKey – Project key
  • analysisId – Analysis id
  • branch – Branch key
  • pullRequest
Returns:

get_quality_gate_of_project(project, organization=None)

Only available on the professional edition

SINCE 6.1 Get the quality gate of a project.

Parameters:
  • project – Project key
  • organization – Organization key. If no organization is provided, the default organization is used.
Returns:

get_quality_gates(organization=None)

Available on all editions

SINCE 4.3 Get a list of quality gates

Parameters:organization – Organization key. If no organization is provided, the default organization is used.
Returns:
get_qualitygate_projects(gateName, selected='selected', query=None, organization=None, page=None, pageSize=None)

Available on all editions

SINCE 4.3 Search for projects associated (or not) to a quality gate.

Parameters:
  • gateName – Quality Gate name. since 8.4
  • selected

    Depending on the value, show only selected items (selected=selected), deselected items (selected=deselected), or all items with their selection status (selected=all). Possible values are for:

    • all
    • deselected
    • selected

    default value is selected

  • query – To search for projects containing this string. If this parameter is set, “selected” is set to “all”.
  • organization – Organization key. If no organization is provided, the default organization is used.
  • page – page number.
  • pageSize – Page size.
Returns:

list_groups_allowed_to_gate(gateName, q=None, p=None, ps=None, selected=None)

Only available on the professional edition

SINCE 9.2 List the groups that are allowed to edit a Quality Gate.

Parameters:
  • gateName – Quality Gate name
  • q – Limit search to group names that contain the supplied string.
  • p – 1-based page number
  • ps – Page size. Must be greater than 0.
  • selected – Depending on the value, show only selected items (selected=selected), deselected items (selected=deselected), or all items with their selection status (selected=all).
Returns:

list_users_allowed_to_gate(gateName, q=None, p=None, ps=None, selected=None)

Only available on the professional edition

SINCE 9.2 List the users that are allowed to edit a Quality Gate.

Parameters:
  • gateName – Quality Gate name
  • q – Limit search to group names that contain the supplied string.
  • p – 1-based page number
  • ps – Page size. Must be greater than 0.
  • selected – Depending on the value, show only selected items (selected=selected), deselected items (selected=deselected), or all items with their selection status (selected=all).
Returns:

remove_group_from_gate(gateName, groupName)

Only available on the professional edition

SINCE 9.2 Remove the ability from a group to edit a Quality Gate.

Parameters:
  • gateName – Quality Gate name
  • groupName – Group name or ‘anyone’ (case insensitive)
Returns:

remove_project_from_quality_gate(projectKey, organization=None)

Only available on the professional edition

SINCE 4.3 Remove the association of a project from a quality gate.

Parameters:
  • projectKey – Project key
  • organization – Organization key. If no organization is provided, the default organization is used.
Returns:

remove_user_from_gate(gateName, login)

Only available on the professional edition

SINCE 9.2 Remove the ability from an user to edit a Quality Gate.

Parameters:
  • gateName – Quality Gate name
  • login – User login
Returns:

rename_quality_gate(currentName, name, organization=None)

Only available on the professional edition

SINCE 4.3 Rename a Quality Gate.

Parameters:
  • currentName – Current name of the quality gate
  • name – New name of the quality gate
  • organization – Organization key. If no organization is provided, the default organization is used.
Returns:

select_quality_gate_for_project(projectKey, gateName, organization=None)

Available on all editions

SINCE 4.3 Associate a project to a quality gate.

Parameters:
Returns:

set_default_qualitygate(name, organization=None)

Only available on the professional edition

SINCE 4.3 Set a quality gate as the default quality gate.

Parameters:
  • name – Name of the quality gate to set as default
  • organization – Organization key. If no organization is provided, the default organization is used.
Returns:

show_quality_gate(name, organization=None)

Only available on the professional edition

SINCE 4.3 Display the details of a quality gate.

Parameters:
  • name – Name of the quality gate.
  • organization – Organization key. If no organization is provided, the default organization is used.
Returns:

update_condition_to_quality_gate(id, metric, error, op=None, organization=None)

Only available on the professional edition

SINCE 4.3 Update a condition attached to a quality gate.

Parameters:
  • id – Condition ID
  • metric

    Condition metric. Only metric of the following types are allowed:

    • INT
    • MILLISEC
    • RATING
    • WORK_DUR
    • FLOAT
    • PERCENT
    • LEVEL
  • error – Condition error threshold
  • op

    Condition operator Possible values are for:

    • LT = is lower than
    • GT = is greater than
  • organization – Organization key. If no organization is provided, the default organization is used.
Returns:

sonarqube.rest.qualityprofiles module

class sonarqube.rest.qualityprofiles.SonarQubeQualityProfiles(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube quality profiles Operations

activate_rule_for_quality_profile(key, rule, reset=False, severity=None, **params)

Available on all editions

SINCE 4.4 Activate a rule for a given quality profile.

Parameters:
  • key – Quality Profile key.
  • rule – Rule key
  • reset – Reset severity and parameters of activated rule. Set the values defined on parent profile or from rule default values.
  • severity

    Severity. Ignored if parameter reset is true. Possible values are for:

    • INFO
    • MINOR
    • MAJOR
    • CRITICAL
    • BLOCKER
  • params – customized parameters for the rule.Ignored if parameter reset is true.
Returns:

add_group_to_quality_profile(group, language, qualityProfile)

Only available on the professional edition

SINCE 6.6 Allow a group of users to edit a Quality Profile.

Parameters:
  • group – Group name
  • language – Quality profile language
  • qualityProfile – Quality Profile name
Returns:

associate_project_with_quality_profile(project, language, qualityProfile, organization=None)

Only available on the professional edition

SINCE 5.2 Associate a project with a quality profile.

Parameters:
  • project – Project key.
  • language – Quality profile language.
  • qualityProfile – Quality profile name.
  • organization – organization key.
Returns:

backup_quality_profile(language, qualityProfile, organization=None)

Only available on the professional edition

SINCE 5.2 Backup a quality profile in XML form. The exported profile can be restored through api/qualityprofiles/restore.

Parameters:
  • language – Quality profile language.
  • qualityProfile – Quality profile name.
  • organization – organization key.
Returns:

change_parent_of_quality_profile(parentQualityProfile, language, qualityProfile, organization=None)

Only available on the professional edition

SINCE 5.2 Change a quality profile’s parent.

Parameters:
  • parentQualityProfile – Parent quality profile name.
  • language – Quality profile language.
  • qualityProfile – Quality profile name.
  • organization – organization key.
Returns:

copy_quality_profile(fromKey, toName)

Only available on the professional edition

SINCE 5.2 Copy a quality profile.

Parameters:
  • fromKey – Quality profile key
  • toName – Name for the new quality profile.
Returns:

request response

create_quality_profile(language, name, organization=None)

Only available on the professional edition

SINCE 5.2 Create a quality profile.

Parameters:
  • language – Quality profile language
  • name – Quality profile name
  • organization – organization key.
Returns:

request response

deactivate_rule_on_quality_profile(key, rule)

Only available on the professional edition

SINCE 4.4 Deactivate a rule on a quality profile.

Parameters:
  • key – Quality Profile key. Can be obtained through api/qualityprofiles/search
  • rule – Rule key
Returns:

delete_quality_profile(language, qualityProfile, organization=None)

Available on all editions

SINCE 5.2 Delete a quality profile and all its descendants. The default quality profile cannot be deleted.

Parameters:
  • language – Quality profile language.
  • qualityProfile – Quality profile name.
  • organization – Organization key.
Returns:

export_quality_profile(language, exporterKey=None, qualityProfile=None, organization=None)

Only available on the professional edition

SINCE 5.2 Export a quality profile.

Parameters:
  • language – Quality profile language
  • exporterKey

    Output format. If left empty, the same format as api/qualityprofiles/backup is used. Possible values are described by api/qualityprofiles/exporters. Possible values are for:

    • sonarlint-vs-vbnet
    • findbugs
    • pmd
    • sonarlint-vs-cs
    • roslyn-vbnet
    • roslyn-cs
  • qualityProfile – Quality profile name to export. If left empty, the default profile for the language

is exported. :param organization: Organization key. :return:

get_history_of_changes_on_quality_profile(language, qualityProfile, organization=None, since=None, to=None, p=None, ps=None)

Only available on the professional edition

SINCE 5.2 Get the history of changes on a quality profile: rule activation/deactivation, change in parameters/severity. Events are ordered by date in descending order (most recent first).

Parameters:
  • language – Quality profile language.
  • qualityProfile – Quality profile language.
  • organization – organization key.
  • since – Start date for the changelog. Either a date (server timezone) or datetime can be provided.
  • to – End date for the changelog. Either a date (server timezone) or datetime can be provided.
  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 500
Returns:

get_projects_associate_with_quality_profile(key, q=None, selected='selected', p=None, ps=None)

Only available on the professional edition

SINCE 5.2 List projects with their association status regarding a quality profile

Parameters:
  • key – Quality profile key
  • q – Limit search to projects that contain the supplied string.
  • selected

    Depending on the value, show only selected items (selected=selected), deselected items (selected=deselected), or all items with their selection status (selected=all). Possible values are for:

    • all
    • deselected
    • selected

    default value is selected.

  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 500
Returns:

get_supported_exporters()

Only available on the professional edition

SINCE 5.2 Lists available profile export formats.

Returns:
get_supported_importers()

Only available on the professional edition

SINCE 5.2 List supported importers.

Returns:
remove_project_associate_with_quality_profile(project, language, qualityProfile, organization=None)

Only available on the professional edition

SINCE 5.2 Remove a project’s association with a quality profile.

Parameters:
  • project – Project key
  • language – Quality profile language.
  • qualityProfile – Quality profile name.
  • organization – Organization key.
Returns:

rename_quality_profile(key, name)

Only available on the professional edition

SINCE 5.2 Rename a quality profile.

Parameters:
  • key – Quality profile key
  • name – New quality profile name
Returns:

restore_quality_profile(backup, organization=None)

Only available on the professional edition

SINCE 5.2 Restore a quality profile using an XML file. The restored profile name is taken from the backup file, so if a profile with the same name and language already exists, it will be overwritten.

Parameters:backup – A profile backup file in XML format, as generated by api/qualityprofiles/backup or the former api/profiles/backup.
Returns:
search_quality_profiles(organization=None, defaults='false', language=None, project=None, qualityProfile=None)

Available on all editions

SINCE 5.2 Search quality profiles

Parameters:
  • organization – organization key.
  • defaults – If set to true, return only the quality profiles marked as default for each language. Possible values are for: true or false. default value is false.
  • language – Language key. If provided, only profiles for the given language are returned.
  • project – Project key
  • qualityProfile – Quality profile name
Returns:

set_default_quality_profile(language, qualityProfile, organization=None)

Only available on the professional edition

SINCE 5.2 Select the default profile for a given language.

Parameters:
  • language – Quality profile language.
  • qualityProfile – Quality profile name.
  • organization – organization key.
Returns:

show_quality_profile(language, qualityProfile, organization=None)

Only available on the professional edition

SINCE 5.2 Show a quality profile’s ancestors and children.

Parameters:
  • language – Quality profile language.
  • qualityProfile – Quality profile name.
  • organization – Organization key.
Returns:

sonarqube.rest.rules module

class sonarqube.rest.rules.SonarQubeRules(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube rules Operations

create_rule(name, custom_key=None, customKey=None, markdown_description=None, markdownDescription=None, template_key=None, templateKey=None, prevent_reactivation=None, preventReactivation=None, severity=None, status=None, type=None, params=None)

Available on all editions

SINCE 4.4 Create a a custom rule.

Parameters:
  • OR customKey (custom_key) – Key of the custom rule
  • name – Rule name
  • OR markdown_description (markdown_description) – Rule description
  • OR templateKey (template_key) – Key of the template rule in order to create a custom rule (mandatory for custom rule)
  • OR preventReactivation (prevent_reactivation) – If set to true and if the rule has been deactivated (status ‘REMOVED’), a status 409 will be returned
  • severity

    Rule severity. Possible values are for:

    • INFO
    • MINOR
    • MAJOR
    • CRITICAL
    • BLOCKER
  • status

    Rule status. Possible values are for:

    • BETA
    • DEPRECATED
    • READY
    • REMOVED
  • type

    Rule type. Possible values are for:

    • CODE_SMELL
    • BUG
    • VULNERABILITY
    • SECURITY_HOTSPOT
  • params – Parameters as semi-colon list of =, for example ‘params=key1=v1;key2=v2’ (Only for custom rule)
Returns:

request response

delete_rule(key)

Only available on the professional edition

SINCE 4.4 Delete custom rule. :param key: :return:

get_rule(key, organization=None, actives='false')

Only available on the professional edition

SINCE 4.2 Get detailed information about a rule.

Parameters:
  • key – Rule key
  • organization – organization key.
  • actives – Show rule’s activations for all profiles (“active rules”). Possible values are for: true or false. default value is false.
Returns:

get_rule_repositories(language=None, q=None)

Only available on the professional edition

SINCE 4.5 List available rule repositories

Parameters:
  • language – A language key; if provided, only repositories for the given language will be returned
  • q – A pattern to match repository keys/names against
Returns:

get_rule_tags(organization=None, ps=10, q=None)

Only available on the professional edition

SINCE 4.4 List rule tags

Parameters:
  • organization – organization key.
  • ps – Page size. Must be greater than 0 and less or equal than 100.default value is 10.
  • q – Limit search to tags that contain the supplied string.
Returns:

search_rules(organization=None, activation=None, qprofile=None, languages=None, active_severities=None, asc='true', available_since=None, cwe=None, f=None, facets=None, include_external='false', inheritance=None, is_template=None, owaspTop10=None, p=None, ps=None, q=None, repositories=None, rule_key=None, s=None, sansTop25=None, severities=None, sonarsourceSecurity=None, statuses=None, tags=None, template_key=None, types=None)

Available on all editions

SINCE 4.4 Search for a collection of relevant rules matching a specified query.

Parameters:
  • organization – organization key.
  • activation – Filter rules that are activated or deactivated on the selected Quality profile. Ignored if the parameter ‘qprofile’ is not set.
  • qprofile – Quality profile key to filter on. Used only if the parameter ‘activation’ is set.
  • languages – Comma-separated list of languages
  • active_severities

    Comma-separated list of activation severities, i.e the severity of rules in Quality profiles. Possible values are for:

    • INFO
    • MINOR
    • MAJOR
    • CRITICAL
    • BLOCKER
  • asc – Ascending sort.Possible values are for: true, false, yes, no. default value is true
  • available_since – Filters rules added since date. Format is yyyy-MM-dd
  • cwe – Comma-separated list of CWE identifiers. Use ‘unknown’ to select rules not associated to any CWE.
  • f

    Comma-separated list of the fields to be returned in response. All the fields are returned by default, except actives.Since 5.5, following fields have been deprecated :

    • ”defaultDebtRemFn” becomes “defaultRemFn”
    • ”debtRemFn” becomes “remFn”
    • ”effortToFixDescription” becomes “gapDescription”
    • ”debtOverloaded” becomes “remFnOverloaded”

    Possible values are for:

    • actives
    • createdAt
    • debtOverloaded
    • debtRemFn
    • defaultDebtRemFn
    • defaultRemFn
    • effortToFixDescription
    • gapDescription
    • htmlDesc
    • htmlNote
    • internalKey
    • isExternal
    • isTemplate
    • lang
    • langName
    • mdDesc
    • mdNote
    • name
    • noteLogin
    • params
    • remFn
    • remFnOverloaded
    • repo
    • scope
    • severity
    • status
    • sysTags
    • tags
    • templateKey
    • updatedAt
  • facets

    Comma-separated list of the facets to be computed. No facet is computed by default. Possible values are for:

    • languages
    • repositories
    • tags
    • severities
    • active_severities
    • statuses
    • types
    • true
    • cwe
    • owaspTop10
    • sansTop25
    • sonarsourceSecurity
  • include_external – Include external engine rules in the results. Possible values are for: true, false, yes, no. default value is false.
  • inheritance

    Comma-separated list of values of inheritance for a rule within a quality profile. Used only if the parameter ‘activation’ is set. Possible values are for:

    • NONE
    • INHERITED
    • OVERRIDES
  • is_template – Filter template rules.Possible values are for: true, false, yes, no.
  • owaspTop10 – Comma-separated list of OWASP Top 10 lowercase categories.
  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 500
  • q – UTF-8 search query
  • repositories – Comma-separated list of repositories
  • rule_key – Key of rule to search for
  • s

    Sort field. Possible values are for:

    • name
    • updatedAt
    • createdAt
    • key
  • sansTop25

    Comma-separated list of SANS Top 25 categories. Possible values are for:

    • insecure-interaction
    • risky-resource
    • porous-defenses
  • severities

    Comma-separated list of default severities. Not the same than severity of rules in Quality profiles.Possible values are for:

    • INFO
    • MINOR
    • MAJOR
    • CRITICAL
    • BLOCKER
  • sonarsourceSecurity

    Comma-separated list of SonarSource security categories. Use ‘others’ to select rules not associated with any category. Possible values are for:

    • sql-injection
    • command-injection
    • path-traversal-injection
    • ldap-injection
    • xpath-injection
    • rce
    • dos
    • ssrf
    • csrf
    • xss
    • log-injection
    • http-response-splitting
    • open-redirect
    • xxe
    • object-injection
    • weak-cryptography
    • auth
    • insecure-conf
    • file-manipulation
    • others
  • statuses

    Comma-separated list of status codes. Possible values are for:

    • BETA
    • DEPRECATED
    • READY
    • REMOVED
  • tags – Comma-separated list of tags. Returned rules match any of the tags (OR operator). Possible values are for: security,java8
  • template_key – Key of the template rule to filter on. Used to search for the custom rules based on this template.
  • types

    Comma-separated list of types. Returned rules match any of the tags (OR operator).such as;

    • CODE_SMELL
    • BUG
    • VULNERABILITY
    • SECURITY_HOTSPOT
Returns:

update_rule(key, organization=None, name=None, markdown_description=None, markdown_note=None, remediation_fn_base_effort=None, remediation_fn_type=None, remediation_fy_gap_multiplier=None, severity=None, status=None, tags=None, params=None)

Only available on the professional edition

SINCE 4.4 Update an existing rule.

Parameters:
  • key – Key of the rule to update
  • organization – organization key.
  • name – Rule name (mandatory for custom rule)
  • markdown_description – Rule description (mandatory for custom rule and manual rule)
  • markdown_note – Optional note in markdown format. Use empty value to remove current note. Note is not changed if the parameter is not set.
  • params – Parameters as semi-colon list of =, for example ‘params=key1=v1;key2=v2’ (Only when updating a custom rule)
  • remediation_fn_base_effort – Base effort of the remediation function of the rule
  • remediation_fn_type – Type of the remediation function of the rule
  • remediation_fy_gap_multiplier – Gap multiplier of the remediation function of the rule
  • severity

    Rule severity (Only when updating a custom rule).Possible values are for:

    • INFO
    • MINOR
    • MAJOR
    • CRITICAL
    • BLOCKER
  • status

    Rule status (Only when updating a custom rule). Possible values are for:

    • BETA
    • DEPRECATED
    • READY
    • REMOVED
  • tags – Optional comma-separated list of tags to set. Use blank value to remove current tags. Tags are not changed if the parameter is not set.
Returns:

request response

sonarqube.rest.server module

class sonarqube.rest.server.SonarQubeServer(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube server Operations

get_server_version()

Available on all editions

SINCE 2.10 Version of SonarQube in plain text

Returns:

sonarqube.rest.settings module

class sonarqube.rest.settings.SonarQubeSettings(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube settings Operations

get_settings_definitions(component=None)

Only available on the professional edition

SINCE 6.3 List settings definitions.

Parameters:component – Component key
Returns:
get_settings_values(component=None, keys=None)

Only available on the professional edition

SINCE 6.3 List settings values. If no value has been set for a setting, then the default value is returned. The settings from conf/sonar.properties are excluded from results.

Parameters:
  • component – Component key
  • keys – List of setting keys
Returns:

remove_setting_value(keys, component=None)

Only available on the professional edition

SINCE 6.1 Remove a setting value. The settings defined in conf/sonar.properties are read-only and can’t be changed.

Parameters:
  • keys – Comma-separated list of keys
  • component – Component key
Returns:

update_setting_value(key, value, component=None, fieldValues=None)

Only available on the professional edition

SINCE 6.1 Update a setting value. The settings defined in conf/sonar.properties are read-only and can’t be changed.

Parameters:
  • key – Setting key
  • value – Setting value. To reset a value, please use the reset web service.
  • component – Component key
  • fieldValues – Setting field values. To set several values, the parameter must be called once for each value.
Returns:

sonarqube.rest.sources module

class sonarqube.rest.sources.SonarQubeSources(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube sources Operations

get_source_code(key, from_line=1, to_line=None)

Only available on the professional edition

SINCE 4.4 Get source code. Requires See Source Code permission on file’s project.

Parameters:
  • key – File key
  • from_line – First line to return. Starts at 1
  • to_line – Last line to return (inclusive)
Returns:

get_source_file_scm(key, from_line=1, to_line=None, commits_by_line='false')

Only available on the professional edition

SINCE 4.4 Get SCM information of source files. Require See Source Code permission on file’s project. Each element of the result array is composed of:

  • Line number
  • Author of the commit
  • Datetime of the commit (before 5.2 it was only the Date)
  • Revision of the commit (added in 5.2)
Parameters:
  • key – File key
  • from_line – First line to return. Starts at 1
  • to_line – Last line to return (inclusive)
  • commits_by_line – Group lines by SCM commit if value is false, else display commits for each line,even if two consecutive lines relate to the same commit. Possible values are for: true, false, yes, no. default value is false.
Returns:

get_sources_raw(key, branch=None, pullRequest=None)

Only available on the professional edition

SINCE 5.0 Get source code as raw text. Require ‘See Source Code’ permission on file.

Parameters:
  • key – File key
  • branch – Branch key
  • pullRequest – Pull request id
Returns:

special_attributes_map = {'from_line': 'from', 'to_line': 'to'}

sonarqube.rest.support module

sonarqube.rest.system module

class sonarqube.rest.system.SonarQubeSystem(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube system Operations

change_log_level(level)

Only available on the professional edition

SINCE 5.2 Temporarily changes level of logs. New level is not persistent and is lost when restarting server.

Parameters:level – The new level. Be cautious: DEBUG, and even more TRACE, may have performance impacts. Possible values are: TRACE, DEBUG, INFO.
Returns:
get_available_upgrades()

Only available on the professional edition

SINCE 5.2 Lists available upgrades for the SonarQube instance (if any) and for each one, lists incompatible plugins and plugins requiring upgrade.Plugin information is retrieved from Update Center. Date and time at which Update Center was last refreshed is provided in the response.

Returns:
get_database_migration_status()

Only available on the professional edition

SINCE 5.2 Display the database migration status of SonarQube. State values are:

  • NO_MIGRATION: DB is up to date with current version of SonarQube.
  • NOT_SUPPORTED: Migration is not supported on embedded databases.
  • MIGRATION_RUNNING: DB migration is under go.
  • MIGRATION_SUCCEEDED: DB migration has run and has been successful.
  • MIGRATION_FAILED: DB migration has run and failed. SonarQube must be restarted in order to retry a DB migration (optionally after DB has been restored from backup).
  • MIGRATION_REQUIRED: DB migration is required.
Returns:
get_detailed_information()

Only available on the professional edition

SINCE 5.1 Get detailed information about system configuration.

Returns:
get_health_status()

Only available on the professional edition

SINCE 6.6 Provide health status of SonarQube. State values are:

  • GREEN: SonarQube is fully operational
  • YELLOW: SonarQube is usable, but it needs attention in order to be fully operational
  • RED: SonarQube is not operational
Returns:
get_logs(process='app')

Only available on the professional edition

SINCE 5.2 Get system logs in plain-text format.

Parameters:process – Process to get logs from. Possible values are: app, ce, es, web. default value is app.
Returns:
get_server_state()

Only available on the professional edition

SINCE 5.2 Get state information about SonarQube. status: the running status

  • STARTING: SonarQube Web Server is up and serving some Web Services (eg. api/system/status) but initialization is still ongoing
  • UP: SonarQube instance is up and running
  • DOWN: SonarQube instance is up but not running because migration has failed
(refer to WS /api/system/migrate_db for details) or some other reason (check logs).
  • RESTARTING: SonarQube instance is still up but a restart has been requested (refer to WS /api/system/restart for details).
  • DB_MIGRATION_NEEDED: database migration is required. DB migration can be started using WS /api/system/migrate_db.
  • DB_MIGRATION_RUNNING: DB migration is running (refer to WS /api/system/migrate_db for details)
Returns:
migrate_database()

Only available on the professional edition

SINCE 5.2 Migrate the database to match the current version of SonarQube. Sending a POST request to this URL starts the DB migration. It is strongly advised to make a database backup before invoking this WS. State values are:

  • NO_MIGRATION: DB is up to date with current version of SonarQube.
  • NOT_SUPPORTED: Migration is not supported on embedded databases.
  • MIGRATION_RUNNING: DB migration is under go.
  • MIGRATION_SUCCEEDED: DB migration has run and has been successful.
  • MIGRATION_FAILED: DB migration has run and failed. SonarQube must be restarted in order to retry a DB migration (optionally after DB has been restored from backup).
  • MIGRATION_REQUIRED: DB migration is required.
Returns:request response
ping_server()

Only available on the professional edition

SINCE 6.3 Answers “pong” as plain-text

Returns:
restart_server()

Only available on the professional edition

SINCE 4.3 Restart server.

Returns:

sonarqube.rest.user_groups module

class sonarqube.rest.user_groups.SonarQubeUserGroups(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube user_groups Operations

add_user_to_group(name, login, organization=None)

Only available on the professional edition

SINCE 5.2 Add a user to a group.

Parameters:
  • name – Group name
  • organization – organization key.
  • login – User login
Returns:

create_group(name, organization=None, description=None)

Available on all editions

SINCE 5.2 Create a group.

Parameters:
  • name – Name for the new group. A group name cannot be larger than 255 characters and must be unique. The value ‘anyone’ (whatever the case) is reserved and cannot be used.
  • organization – organization key.
  • description – Description for the new group. A group description cannot be larger than 200 characters.
Returns:

request response

delete_group(name, organization=None)

Only available on the professional edition

SINCE 5.2 Delete a group. The default groups cannot be deleted.

Parameters:
  • name – group name
  • organization – organization key.
Returns:

get_user_group(name, organization=None)

Available on all editions

remove_user_from_group(name, login, organization=None)

Only available on the professional edition

SINCE 5.2 Remove a user from a group.

Parameters:
  • name – Group name
  • login – User login
  • organization – organization key.
Returns:

search_user_groups(organization=None, f=None, managed=None, q=None, p=None, ps=None)

Available on all editions

SINCE 5.2 Search for user groups.

Parameters:
  • organization – organization key.
  • f

    Comma-separated list of the fields to be returned in response. All the fields are returned by default. Possible values are for:

    • name
    • description
    • membersCount
  • managed – Return managed or non-managed groups. Only available for managed instances, throws for non-managed instances. (since 10.0)
  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 500
  • q – Limit search to names that contain the supplied string.
Returns:

search_users_belong_to_group(name, organization=None, q=None, selected='selected', p=None, ps=None)

Only available on the professional edition

SINCE 5.2 Search for users with membership information with respect to a group.

Parameters:
  • name – Group name
  • organization – organization key.
  • q – Limit search to names or logins that contain the supplied string.
  • selected

    Depending on the value, show only selected items (selected=selected), deselected items (selected=deselected), or all items with their selection status (selected=all).Possible values are for:

    • all
    • deselected
    • selected

    default value is selected.

  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 500
Returns:

update_group(currentName, name=None, description=None)

Available on all editions

SINCE 5.2 Update a group.

Parameters:
  • currentName – Name of the group to be updated. (since 8.5)
  • name – New optional name for the group. A group name cannot be larger than 255 characters and must be unique. Value ‘anyone’ (whatever the case) is reserved and cannot be used. If value is empty or not defined, then name is not changed.
  • description – New optional description for the group. A group description cannot be larger than 200 characters. If value is not defined, then description is not changed.
Returns:

sonarqube.rest.user_tokens module

class sonarqube.rest.user_tokens.SonarQubeUserTokens(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube user tokens Operations

generate_user_token(name, expirationDate=None, login=None, projectKey=None, type=None)

Available on all editions

SINCE 5.3 Generate a user access token. Please keep your tokens secret. They enable to authenticate and analyze projects. It requires administration permissions to specify a ‘login’ and generate a token for another user. Otherwise, a token is generated for the current user.

Parameters:
  • name – Token name
  • expirationDate – The expiration date of the token being generated, in ISO 8601 format (YYYY-MM-DD). If not set, default to no expiration. since 9.5
  • login – User login. If not set, the token is generated for the authenticated user.
  • projectKey – The key of the only project that can be analyzed by the PROJECT_ANALYSIS_TOKEN being generated. since 9.5
  • type – Token Type. If this parameters is set to PROJECT_ANALYSIS_TOKEN, it is necessary to provide the projectKey parameter too. since 9.5
Returns:

request response

revoke_user_token(name, login=None)

Available on all editions

SINCE 5.3 Revoke a user access token. It requires administration permissions to specify a ‘login’ and revoke a token for another user. Otherwise, the token for the current user is revoked.

Parameters:
  • name – Token name
  • login – User login
Returns:

search_user_tokens(login=None)

Available on all editions

SINCE 5.3 List the access tokens of a user. The login must exist and active. Field ‘lastConnectionDate’ is only updated every hour, so it may not be accurate, for instance when a user is using a token many times in less than one hour.

Parameters:login – User login
Returns:

sonarqube.rest.users module

class sonarqube.rest.users.SonarQubeUsers(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube users Operations

MAX_SEARCH_NUM = 200
anonymize_deactivated_user(login)

Only available on the professional edition

SINCE 9.7 Anonymize a deactivated user.

Parameters:login – User login
Returns:request response
change_user_password(login, password, previousPassword=None)

Only available on the professional edition

SINCE 5.2 Update a user’s password. Authenticated users can change their own password, provided that the account is not linked to an external authentication system. Administer System permission is required to change another user’s password.

Parameters:
  • login – User login
  • password – New password
  • previousPassword – Previous password. Required when changing one’s own password.
Returns:

create_user(login, name, email=None, password=None, local='true', scmAccount=None)

Only available on the professional edition

SINCE 3.7 Create a user.

Parameters:
  • login – User login
  • name – User name
  • email – User email
  • password – User password. Only mandatory when creating local user, otherwise it should not be set
  • local – Specify if the user should be authenticated from SonarQube server or from an external authentication system. Password should not be set when local is set to false. Possible values are for: true, false, yes, no. default value is true.
  • scmAccount – List of SCM accounts. To set several values, the parameter must be called once for each value.
Returns:

request response

current()

Only available on the professional edition

SINCE 5.2

Get the details of the current authenticated user.

deactivate_user(login, anonymize=None)

Only available on the professional edition

SINCE 3.7 Deactivate a user.

Parameters:
  • login – User login
  • anonymize – Anonymize user in addition to deactivating it. since 9.7
Returns:

request response

dismiss_sonarlint_advertisement()

Only available on the professional edition

SINCE 9.2 Dismiss SonarLint advertisement.

Returns:
get_user(login)

Available on all editions

search_groups_user_belongs_to(login, q=None, selected='selected', p=None, ps=None, organization=None)

Only available on the professional edition

SINCE 5.2 Lists the groups a user belongs to.

Parameters:
  • login
  • q – Limit search to group names that contain the supplied string.
  • selected

    Depending on the value, show only selected items (selected=selected), deselected items (selected=deselected), or all items with their selection status (selected=all).Possible values are for:

    • all
    • deselected
    • selected

    default value is selected.

  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 500
  • organization – organization key.
Returns:

search_users(deactivated=None, lastConnectedAfter=None, lastConnectedBefore=None, managed=None, slLastConnectedAfter=None, slLastConnectedBefore=None, q=None, p=None, ps=None)

Available on all editions

SINCE 3.6 Get a list of active users.

Parameters:
  • deactivated – Return deactivated users instead of active users
  • lastConnectedAfter – Filter the users based on the last connection date field.
  • lastConnectedBefore – Filter the users based on the last connection date field.
  • managed – Return managed or non-managed users.
  • slLastConnectedAfter – Filter the users based on the sonar lint last connection date field Only users who interacted with this instance using SonarLint at or after the date will be returned. The format must be ISO 8601 datetime format (YYYY-MM-DDThh:mm:ss±hhmm)
  • slLastConnectedBefore – Filter the users based on the sonar lint last connection date field. Only users that never connected or who interacted with this instance using SonarLint at or before the date will be returned. The format must be ISO 8601 datetime format (YYYY-MM-DDThh:mm:ss±hhmm)
  • q – Filter on login, name and email
  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 500
Returns:

update_identity_provider(login, newExternalProvider, newExternalIdentity=None)

Only available on the professional edition

SINCE 8.7 Update identity provider information.

Parameters:
  • login – User login
  • newExternalProvider – New external identity, usually the login used in the authentication system.

If not provided previous identity will be used. :param newExternalIdentity: New external provider. Only authentication system installed are available. Use ‘sonarqube’ identity provider for LDAP. :return:

update_user(login, name=None, email=None, scmAccount=None)

Only available on the professional edition

SINCE 3.7 Update a user.

Parameters:
  • login – User login
  • name – User name
  • email – User email
  • scmAccount – SCM accounts.
Returns:

request response

update_user_login(login, newLogin)

Only available on the professional edition

SINCE 7.6 Update a user login. A login can be updated many times.

Parameters:
  • login – The current login (case-sensitive)
  • newLogin – The new login. It must not already exist.
Returns:

sonarqube.rest.views module

class sonarqube.rest.views.SonarQubeViews(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

Manage Portfolios

add_application(application, portfolio)

Only available on the professional edition

SINCE 9.3 Add an existing application to a portfolio.

Parameters:
  • application – Key of the application to be added
  • portfolio – Key of the portfolio where the application will be added
Returns:

add_application_branch(application, branch, key)

Only available on the professional edition

SINCE 9.3 Add a branch of an application selected in a portfolio.

Parameters:
  • application – Key of the application
  • branch – Key of the branch
  • key – Key of the portfolio
Returns:

add_local_view(key, ref_key)

Only available on the professional edition

since 1.0 Add a local reference to an existing portfolio Authentication is required for this API endpoint

Parameters:
  • key – Key of the parent portfolio
  • ref_key – Key of the referenced local portfolio
Returns:

add_portfolio(portfolio, reference)

Only available on the professional edition

SINCE 9.3 Add an existing portfolio to the structure of another portfolio.

Parameters:
  • portfolio – Key of the portfolio where a reference will be added
  • reference – Key of the portfolio to be added
Returns:

add_project(key, project)

Only available on the professional edition

since 1.0 Add a project to a portfolio Requires ‘Administrator’ permission on the portfolio and ‘Browse’ permission for adding project

Parameters:
  • key – Key of the portfolio
  • project – Key of the project
Returns:

add_project_branch(project, branch, key)

Only available on the professional edition

SINCE 9.2 Add a branch of a project selected in a portfolio.

Parameters:
  • project – Key of the project
  • branch – Key of the branch
  • key – Key of the portfolio
Returns:

add_sub_view(key, name, description=None, subKey=None)

Only available on the professional edition

since 1.0 Add a portfolio to an existing portfolio Authentication is required for this API endpoint

Parameters:
  • key – Key of the parent portfolio
  • name – Name of the new portfolio
  • description – Description of the new portfolio, can be left blank
  • subKey – If specified, will be used for the new portfolio’s key instead of the default generated value
Returns:

create(name, description=None, key=None, visibility=None)

Only available on the professional edition

since 1.0 Create a new (root) portfolio. Requires ‘Administer System’ permission or ‘Create Portfolios’ permission

Parameters:
  • name – Name for the new portfolio
  • description – Description for the new portfolio, can be left blank
  • key – Key for the new portfolio. A suitable key will be generated if not provided
  • visibility – Whether the created portfolio or application should be visible to everyone, or only specific user/groups. If no visibility is specified, the default visibility of the organization will be used. Possible values: private, public
Returns:

define(definition)

Only available on the professional edition

since 1.0 Define the portfolio structure by uploading a XML definition file. The uploaded file is validated against the XML Schema available on the server and its structure is checked for inconsistencies (e.g loops in local references, duplicate project associations). If the file is deemed valid, the portfolio hierarchy is updated according to the contents of the file. Requires Provision Projects permission.

Parameters:definition – XML file to upload and validate
Returns:
definition()

Only available on the professional edition

since 2.0 Return the definition of the structure of portfolios in XML format. Requires Create Projects permission.

Returns:
delete(key)

Only available on the professional edition

since 1.0 Delete a portfolio definition. Requires ‘Administrator’ permission on the portfolio

Parameters:key – Portfolio key
Returns:
get_view(key)

Available on all editions

list()

Available on all editions

since 1.0 List root portfolios. Requires authentication. Only portfolios with the admin permission are returned.

Returns:
list_applications(portfolio)

Only available on the professional edition

SINCE 9.3 List applications which the user has access to that can be added to a portfolio.

Parameters:portfolio – Key of the would-be parent portfolio
Returns:
list_portfolios(portfolio)

Only available on the professional edition

SINCE 9.3 List portfolios that can be referenced.

Parameters:portfolio – Key of the would-be parent portfolio
Returns:
local_views(key)

Only available on the professional edition

since 1.0 List portfolios that can be locally referrenced Authentication is required for this API endpoint

Parameters:key – Key of the would-be parent portfolio
Returns:
move(destination, key)

Only available on the professional edition

since 1.0 Move a portfolio Authentication is required for this API endpoint

Parameters:
  • destination – Key of the destination portfolio
  • key – Key of the portfolio to move
Returns:

move_options(key)

Only available on the professional edition

since 1.0 List possible portfolio destinations Authentication is required for this API endpoint

Parameters:key – Key of the portfolio to move
Returns:
remove_application(application, portfolio)

Only available on the professional edition

SINCE 9.3 Remove an application from a portfolio.

Parameters:
  • application – Key of the application to be removed
  • portfolio – Portfolio key
Returns:

remove_application_branch(application, branch, key)

Only available on the professional edition

SINCE 9.3 Remove a branch of an application selected in a portfolio.

Parameters:
  • application – Key of the project
  • branch – Key of the branch
  • key – Key of the portfolio
Returns:

remove_portfolio(portfolio, reference)

Only available on the professional edition

SINCE 9.3 Remove a reference to a portfolio.

Parameters:
  • portfolio – Portfolio key
  • reference – Key of the referenced portfolio to be removed
Returns:

remove_project(key, project)

Only available on the professional edition

since 1.0 Remove a project from a portfolio Requires ‘Administrator’ permission on the portfolio

Parameters:
  • key – Key of the portfolio
  • project – Key of the project
Returns:

remove_project_branch(project, branch, key)

Only available on the professional edition

SINCE 9.2 Remove a branch of a project selected in a portfolio.

Parameters:
  • project – Key of the project
  • branch – Key of the branch
  • key – Key of the portfolio
Returns:

set_manual_mode(portfolio)

Only available on the professional edition

since 7.4 Set the projects selection mode of a portfolio on manual selection. In order to add project, please use api/view/add_project. Requires ‘Administrator’ permission on the portfolio

Parameters:portfolio – Key of the portfolio or sub-portfolio to update
Returns:
set_none_mode(portfolio)

Only available on the professional edition

SINCE 9.1 Set the projects selection mode of a portfolio to none. After setting this mode portfolio will not have any projects assigned. Requires ‘Administrator’ permission on the portfolio.

Parameters:portfolio – Key of the portfolio or sub-portfolio to update
Returns:
set_regexp_mode(portfolio, regexp)

Only available on the professional edition

since 7.4 Set the projects selection mode of a portfolio on regular expression. Requires ‘Administrator’ permission on the portfolio

Parameters:
  • portfolio – Key of the portfolio or sub-portfolio to update
  • regexp – A valid regexp with respect to the JDK’s java.util.regex.Pattern class
Returns:

set_remaining_projects_mode(portfolio)

Only available on the professional edition

since 7.4 Set the projects selection mode of a portfolio on unassociated projects in hierarchy. Requires ‘Administrator’ permission on the portfolio

Parameters:portfolio – Key of the portfolio or sub-portfolio to update
Returns:
set_tags_mode(portfolio, tags)

Only available on the professional edition

since 7.4 Set the projects selection mode of a portfolio on project tags. Requires ‘Administrator’ permission on the portfolio

Parameters:
  • portfolio – Key of the portfolio or sub-portfolio to update
  • tags – Comma-separated list of tags. It’s not possible to set nothing.
Returns:

show(key)

Available on all editions

since 1.0 Show the details of a portfolio, including its hierarchy and project selection mode. Authentication is required for this API endpoint

Parameters:key – The key of the portfolio
Returns:
special_attributes_map = {'definition': 'def'}
update(key, name, description=None)

Available on all editions

since 1.0 Update a portfolio. Requires ‘Administrator’ permission on the portfolio

Parameters:
  • key – Key of the portfolio to update
  • name – New name for the portfolio
  • description – New description for the application
Returns:

sonarqube.rest.webhooks module

class sonarqube.rest.webhooks.SonarQubeWebhooks(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube webhooks Operations

create_webhook(name, url, organization=None, project=None, secret=None)

Only available on the professional edition

SINCE 7.1 Create a Webhook.

Parameters:
  • name – Name displayed in the administration console of webhooks
  • url – Server endpoint that will receive the webhook payload, for example ‘http://my_server/foo’. If HTTP Basic authentication is used, HTTPS is recommended to avoid man in the middle attacks. Example: ‘https://myLogin:myPassword@my_server/foo
  • organization – organization key.
  • project – The key of the project that will own the webhook
  • secret – If provided, secret will be used as the key to generate the HMAC hex (lowercase) digest value in the ‘X-Sonar-Webhook-HMAC-SHA256’ header
Returns:

request response

delete_webhook(webhook)

Only available on the professional edition

SINCE 7.1 Delete a Webhook.

Parameters:webhook – The key of the webhook to be deleted, auto-generated value can be obtained through api/webhooks/create or api/webhooks/list
Returns:
get_webhook_deliveries(webhook=None, componentKey=None, ceTaskId=None, p=None, ps=None)

Only available on the professional edition

SINCE 6.2 Get the recent deliveries for a specified project or Compute Engine task.

Parameters:
  • webhook – Key of the webhook that triggered those deliveries
  • componentKey – Key of the project
  • ceTaskId – Id of the Compute Engine task
  • p – page number.
  • ps – Page size. Must be greater than 0 and less or equal than 500
Returns:

get_webhook_delivery(deliveryId)

Only available on the professional edition

SINCE 6.2 Get a webhook delivery by its id.

Parameters:deliveryId – Id of delivery
Returns:
search_webhooks(organization=None, project=None)

Only available on the professional edition

SINCE 7.1 Search for global webhooks or project webhooks. Webhooks are ordered by name.

Parameters:
  • organization – organization key.
  • project – Project key
Returns:

update_webhook(webhook, name, url, secret=None)

Only available on the professional edition

SINCE 7.1 Update a Webhook.

Parameters:
  • webhook – The key of the webhook to be updated
  • name – new name of the webhook
  • url – new url to be called by the webhook
  • secret – If provided, secret will be used as the key to generate the HMAC hex (lowercase) digest value in the ‘X-Sonar-Webhook-HMAC-SHA256’ header
Returns:

sonarqube.rest.webservices module

class sonarqube.rest.webservices.SonarQubeWebservices(**kwargs)

Bases: sonarqube.utils.rest_client.RestClient

SonarQube webservices Operations

list_web_services(include_internals='false')

Only available on the professional edition

SINCE 4.2 List web services

Parameters:include_internals – Include web services that are implemented for internal use only. Their forward-compatibility is not assured. Possible values are for: true or false. default value is false.
Returns:
web_service_response_example(action, controller)

Only available on the professional edition

SINCE 4.4 Display web service response example

Parameters:
  • action – Action of the web service
  • controller – Controller of the web service
Returns:

Module contents

class sonarqube.rest.SonarCloudClient(sonarqube_url=None, username=None, password=None, token=None, verify=None, cert=None, timeout=None)

Bases: sonarqube.rest.SonarQubeClient

class sonarqube.rest.SonarEnterpriseClient(sonarqube_url=None, username=None, password=None, token=None, verify=None, cert=None, timeout=None)

Bases: sonarqube.rest.SonarQubeClient

class sonarqube.rest.SonarQubeClient(sonarqube_url=None, username=None, password=None, token=None, verify=None, cert=None, timeout=None)

Bases: object

A Python Client for SonarQube Server APIs.

DEFAULT_URL = 'http://localhost:9000'
alm_integrations

ALM Integrations

alm_settings

ALM settings

analysis_cache

Analysis cache

applications

SonarQube applications Operations

Returns:
audit_logs

Manage Audit logs

auth

SonarQube authentication Operations

Returns:
ce

SonarQube ce Operations

Returns:
components

SonarQube components Operations

Returns:
static decode_response(response)
Returns:Decoded JSON content as a dict, or raw text if content could not be decoded as JSON.
Raises:requests.HTTPError if the response contains an HTTP error status code.
duplications

SonarQube duplications Operations

Returns:
editions

Manage SonarSource commercial editions

favorites

SonarQube favorites Operations

Returns:
get_endpoint_url(endpoint)

Return the complete url including host and port for a given endpoint. :param endpoint: service endpoint as str :return: complete url (including host and port) as str

hotspots

Security Hotspots

Returns:
issues

SonarQube issues Operations

Returns:
languages

SonarQube languages Operations

Returns:
measures

SonarQube measures Operations

Returns:
metrics

SonarQube metrics Operations

Returns:
monitoring
new_code_periods

SonarQube new code periods Operations

Returns:
notifications

SonarQube notifications Operations

Returns:
permissions

SonarQube permissions Operations

Returns:
plugins

SonarQube plugins Operations

Returns:
project_analyses

SonarQube project analyses Operations

Returns:
project_badges

SonarQube project badges Operations

Returns:
project_branches

SonarQube project branches Operations

Returns:
project_dump

Project export/import

Returns:

SonarQube project links Operations

Returns:
project_pull_requests

SonarQube project pull requests Operations

Returns:
project_tags

SonarQube project tags Operations

Returns:
projects

SonarQube projects Operations

Returns:
qualitygates

SonarQube quality gates Operations

Returns:
qualityprofiles

SonarQube quality profiles Operations

Returns:
request_get(endpoint, **kwargs)

Send HTTP GET to the endpoint.

Parameters:endpoint – The endpoint to send to.
Returns:
request_post(endpoint, **kwargs)

Send HTTP POST to the endpoint.

Parameters:endpoint – The endpoint to send to.
Returns:
rules

SonarQube rules Operations

Returns:
server

SonarQube server Operations

Returns:
settings

SonarQube settings Operations

Returns:
sources

SonarQube sources Operations

Returns:
system

SonarQube system Operations

Returns:
user_groups

SonarQube user_groups Operations

Returns:
user_tokens

SonarQube user tokens Operations

Returns:
users

SonarQube users Operations

Returns:
views

Manage Portfolios

webhooks

SonarQube webhooks Operations

Returns:
webservices

SonarQube webservices Operations

Returns: