{"id":5235,"library":"genbadge","title":"Genbadge - Generate Badges for Python Tools","description":"Genbadge (version 1.1.3) is a Python library that provides command-line utilities to generate badges for various development tools that may not offer them natively. It currently supports generating badges for test results (e.g., from `junit.xml`), code coverage (e.g., from `coverage.xml`), and flake8 reports. The project has an active development status with several releases per year, addressing bug fixes and adding new features.","status":"active","version":"1.1.3","language":"en","source_language":"en","source_url":"https://github.com/smarie/python-genbadge","tags":["badge","CI/CD","coverage","testing","flake8","pytest","cli","svg"],"install":[{"cmd":"pip install genbadge","lang":"bash","label":"Minimal installation (core features)"},{"cmd":"pip install genbadge[all]","lang":"bash","label":"Full installation (including test, coverage, and flake8 support)"}],"dependencies":[{"reason":"CLI framework","package":"click","optional":false},{"reason":"For SVG file templating","package":"Pillow","optional":false},{"reason":"To call the shields.io API","package":"requests","optional":false},{"reason":"Explicitly required for Python 3.12+ compatibility","package":"setuptools","optional":false},{"reason":"Required for `genbadge tests` command when analyzing pytest output","package":"pytest","optional":true},{"reason":"Required for `genbadge coverage` command when analyzing coverage.py output","package":"coverage","optional":true},{"reason":"Required for `genbadge flake8` command when analyzing flake8 output","package":"flake8","optional":true}],"imports":[],"quickstart":{"code":"# 1. Install genbadge with coverage support\npip install genbadge[coverage]\n\n# 2. Run your tests with coverage.py to generate a coverage.xml report\n# (Example: assuming you have tests and source code in a 'src' directory)\n# (Run from your project root where .coverage file will be generated)\n# pip install coverage\n# coverage run -m pytest\n# coverage xml -o coverage.xml\n# Create a dummy coverage.xml for demonstration if not available\nimport os\nif not os.path.exists('coverage.xml'):\n    with open('coverage.xml', 'w') as f:\n        f.write('<coverage branch-rate=\"0.75\" line-rate=\"0.80\">\\n')\n        f.write('  <sources><source>src</source></sources>\\n')\n        f.write('  <packages><package name=\"src\"><classes><class branch-rate=\"0.75\" complexity=\"0\" filename=\"src/my_module.py\" line-rate=\"0.80\" name=\"my_module.py\">\\n')\n        f.write('    <methods/><lines><line branch=\"false\" hits=\"1\" number=\"1\"/><line branch=\"false\" hits=\"1\" number=\"2\"/><line branch=\"true\" condition-coverage=\"100% (2/2)\" hits=\"1\" number=\"5\"/><line branch=\"false\" hits=\"1\" number=\"6\"/><line branch=\"false\" hits=\"0\" number=\"9\"/></lines>\\n')\n        f.write('  </class></classes></package></packages>\\n')\n        f.write('</coverage>')\n\n# 3. Generate the coverage badge from the XML report\n# The badge will be saved as 'coverage-badge.svg' in the current directory\n# You can specify the output file with -o flag, e.g., genbadge coverage -o ./reports/coverage-badge.svg\nos.system('genbadge coverage -i coverage.xml -o coverage-badge.svg')\n\nprint(\"Coverage badge generated as coverage-badge.svg\")\nprint(\"You can include it in your README with: ![Coverage](coverage-badge.svg)\")","lang":"python","description":"This quickstart demonstrates how to generate a coverage badge using `genbadge` from a `coverage.xml` report. First, ensure `genbadge` is installed with `coverage` extra. Then, generate your `coverage.xml` report (e.g., using the `coverage.py` tool). Finally, run the `genbadge coverage` command, specifying the input XML file and desired output SVG file."},"warnings":[{"fix":"Upgrade your Python environment to 3.8 or newer, or use an older version of genbadge that explicitly supports your Python version.","message":"As of version 1.1.2, genbadge officially dropped support for Python versions 2.7, 3.5, 3.6, and 3.7. This version and subsequent releases may not function correctly on these older Python environments.","severity":"breaking","affected_versions":"< 1.1.2"},{"fix":"Upgrade genbadge to version 1.1.1 or higher. If unable to upgrade genbadge, consider downgrading Pillow to a version below 10.","message":"Older versions of genbadge (prior to 1.1.1) might experience issues when running with Pillow version 10 or greater due to API changes in Pillow. [from release notes]","severity":"gotcha","affected_versions":"< 1.1.1"},{"fix":"Upgrade genbadge to version 1.0.4 or higher to correctly handle coverage reports with zero branches.","message":"When using `genbadge coverage` on reports where no branches are present (e.g., when `--no-branch` option is set in coverage.py), older versions could raise a `ZeroDivisionError`. [from release notes]","severity":"gotcha","affected_versions":"< 1.0.4"},{"fix":"Upgrade genbadge to version 1.1.1 or higher. Alternatively, ensure `setuptools` is explicitly installed in your environment (`pip install setuptools`).","message":"Users running Python 3.12 with older genbadge versions might encounter problems related to a missing `setuptools` dependency, as it was explicitly added for 3.12 support. [from release notes]","severity":"gotcha","affected_versions":"< 1.1.1"},{"fix":"Upgrade genbadge to version 1.1.3 or higher, which migrates to `importlib.resources`.","message":"Versions prior to 1.1.3 used `pkg_resources` which is a deprecated dependency and could lead to `UserWarning` messages. [from release notes]","severity":"deprecated","affected_versions":"< 1.1.3"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}