Skip to main content
https://img.shields.io/github/license/kako-nawao/python-sonarqube-api.svg https://img.shields.io/pypi/pyversions/sonarqube-api.svg https://img.shields.io/pypi/v/sonarqube-api.svg https://img.shields.io/travis/kako-nawao/python-sonarqube-api.svg https://img.shields.io/codecov/c/github/kako-nawao/python-sonarqube-api.svg

API Handler for SonarQube web service, providing basic authentication (which seems to be the only kind that SonarQube supports) and a few methods to run sonarqube API.

Installation

Install from PyPI:

pip install opn-sonarqube-api

Compatibility

This package is compatible Python versions 2.7, 3.4, 3.5 and 3.6. Probably others, but those are the ones against which we build (by Travis CI).

Usage

The API handler is easy to use, you just need to initialize it with the connection parameters (by default localhost on port 9000 without authentication) and use any of the methods to get the required information or create rules.

Example getting projects with coverage and issues metrics:

from sonarqube_api.sonar import SonarAPI

h = SonarAPI(user='admin', password='admin')
for project in h.get_resources_full_data(metrics=['coverage', 'violations']):
    # do something with project data...

Since the actual response data from SonarQube server is usually paged, all methods return generators to optimize memory as well retrieval performance of the first items.

You can also specify a single resources to fetch, but keep in mind that the resource methods return generators, so you still need to get the next object:

proj = next(h.get_resources_full_data(resource='some:example'))

Sonar authentication tokens can also be used in place of username and password, which is particularly useful when accessing the SonarQube API from a CI server, as tokens can easily be revoked in the event of unintended exposure:

h = SonarAPI(token='f052f55b127bb06f63c31cb2064ea301048d9e5d')

Supported Methods

The methods supported by the SonarAPI are:

  • activate_rule: activate a rule for a given profile in the server

  • create_rule: create a rule in the server

  • get_metrics: yield metrics definition

  • get_rules: yield active rules

  • get_resources_debt: yield projects with their technical debt by category

  • get_resources_metrics: yield projects with some general metrics

  • get_resources_full_data: yield projects with their general metrics and technical debt by category (merge of previous two methods)

  • validate_authentication: validate authentication credentials

  • create_group

  • search_group

  • update_group

  • delete_group

  • create_permission_template

  • update_permission_template

  • search_permission_template

  • delete_permission_template

  • add_group_to_template

  • list_groups_of_template

  • remove_group_from_template

  • add_permission_to_user

  • remove_permission_to_user

  • add_permission_to_group

  • remove_permission_to_group

  • search_permission_for_group

  • generate_token

  • revoke_token

  • user_tokens

  • user_current

  • get_metrics

  • restore_quality_profile_from_xml

  • create_quality_profile

  • add_project_to_quality_profile

  • delete_quality_profile

  • activate_rule

  • get_resources_debt

  • get_resources_metrics

  • create_rule

  • get_rules

  • get_resources_full_data

  • setting

  • getting

  • list_qualitygates

  • show_qualitygates

  • create_qualitygates

  • destroy_qualitygates

  • create_condition_qualitygates

  • create_quality_gate_from_json

  • delete_condition_qualitygates

  • update_condition_qualitygates

Release files for opn-sonarqube-api 2.3.3.4261112

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for opn-sonarqube-api 2.3.3.4261112
File Size Uploaded
opn_sonarqube_api-2.3.3.4261112.tar.gz 20.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for opn-sonarqube-api 2.3.3.4261112
File Interpreter ABI Platform
opn_sonarqube_api-2.3.3.4261112-py2-none-any.whl Python 2 none any Details

Total release size: 48.8 kB

Release files / opn_sonarqube_api-2.3.3.4261112.tar.gz

Download URL opn_sonarqube_api-2.3.3.4261112.tar.gz
Size 20.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5ffb2f748dc9f3af762080b83ac5683f6d1e8252fca84b5a08dee12584ca2cff
BLAKE2b-256 checksum
How to use checksums
ffc809dfa12cc9fe78fb138d56829868e8c3ab646f9a204832894e7d85f7ce32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.8.3 requests/2.27.1 setuptools/44.1.0 requests-toolbelt/1.0.0 tqdm/4.64.1 CPython/2.7.18

Release files / opn_sonarqube_api-2.3.3.4261112-py2-none-any.whl

Download URL opn_sonarqube_api-2.3.3.4261112-py2-none-any.whl
Size 28.3 kB
Tags Python 2
SHA-256 checksum
How to use checksums
2dc4f5086c5ff966b398d4cdee92401040938cc4768a3386e0fd40cdf4d4a19e
BLAKE2b-256 checksum
How to use checksums
e1e5b6a7229ab441fdde7e22dea6d52b5c834eab28b6e83ba14126068bb9fcb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.8.3 requests/2.27.1 setuptools/44.1.0 requests-toolbelt/1.0.0 tqdm/4.64.1 CPython/2.7.18
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page