Welcome to SonarQube Client with Python’s documentation!¶
python-sonarqube-api provides a simple interface for clients to interact with SonarQube via the REST API.
Compatibility¶
- This package is compatible Python versions 2.7, 3.3+.
- Tested with SonarQube Community Edition 8.9.x LTS and SonarCloud Server.
Editions¶
There are two editions of python-sonarqube-api:
- Community Edition (CE) is available freely under the GNU Affero General Public License v3.0.
- Professional Edition (PE) includes [extra features](https://python-sonarqube-pro-api.readthedocs.io/en/latest/#api-reference) that are more useful for developers with more than 280 interface functions. To use PE and get timely Email support and continuous updates, please become a Purchaser(https://shijl0925.gumroad.com/l/nlokc) and become a subscriber(https://shijl0925.gumroad.com/subscribe).
Notice: Professional Edition’s extra features have been remarked by using Only available on the professional edition in API Document.
Differences | Community Edition | Professional Edition |
---|---|---|
License | GNU AGPLv3 License | MIT License |
Commercial Use | No | Yes |
Supported APIs (SonarQube Web APIs) | 40 | more than 280 |
Compatibility (SonarQube Versions) | 7.9.x - 8.9.x | 7.9.x - 10.x |
Payment only needs to be made once, and library updates will be provided for free.
Installation¶
Community Edition¶
Use pip to install the latest stable version of python-sonarqube-api
:
$ pip install --upgrade python-sonarqube-api
Professional Edition¶
Use pip to install the Python wheel or source package, Use –force-reinstall to force an installation If necessary:
$ pip install python_sonarqube_pro_api-x.y.z-py3-none-any.whl
Change Log¶
Community Edition¶
See the CHANGELOG-CE.md file for Community Edition.
Professional Edition¶
See the CHANGELOG-PE.md file for Professional Edition.
Documentation¶
This part of the documentation will show you how to get started in using python-sonarqube-api.
The Client is easy to use, you just need to initialize it with the connection parameters (default sonarqube url is http://localhost:9000).
Setup a SonarQube Client¶
from sonarqube import SonarQubeClient
sonar = SonarQubeClient(sonarqube_url="http://localhost:9000", username='admin', password='admin')
Sonar authentication tokens can also be used in place of username and password:
sonar = SonarQubeClient(sonarqube_url="http://localhost:9000", token='*****************')
Example¶
Refer to the example script for a full working example.
- API examples
- Setup
- api/authentication
- api/ce
- api/components
- api/duplications
- api/favorites
- api/issues
- api/languages
- api/measures
- api/metrics
- api/notifications
- api/permissions
- api/project_analyses
- api/project_badges
- api/project_branches
- api/project_links
- api/project_pull_requests
- api/project_tags
- api/projects
- api/qualitygates
- api/qualityprofiles
- api/rules
- api/settings
- api/user_groups
- api/user_tokens
- api/users
- api/webhooks
- api/server
- api/sources
- api/plugins
API Reference¶
If you are looking for information on a specific function, class or method, this part of the documentation is for you.
- sonarqube.rest package
- Submodules
- sonarqube.rest.alm_integrations module
- sonarqube.rest.alm_settings module
- sonarqube.rest.analysis_cache module
- sonarqube.rest.applications module
- sonarqube.rest.audit_logs module
- sonarqube.rest.auth module
- sonarqube.rest.ce module
- sonarqube.rest.components module
- sonarqube.rest.duplications module
- sonarqube.rest.editions module
- sonarqube.rest.favorites module
- sonarqube.rest.hotspots module
- sonarqube.rest.issues module
- sonarqube.rest.languages module
- sonarqube.rest.measures module
- sonarqube.rest.metrics module
- sonarqube.rest.monitoring module
- sonarqube.rest.new_code_periods module
- sonarqube.rest.notifications module
- sonarqube.rest.permissions module
- sonarqube.rest.plugins module
- sonarqube.rest.project_analyses module
- sonarqube.rest.project_badges module
- sonarqube.rest.project_branches module
- sonarqube.rest.project_dump module
- sonarqube.rest.project_links module
- sonarqube.rest.project_pull_requests module
- sonarqube.rest.project_tags module
- sonarqube.rest.projects module
- sonarqube.rest.qualitygates module
- sonarqube.rest.qualityprofiles module
- sonarqube.rest.rules module
- sonarqube.rest.server module
- sonarqube.rest.settings module
- sonarqube.rest.sources module
- sonarqube.rest.support module
- sonarqube.rest.system module
- sonarqube.rest.user_groups module
- sonarqube.rest.user_tokens module
- sonarqube.rest.users module
- sonarqube.rest.views module
- sonarqube.rest.webhooks module
- sonarqube.rest.webservices module
- Module contents
Additional Notes¶
If you find that the interface in the this Python library does not meet your requirements or is missing, you can use request_get and request_post to extend your code. (Only for Professional Edition)
for example:
from sonarqube import SonarQubeClient
sonar = SonarQubeClient(sonarqube_url="http://localhost:9000", username='admin', password='admin')
# Get Request
res = sonar.request_get(endpoint="/api/components/search", params={"qualifiers": "TRK"})
# Post Request
res = sonar.request_post(endpoint="/api/users/deactivate", data={"login": "login"})