Batch generator
BadgeGenerator(template: BadgeTemplate = BadgeTemplate.DEFAULT, log_level: Union[LogLevel, str] = LogLevel.WARNING, style: Optional[BadgeStyle] = None)
¶
Generate customizable SVG badges.
| PARAMETER | DESCRIPTION |
|---|---|
|
The name of the SVG template file.
TYPE:
|
|
The logging level. Options are 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'.
TYPE:
|
|
Visual style preset. Defaults to :attr:
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
is_valid_hex_color |
Validate if a string is a valid hex color. |
validate_color |
Validate the color input. |
validate_frame |
Validate the frame input. |
validate_inputs |
Validate parameters shared by the different badge templates. |
local_path |
Get the absolute path for a given relative path. |
get_base64_content |
Get the base64 encoded content of a binary file. |
generate_badge |
Generates a badge based on the provided parameters and saves it as an SVG file. |
Source code in src/badgeshield/badge_generator.py
is_valid_hex_color(color: str) -> bool
staticmethod
¶
validate_color(color: Union[BadgeColor, str], color_name: str) -> str
staticmethod
¶
Validate the color input.
Source code in src/badgeshield/badge_generator.py
validate_frame(frame: Optional[Union[FrameType, str]]) -> str
staticmethod
¶
Validate the frame input.
Source code in src/badgeshield/badge_generator.py
validate_inputs(left_text: str, left_color: Union[BadgeColor, str], output_path: Optional[str], badge_name: str, right_text: Optional[str] = None, right_color: Optional[Union[BadgeColor, str]] = None, logo: Optional[str] = None, frame: Optional[Union[FrameType, str]] = None) -> Tuple[str, str, str, Optional[str]]
¶
Validate parameters shared by the different badge templates.
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
Containing the normalized left color, right color, output directory, and frame asset path (when applicable).
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError:
|
If any argument is missing or malformed (e.g., empty text, invalid output directory, missing logo file, incorrect badge name suffix). |
TypeError:
|
When a value has the wrong type for its expected enum/string input. # type: ignore[arg-type] |
Source code in src/badgeshield/badge_generator.py
| Python | |
|---|---|
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | |
local_path(relative_path: str) -> str
¶
Get the absolute path for a given relative path.
| PARAMETER | DESCRIPTION |
|---|---|
|
The relative path to resolve.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The absolute resolved path.
TYPE:
|
Source code in src/badgeshield/badge_generator.py
get_base64_content(bin_file: str) -> str
¶
Get the base64 encoded content of a binary file.
Source code in src/badgeshield/badge_generator.py
generate_badge(left_text: str, left_color: Union[BadgeColor, str], badge_name: str, output_path: Optional[str] = None, right_text: Optional[str] = None, right_color: Optional[Union[BadgeColor, str]] = None, logo: Optional[str] = None, frame: Optional[Union[FrameType, str]] = None, left_link: Optional[str] = None, right_link: Optional[str] = None, id_suffix: str = '', left_title: Optional[str] = None, right_title: Optional[str] = None, logo_tint: Optional[Union[str, BadgeColor]] = None) -> str
¶
Generates a badge based on the provided parameters and saves it as an SVG file.
| PARAMETER | DESCRIPTION |
|---|---|
|
Text for the left side of the badge.
TYPE:
|
|
Background color for the left side of the badge.
TYPE:
|
|
The name of the badge file to be generated.
TYPE:
|
|
Output path for the generated badge SVG file.
TYPE:
|
|
Text for the right side of the badge. Defaults to None.
TYPE:
|
|
Background color for the right side of the badge. Defaults to None.
TYPE:
|
|
URL or path to a logo image. Defaults to None.
TYPE:
|
|
Frame template to use, either as a FrameType or its name/path.
TYPE:
|
|
Link for the left side of the badge. Defaults to None.
TYPE:
|
|
Link for the right side of the badge. Defaults to None.
TYPE:
|
|
Suffix to add to the ID of the badge elements. Defaults to ''.
TYPE:
|
|
Title text for the left side of the badge. Defaults to None.
TYPE:
|
|
Title text for the right side of the badge. Defaults to None.
TYPE:
|
|
Optional color applied to monochrome the logo.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError:
|
If the output_path is empty or invalid. |
TypeError:
|
If frame is not an instance of FrameType. |
| RETURNS | DESCRIPTION |
|---|---|
str
|
The absolute path of the written SVG file, equivalent to
TYPE:
|
Source code in src/badgeshield/badge_generator.py
| Python | |
|---|---|
971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 | |
BadgeBatchGenerator(max_workers: int = 5, log_level: Union[LogLevel, str] = LogLevel.INFO)
¶
Generate many badges concurrently using a thread pool.
| METHOD | DESCRIPTION |
|---|---|
generate_batch |
Generate multiple badges concurrently. |
Source code in src/badgeshield/badge_generator.py
generate_batch(badges: List[Dict], progress_callback: Optional[Callable[[str], None]] = None) -> None
¶
Generate multiple badges concurrently.
| PARAMETER | DESCRIPTION |
|---|---|
|
TYPE:
|
|
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
RuntimeError:
|
Aggregated failures when one or more badges cannot be generated. |