Registry / devops / pysonar

pysonar

JSON →
library1.6.0.4905pypypiunverified

pysonar is a command-line tool developed by SonarSource for static code analysis of Python projects with SonarQube or SonarCloud. It acts as a wrapper around the SonarScanner CLI, simplifying configuration and execution for Python ecosystems. It is actively maintained with frequent releases, currently at version 1.4.0.4676, and supports configuration via `pyproject.toml` or `sonar-project.properties` files.

pip install pysonar
INSTALL
IMPORT
SIG · PYSONAR
P
pysonar
devopspythonv1.6.0.4905
Install
2.3s avg
Import
—
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.6.0.4905 · 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.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 21.8MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 2.3s · import 0.000s · 22MB
20MB installed
● package 20MB
Code
Verified usage

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

pysonar
✓ pysonar --help
✗ import pysonar
pysonar is primarily a command-line interface (CLI) tool and is not intended to be imported as a Python library for direct programmatic use.

To quickly get started, install `pysonar`, configure your project (ideally via a `[tool.sonar]` section in `pyproject.toml`), and then run the `pysonar` command with your SonarQube or SonarCloud authentication token. The token can be passed via command-line argument `--token` or an environment variable `SONAR_TOKEN`.

# 1. Install pysonar pip install pysonar # 2. Configure your project (e.g., in pyproject.toml in your project root) # Replace <your-project-key> with your SonarQube project key. # For SonarCloud, also uncomment and set 'organization'. # For SonarQube Server, ensure host.url is set if not default. # # [tool.sonar] # project-key = "<your-project-key>" # # host.url = "https://sonarqube.example.com" # # organization = "<your-organization-key>" # 3. Run the analysis # Ensure SONAR_TOKEN is set in your environment with a valid SonarQube/SonarCloud token. # Example: export SONAR_TOKEN="your_sonar_token_here" import os sonar_token = os.environ.get('SONAR_TOKEN', '') if not sonar_token: print("Error: SONAR_TOKEN environment variable not set. Please set it before running pysonar.") else: print("Running SonarQube analysis...") # The actual command would be run in your shell or CI/CD pipeline # For demonstration, we'll print it. In a real scenario, you'd use subprocess.run() print(f"Executing: pysonar --token {sonar_token}") # Example of actual command to run (requires `pysonar` to be in PATH): # import subprocess # result = subprocess.run(["pysonar", "--token", sonar_token], capture_output=True, text=True) # print(result.stdout) # if result.stderr: print(result.stderr) # if result.returncode != 0: print("Analysis failed!")
pysonar --version
Debug
Known issues
breakingThe `pysonar-scanner` PyPI package is deprecated in favor of `pysonar`. Users should migrate to `pysonar` for all new projects and existing projects where possible. The deprecated package is no longer actively maintained and may break.
fix
Uninstall `pysonar-scanner` and install `pysonar`: `pip uninstall pysonar-scanner && pip install pysonar`.
affects: >=0.3.0.2016 for pysonar-scanner, all versions of pysonar
gotchapysonar requires SonarQube Server v10.6 or higher, or SonarCloud. Older versions of pysonar (before 1.0.1) incorrectly stated compatibility with SonarQube v9.9. If you are on an older SonarQube server, you might need to use the deprecated `pysonar-scanner` or upgrade your SonarQube instance.
fix
Ensure your SonarQube server is version 10.6+ or use SonarCloud. If not possible, consider using the `pysonar-scanner` (deprecated) for older SonarQube versions, or upgrade pysonar to at least 1.0.1.
affects: <1.0.1
gotchaWhen defining SonarQube analysis properties in a `pyproject.toml` file under `[tool.sonar]`, the `sonar.` prefix for property keys should be omitted. Property keys are generally camelCase (e.g., `projectKey`), although kebab-case is also accepted (e.g., `project-key`).
fix
Instead of `sonar.projectKey = "mykey"`, use `projectKey = "mykey"` or `project-key = "mykey"` in `pyproject.toml`.
affects: All versions
gotchapysonar is a wrapper around the SonarScanner CLI. While it simplifies Python project analysis, it still fundamentally relies on the underlying SonarScanner CLI. This means some deep troubleshooting might involve understanding the generic SonarScanner CLI behavior.
fix
When debugging complex analysis issues, consult the official SonarScanner CLI documentation in addition to pysonar's specific guidance.
affects: All versions
Upgrade
Version history
1.6.0.4905latest on PyPI · released May 28, 2026
Audit
Dependencies
PythonrequiredRuntime environment.
SonarQube ServerrequiredRequires SonarQube Server v10.6 or higher, or SonarCloud, for analysis reporting.
Agent activity
15 hits · last 30 days
node
14
Resources
pysonar — pip install pysonar · libregistry