Badge Generation
Khaos exposes a Python badge utility module for generating SVG status badges from evaluation results. There is no dedicated khaos badges CLI command in the stable release.
Core API
Python
from khaos.badges import (
Badge,
BadgeStyle,
BadgeColor,
reliability_badge,
status_badge,
security_badge,
coverage_badge,
custom_badge,
generate_badges_from_results,
shields_io_url,
reliability_shields_url,
)Generate Basic Badges
Python
from pathlib import Path
from khaos.badges import reliability_badge, status_badge, BadgeStyle
# reliability_badge score is 0.0-1.0
r = reliability_badge(score=0.95, style=BadgeStyle.FLAT)
Path("badges/reliability.svg").write_text(r.to_svg(), encoding="utf-8")
s = status_badge(passed=True, label="khaos")
Path("badges/status.svg").write_text(s.to_svg(), encoding="utf-8")Generate From CI Results
Run CI in JSON mode, then create badge SVG files from the resulting payload.
Terminal
# 1) Produce JSON report
khaos ci my-agent --eval quickstart --format json --output-file results.jsonPython
import json
from pathlib import Path
from khaos.badges import generate_badges_from_results, BadgeStyle
results = json.loads(Path("results.json").read_text(encoding="utf-8"))
out = generate_badges_from_results(results, output_dir="badges", style=BadgeStyle.FLAT)
print(out)Shields.io URLs
Python
from khaos.badges import shields_io_url, reliability_shields_url
url = shields_io_url(label="khaos", message="passing", color="#4c1", style="flat")
print(url)
# reliability_shields_url also expects score in 0.0-1.0
print(reliability_shields_url(score=0.95))Notes
BadgeColorvalues are hex colors in this releaseBadge.to_markdown()andBadge.to_html()return references tobadge.svg- For README badges, write SVG files to your repo or use generated Shields URLs
Recommended Flow
Generate badges in CI with Python after
khaos ci --format json, then publish SVG artifacts or commit them to a docs branch.Related
- CI/CD Integration - pipeline setup
- Metrics - interpreting score fields