Anybadge
Anybadge is a Python library and command-line tool designed for simple and flexible generation of SVG badges for your projects. It allows users to define custom labels, values, and configurable thresholds to color badges dynamically. The library is actively maintained, with its current version being 1.16.0, and receives regular updates.
Warnings
- breaking Python 2.7 support was dropped in version 1.10.0. Projects using older Python versions must upgrade to Python 3.4 or higher.
- gotcha Earlier versions (prior to v1.16.0) could mishandle malformed thresholds, leading to unexpected badge colors or errors.
- gotcha Issues with escaping special characters in badge labels and values were present in versions prior to v1.16.0, potentially causing malformed SVG output.
- gotcha A package version bug was identified and fixed in v1.16.0, which might have affected how the library reported or used its own version information.
Install
-
pip install anybadge
Imports
- Badge
from anybadge import Badge
- anybadge
import anybadge
Quickstart
import anybadge
# Define thresholds for coloring the badge based on value
# <2=red, <4=orange, <6=yellow, <10=green
thresholds = {2: 'red', 4: 'orange', 6: 'yellow', 10: 'green'}
# Create a badge instance
badge = anybadge.Badge(
label='pylint',
value=2.22,
thresholds=thresholds
)
# Write the badge to an SVG file
badge.write_badge('pylint.svg')
print('pylint.svg generated.')