Registry / devops / genbadge

genbadge

JSON →
library1.1.3pypypiunverified

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.

pip install genbadge
INSTALL
IMPORT
SIG · GENBADGE
G
genbadge
devopspythonv1.1.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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.

# 1. Install genbadge with coverage support pip install genbadge[coverage] # 2. Run your tests with coverage.py to generate a coverage.xml report # (Example: assuming you have tests and source code in a 'src' directory) # (Run from your project root where .coverage file will be generated) # pip install coverage # coverage run -m pytest # coverage xml -o coverage.xml # Create a dummy coverage.xml for demonstration if not available import os if not os.path.exists('coverage.xml'): with open('coverage.xml', 'w') as f: f.write('<coverage branch-rate="0.75" line-rate="0.80">\n') f.write(' <sources><source>src</source></sources>\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') 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') f.write(' </class></classes></package></packages>\n') f.write('</coverage>') # 3. Generate the coverage badge from the XML report # The badge will be saved as 'coverage-badge.svg' in the current directory # You can specify the output file with -o flag, e.g., genbadge coverage -o ./reports/coverage-badge.svg os.system('genbadge coverage -i coverage.xml -o coverage-badge.svg') print("Coverage badge generated as coverage-badge.svg") print("You can include it in your README with: ![Coverage](coverage-badge.svg)")
genbadge --version
Debug
Known issues
breakingAs 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.
fix
Upgrade your Python environment to 3.8 or newer, or use an older version of genbadge that explicitly supports your Python version.
affects: < 1.1.2
gotchaOlder 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]
fix
Upgrade genbadge to version 1.1.1 or higher. If unable to upgrade genbadge, consider downgrading Pillow to a version below 10.
affects: < 1.1.1
gotchaWhen 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]
fix
Upgrade genbadge to version 1.0.4 or higher to correctly handle coverage reports with zero branches.
affects: < 1.0.4
gotchaUsers 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]
fix
Upgrade genbadge to version 1.1.1 or higher. Alternatively, ensure `setuptools` is explicitly installed in your environment (`pip install setuptools`).
affects: < 1.1.1
deprecatedVersions prior to 1.1.3 used `pkg_resources` which is a deprecated dependency and could lead to `UserWarning` messages. [from release notes]
fix
Upgrade genbadge to version 1.1.3 or higher, which migrates to `importlib.resources`.
affects: < 1.1.3
Errors
Common errors & fixes
xml.etree.ElementTree.ParseError: mismatched tag
The input XML file (e.g., `junit.xml`, `coverage.xml`) is malformed, often due to incorrect nesting of tags, unescaped special characters, or encoding issues, which prevents `genbadge` from parsing it correctly.
fix
Validate your XML report file using an XML validator to identify and correct malformed tags, ensuring proper XML structure and escaping any special characters. Ensure the file encoding matches the XML declaration.
ZeroDivisionError: division by zero
This error occurs in older versions of `genbadge` (specifically prior to 1.0.4) when generating a coverage badge from a `coverage.xml` file that reports zero branches, leading to a division by zero during internal calculations.
fix
Upgrade `genbadge` to version 1.0.4 or newer using `pip install --upgrade genbadge`. This version includes a fix for this specific edge case in coverage calculation.
genbadge: command not found
The `genbadge` command-line utility is not found in your system's PATH environment variable, meaning the operating system cannot locate the executable after installation.
fix
Ensure `genbadge` is installed (`pip install genbadge`) and that Python's script directory (where executables like `genbadge` are placed) is included in your system's PATH. Alternatively, execute it using `python -m genbadge <command>`.
FileNotFoundError: [Errno 2] No such file or directory: './reports/junit/junit.xml'
`genbadge` cannot find the expected input report file (e.g., `junit.xml`, `coverage.xml`, `flake8stats.txt`) at the default location or the path provided by the user.
fix
Verify that your report file exists at the specified location. If it's in a different path, use the `-i` or `--input-file` option to explicitly provide the correct path to `genbadge` (e.g., `genbadge tests -i my_custom_reports/tests.xml`).
FileNotFoundError: [Errno 2] No such file or directory: 'coverage.xml'
The input file specified for badge generation (e.g., `coverage.xml` or `junit.xml`) does not exist at the given path.
fix
Ensure the input file exists at the provided path. If it's a report, generate it first using your testing or coverage tool before running `genbadge`.
Upgrade
Version history
1.1.3latest on PyPI · released Nov 24, 2025
Audit
Dependencies
clickrequiredCLI framework
PillowrequiredFor SVG file templating
requestsrequiredTo call the shields.io API
setuptoolsrequiredExplicitly required for Python 3.12+ compatibility
pytestoptionalRequired for `genbadge tests` command when analyzing pytest output
coverageoptionalRequired for `genbadge coverage` command when analyzing coverage.py output
flake8optionalRequired for `genbadge flake8` command when analyzing flake8 output
Agent activity
3 hits · last 30 days
node
2
Resources