Package: anybadge
anybadgePython project for generating badges for your projectsSupports: Python 3.4-3.9 (2.7 support has been dropped)Overviewanybadgecan be used to add badge generation to your Python projects,
and also provides a command line interface.This utility can be used to generate .svg badge images, using configurable
thresholds for coloring the badges based on the badge value.  Many badge
generation tools just provide the ability to specify the color of badge.anybadgeallows you to specify the label, badge value, and color, but
it also allows you to specify a set of thresholds that can be used to
select a color based on the badge value.anybadgemay be useful for companies developing internally, or any time
making calls to external badge services is not possible, or undesirable.
In this situation usinganybadgewill be easier than running your own
internal badge service.The package can be imported into your python code, or run direct from the
command line.DemoYou can find arepl.it demo here.
This will allow you to see what the package can do and play with it to test outputs.Basic usageCommand lineAs an example, if you want to produce a pylint badge, you may runanybadgefrom the command line like this:anybadge-lpylint-v2.22-fpylint.svg2=red4=orange8=yellow10=greenThis would result in a badge like this:In this example the label is set to "pylint", the value "2.22", and an
output file called "pylint.svg".  The thresholds are provided in pairs
of<value>=colorValues can be integer or floats for ranges, and
string values are also supported.PythonHere is the same example implemented in Python code:importanybadge# Define thresholds: <2=red, <4=orange <8=yellow <10=greenthresholds={2:'red',4:'orange',6:'yellow',10:'green'}badge=anybadge.Badge('pylint',2.22,thresholds=thresholds)badge.write_badge('pylint.svg')Installationanybadgeis available in PyPi athttps://pypi.python.org/pypi/anybadgeYou can install the latest release ofanybadgeusingpip:pipinstallanybadgeThis will install the Python package, and also makeanybadgeavailable
as a command line utility.Getting helpTo get help from the command line utility, just run:anybadge--helpCommand line usageOutputRunning the utility with the--fileoption will result in the .svg image being
written to file.  Without the--fileoption the.svgfile content will be
written to stdout, so can be redirected to a file.ThresholdsSome thresholds have been built in to save time.  To use these thresholds you
can simply specify the template name instead of threshold value/color pairs.anybadge--value=<VALUE>--file=<FILE><TEMPLATE-NAME>For example:anybadge--value=2.22--file=pylint.svgpylintColorsAnybadge comes with some pre-defined colors, which can be referred to by name.  It also
supports the use of custom colors by using the hex representation of the color.  Both color
types can be used in thedefault_color,text_colorandthresholdsattributes. Color names are
taken from theMozilla color keywords list.Here is a Python example showing use of a named color and a custom color.importanybadgebadge=anybadge.Badge(label='custom color',value='teal',default_color='teal',num_padding_chars=1)badge=anybadge.Badge(label='custom color',value='teal',default_color='#008080',num_padding_chars=1)Available named colors are:Color NameHexExamplealiceblue#F0F8FFantiquewhite#FAEBD7aqua#00FFFFaquamarine#7FFFD4azure#F0FFFFbeige#F5F5DCbisque#FFE4C4black#000000blanchedalmond#FFEBCDblue#0000FFblueviolet#8A2BE2bright_red#FF0000bright_yellow#FFFF00brown#A52A2Aburlywood#DEB887cadetblue#5F9EA0chartreuse#7FFF00chocolate#D2691Ecoral#FF7F50cornflowerblue#6495EDcornsilk#FFF8DCcrimson#DC143Cdarkblue#00008Bdarkcyan#008B8Bdarkgoldenrod#B8860Bdarkgray#A9A9A9darkgreen#006400darkkhaki#BDB76Bdarkmagenta#8B008Bdarkolivegreen#556B2Fdarkorange#FF8C00darkorchid#9932CCdarkred#8B0000darksalmon#E9967Adarkseagreen#8FBC8Fdarkslateblue#483D8Bdarkslategray#2F4F4Fdarkturquoise#00CED1darkviolet#9400D3deeppink#FF1493deepskyblue#00BFFFdimgray#696969dodgerblue#1E90FFfirebrick#B22222floralwhite#FFFAF0forestgreen#228B22fuchsia#FF00FFgainsboro#DCDCDCghostwhite#F8F8FFgold#FFD700goldenrod#DAA520gray#808080green#4C1greenyellow#ADFF2Fgreen_2#008000honeydew#F0FFF0hotpink#FF69B4indianred#CD5C5Cindigo#4B0082ivory#FFFFF0khaki#F0E68Clavender#E6E6FAlavenderblush#FFF0F5lawngreen#7CFC00lemonchiffon#FFFACDlightblue#ADD8E6lightcoral#F08080lightcyan#E0FFFFlightgoldenrodyellow#FAFAD2lightgray#D3D3D3lightgreen#90EE90lightpink#FFB6C1lightsalmon#FFA07Alightseagreen#20B2AAlightskyblue#87CEFAlightslategray#778899lightsteelblue#B0C4DElightyellow#FFFFE0light_grey#9F9F9Flime#00FF00limegreen#32CD32linen#FAF0E6maroon#800000mediumaquamarine#66CDAAmediumblue#0000CDmediumorchid#BA55D3mediumpurple#9370DBmediumseagreen#3CB371mediumslateblue#7B68EEmediumspringgreen#00FA9Amediumturquoise#48D1CCmediumvioletred#C71585midnightblue#191970mintcream#F5FFFAmistyrose#FFE4E1moccasin#FFE4B5navajowhite#FFDEADnavy#000080oldlace#FDF5E6olive#808000olivedrab#6B8E23orange#FE7D37orangered#FF4500orange_2#FFA500orchid#DA70D6palegoldenrod#EEE8AApalegreen#98FB98paleturquoise#AFEEEEpalevioletred#DB7093papayawhip#FFEFD5peachpuff#FFDAB9peru#CD853Fpink#FFC0CBplum#DDA0DDpowderblue#B0E0E6purple#800080rebeccapurple#663399red#E05D44rosybrown#BC8F8Froyalblue#4169E1saddlebrown#8B4513salmon#FA8072sandybrown#F4A460seagreen#2E8B57seashell#FFF5EEsienna#A0522Dsilver#C0C0C0skyblue#87CEEBslateblue#6A5ACDslategray#708090snow#FFFAFAspringgreen#00FF7Fsteelblue#4682B4tan#D2B48Cteal#008080thistle#D8BFD8tomato#FF6347turquoise#40E0D0violet#EE82EEwheat#F5DEB3white#FFFFFFwhitesmoke#F5F5F5yellow#DFB317yellowgreen#9ACD32yellow_green#A4A61DEmojisIt is possible to use emoji characters in badge labels and values. Here are some examples:These files were created by using theactualemoji character in the label/value text. For example:badge=anybadge.Badge(label="Pipeline status",value="😄")There are some caveats worth mentioning:The "look" of the emoji is determined by the client (Emoji characters are placed as-is into the SVG file, and are
rendered client-side)Rendering may fail in some viewers and developer IDEs (for example, PyCharm does not render emojis in the svg viewer)Emojis can have different widths, so the layout may be affected. You can usenum_label_padding_charsandnum_value_padding_charsto fix (see below)Here are some examples to show how to use padding to fix layout:BadgeCodeanybadge.Badge("Pipeline status", "😄")anybadge.Badge("Pipeline status", "😄", num_value_padding_chars=1)Semantic version supportAnybadge supports semantic versions for value and threshold keys. This supports color-coded
badges based on version numbering. Here are some examples:badge=Badge(label='Version',value='3.0.0',thresholds={'3.0.0':'red','3.2.0':'orange','999.0.0':'green'},semver=True)In the above example the thresholds equate to the following:If value is < 3.0.0 then badge will be red.If value is < 3.2.0 then badge will be orange.If value is < 999.0.0 then badge will be green.Each threshold entry is used to define the upper bounds of the threshold. If you don't know the
upper bound for your version number threshold you will need to provide an extreme upper bound -
in this example it is999.0.0.ExamplesPylint using templateanybadge--value=2.22--file=pylint.svgpylintPylint using argumentsanybadge-lpylint-v2.22-fpylint.svg2=red4=orange8=yellow10=greenCoverage using templateanybadge--value=65--file=coverage.svgcoveragePipeline, using labeled colorsanybadge--label=pipeline--value=passing--file=pipeline.svgpassing=greenfailing=redBadge with fixed coloranybadge--label=awesomeness--value="110%"--file=awesomeness.svg--color='#97CA00'GitLab Scoped style badgeanybadge--style=gitlab-scoped--label=Project--value=Archimedes--file=gitlab_scoped.svg--color='#c1115d'Thresholds based on semantic versionsanybadge--label=Version--value=2.4.5--file=version.svg1.0.0=red2.4.6=orange2.9.1=yellow999.0.0=greenImporting in your own appfromanybadgeimportBadgetest1=Badge(label,value,font_name='DejaVu Sans,Verdana,Geneva,sans-serif',font_size=11,num_padding_chars=0.5,template='<?xml version="1.0" encoding="UTF-8"?>\n<svg xmlns="http://www.w3.org/2000/svg" width="{{ badge width }}" height="20">\n<linearGradient id="b" x2="0" y2="100%">\n<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>\n<stop offset="1" stop-opacity=".1"/>\n</linearGradient>\n<mask id="a">\n<rect width="{{ badge width }}" height="20" rx="3" fill="#fff"/>\n</mask>\n<g mask="url(#a)">\n<path fill="#555" d="M0 0h{{ color split x }}v20H0z"/>\n<path fill="{{ color }}" d="M{{ color split x }} 0h{{ value width }}v20H{{ color split x }}z"/>\n<path fill="url(#b)" d="M0 0h{{ badge width }}v20H0z"/>\n</g>\n<g fill="{{ label text color }}" text-anchor="middle" font-family="{{ font name }}" font-size="{{ font size }}">\n<text x="{{ label anchor shadow }}" y="15" fill="#010101" fill-opacity=".3">{{ label }}</text>\n<text x="{{ label anchor }}" y="14">{{ label }}</text>\n</g>\n<g fill="{{ value text color }}" text-anchor="middle" font-family="{{ font name }}" font-size="{{ font size }}">\n<text x="{{ value anchor shadow }}" y="15" fill="#010101" fill-opacity=".3">{{ value }}</text>\n<text x="{{ value anchor }}" y="14">{{ value }}</text>\n</g>\n</svg>',value_prefix='',value_suffix='',thresholds=None,default_color='#4c1',use_max_when_value_exceeds=True,value_format=None,text_color='#fff')test1.write_badge('test1.svg')Command-line optionsThe command line options can be viewed usinganybadge --help.ExamplesHere are some usage specific command line examples that may save time on defining
thresholds.Pylint::anybadge.py --value=2.22 --file=pylint.svg pylint
anybadge.py --label=pylint --value=2.22 --file=pylint.svg 2=red 4=orange 8=yellow 10=greenCoverage::anybadge.py --value=65 --file=coverage.svg coverage
anybadge.py --label=coverage --value=65 --suffix='%%' --file=coverage.svg 50=red 60=orange 80=yellow 100=greenCI Pipeline::anybadge.py --label=pipeline --value=passing --file=pipeline.svg passing=green failing=redPython usageFor Python API details you can use the inbuilt documentation:fromanybadgeimportbadgehelp(badge)