Registry / devops / python-sonarqube-api

python-sonarqube-api

JSON →
library2.0.5pypypiunverified

python-sonarqube-api is a Python wrapper for the SonarQube and SonarCloud API, providing a convenient interface to interact with SonarQube Community, Enterprise, and SonarCloud instances. It supports Python 2.7 and 3.3+ (though modern usage typically implies Python 3.6+). The library is actively maintained, with version 2.0.5 currently available, facilitating integration of SonarQube's static analysis capabilities into Python applications and CI/CD pipelines.

devopshttp-networking
Install & Compatibility
Where this runs
tested against v2.0.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.634s · 21.5MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.1s · import 0.565s · 22MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

from sonarqube import SonarQubeClient
from sonarqube import SonarCloudClient
from sonarqube import SonarEnterpriseClient

SonarAPIHandler was a class in an older/different, similarly named package (kako-nawao/python-sonarqube-api). The current official package uses SonarQubeClient, SonarCloudClient, or SonarEnterpriseClient from the 'sonarqube' top-level module.

from sonarqube import SonarQubeClient

This quickstart demonstrates how to connect to a SonarQube instance using a token and retrieve a list of projects. It uses environment variables for sensitive connection details. For SonarCloud, `SonarCloudClient` should be used with `sonarcloud_url` instead of `sonarqube_url`.

import os from sonarqube import SonarQubeClient # Configure connection details using environment variables for security SONARQUBE_URL = os.environ.get('SONARQUBE_URL', 'http://localhost:9000') SONARQUBE_TOKEN = os.environ.get('SONARQUBE_TOKEN', 'YOUR_SONARQUBE_TOKEN') # Or use user/password # Initialize the SonarQube client try: client = SonarQubeClient(sonarqube_url=SONARQUBE_URL, token=SONARQUBE_TOKEN) # Example: Fetch all projects print(f"Connected to SonarQube at {SONARQUBE_URL}") print("Fetching projects...") projects = list(client.projects.search_projects()) if projects: print(f"Found {len(projects)} projects:") for project in projects[:3]: # Print first 3 projects print(f" - {project.get('name')} (Key: {project.get('key')})") else: print("No projects found or accessible.") except Exception as e: print(f"An error occurred: {e}") print("Please ensure SonarQube is running and accessible, and your token/credentials are correct.") print("For SonarCloud, use SonarCloudClient and 'sonarcloud_url' parameter.")
Debug
Known footguns
breakingSonarQube API changes in versions 9.7.1 and later removed the 'Statistics.edition' field from the `/api/system/info` endpoint.
gotchaSonarQube API methods that return large datasets are often paginated by the server. The `python-sonarqube-api` client methods frequently return generators to handle this efficiently.
gotchaToken-based authentication is the recommended and more secure method for programmatic access to SonarQube/SonarCloud APIs over username/password.
gotchaDifferent client classes exist for different SonarQube environments: `SonarQubeClient` for SonarQube Community/Enterprise, `SonarCloudClient` for SonarCloud, and `SonarEnterpriseClient` specifically for SonarQube Enterprise Edition.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
22 hits · last 30 days
gptbot
4
bingbot
4
ahrefsbot
4
amazonbot
4
script
1
Resources