{"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":"python","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,"search_vec":"'1.1.3':9 'activ':56 'ad':68 'address':64 'badg':3,22,37,71 'bug':65 'ci/cd':72 'cli':77 'code':44 'command':17 'command-lin':16 'coverag':45,73 'coverage.xml':48 'current':34 'develop':25,57 'e.g':41,46 'featur':70 'fix':66 'flake8':50,75 'genbadg':1,7 'generat':2,21,36 'junit.xml':43 'librari':13 'line':18 'may':28 'nativ':32 'new':69 'offer':30 'per':62 'project':53 'provid':15 'pytest':76 'python':5,12 'releas':61 'report':51 'result':40 'sever':60 'status':58 'support':35 'svg':78 'test':39,74 'tool':6,26 'util':19 'various':24 'version':8 'year':63","created_at":"2026-04-14T01:25:02.936917+00:00","updated_at":"2026-04-17T14:34:08.514857+00:00","problems":[{"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.","cause":"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.","error":"xml.etree.ElementTree.ParseError: mismatched tag"},{"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.","cause":"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.","error":"ZeroDivisionError: division by zero"},{"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>`.","cause":"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.","error":"genbadge: command not found"},{"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`).","cause":"`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.","error":"FileNotFoundError: [Errno 2] No such file or directory: './reports/junit/junit.xml'"},{"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`.","cause":"The input file specified for badge generation (e.g., `coverage.xml` or `junit.xml`) does not exist at the given path.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'coverage.xml'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"genbadge","cli_version":"Usage: genbadge [OPTIONS] COMMAND [ARGS]...","type":"library","homepage":null,"github":"https://github.com/smarie/python-genbadge","docs":null,"changelog":null,"pypi":"https://pypi.org/project/genbadge/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops","testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-04-13","next_check":"2026-07-12","install_tag":null}}