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.
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
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.634s · 21.5MB
glibcpy 3.10–3.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.")
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.