Registry / devops / anybadge

anybadge

JSON →
library1.16.0pypypi✓ verified 23d ago

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.

pip install anybadge
INSTALL
IMPORT
SIG · ANYBADGE
A
anybadge
devopspythonv1.16.0
Install
1.6s avg
Import
123ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.16.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.124s · 19MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.122s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Badge
from anybadge import Badge
anybadge
import anybadge
For direct access to the main module or `anybadge.Badge` if not importing `Badge` directly.

This example demonstrates how to create a PyLint score badge using thresholds to determine its color and then save it as an SVG file. Values can be integers, floats, or strings, and custom colors (hex codes or named colors) are supported.

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.')
anybadge --version
Debug
Known issues
breakingPython 2.7 support was dropped in version 1.10.0. Projects using older Python versions must upgrade to Python 3.4 or higher.
fix
Ensure your project runs on Python >= 3.4. Upgrade your Python environment if necessary.
affects: <1.10.0
gotchaEarlier versions (prior to v1.16.0) could mishandle malformed thresholds, leading to unexpected badge colors or errors.
fix
Upgrade to anybadge v1.16.0 or newer. Ensure threshold definitions are correctly formatted (e.g., `{'value': 'color'}`).
affects: <1.16.0
gotchaIssues with escaping special characters in badge labels and values were present in versions prior to v1.16.0, potentially causing malformed SVG output.
fix
Upgrade to anybadge v1.16.0 or newer to benefit from fixes for label and value escaping.
affects: <1.16.0
gotchaA 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.
fix
Upgrade to anybadge v1.16.0 or newer to resolve any internal package versioning inconsistencies.
affects: <1.16.0
Errors
Common errors & fixes
ImportError: cannot import name 'get_template' from 'anybadge.templates'
This error occurs due to a known issue in certain versions of the anybadge package where the 'get_template' function is not properly accessible.
fix
Upgrade to the latest version of anybadge where this issue has been resolved.
ModuleNotFoundError: No module named 'anybadge'
This error occurs when the anybadge package is not installed in the Python environment.
fix
Install anybadge using pip: 'pip install anybadge'.
TypeError: __init__() got an unexpected keyword argument 'thresholds'
This error occurs when an incorrect keyword argument is passed to the Badge class constructor in anybadge.
fix
Ensure that the 'thresholds' argument is correctly defined as a dictionary mapping numeric thresholds to color names.
ImportError: cannot import name 'Badge' from 'anybadge'
This error typically occurs when a local Python file or directory is named `anybadge.py` (or `anybadge`) and shadows the installed `anybadge` package, causing Python to import the local file instead of the library.
fix
Rename your local Python file or directory from `anybadge.py` (or `anybadge`) to something else to avoid name collision with the installed library.
cannot import name 'get_template' from 'anybadge.templates'
This error usually arises from an incompatibility after an `anybadge` update, where internal module structures or function names (like `get_template`) might have changed, or due to a corrupted or mixed installation.
fix
Ensure you have the latest version of `anybadge` installed by running `pip install --upgrade anybadge`. If the issue persists, consider recreating your Python environment and reinstalling the package.
Upgrade
Version history
1.16.0latest on PyPI · released Jan 11, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
33 hits · last 30 days
node
30
OpenAI (training)
1
Resources
anybadge — pip install anybadge · libregistry