pybadges is a Python library and command line tool that allows you to create Github-style badges as SVG images. For example:
The aesthetics of the generated badges matches the visual design found in this specification.
The implementation of the library was heavily influenced by Shields.io and the JavaScript badge-maker library.
Getting Started
Installing
pybadges can be installed using pip:
pip install pybadges
To test that installation was successful, try:
python -m pybadges --left-text=build --right-text=failure --right-color='#c00' --browserYou will see a badge like this in your browser:
Usage
pybadges can be used both from the command line and as a Python library.
The command line interface is a great way to experiment with the API before writing Python code.
You could also look at the example server.
Command line usage
Complete documentation of pybadges command arguments can be found using the --help
flag:
python -m pybadges --help
But the following usage demonstrates every interesting option:
python -m pybadges \
--left-text=complete \
--right-text=example \
--left-color=green \
--right-color='#fb3' \
--left-link=http://www.complete.com/ \
--right-link=http://www.example.com \
--logo='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAD0lEQVQI12P4zwAD/xkYAA/+Af8iHnLUAAAAAElFTkSuQmCC' \
--embed-logo \
--whole-title="Badge Title" \
--left-title="Left Title" \
--right-title="Right Title" \
--browserA note about --logo and --embed-logo
Note that the --logo option can include a regular URL:
python -m pybadges \
--left-text="python" \
--right-text="3.2, 3.3, 3.4, 3.5, 3.6" \
--whole-link="https://www.python.org/" \
--browser \
--logo='https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/python.svg'If the --logo option is set, the --embed-logo option can also be set.
The --embed-logo option causes the content of the URL provided in --logo
to be embedded in the badge rather than be referenced through a link.
The advantage of using this option is an extra HTTP request will not be required to render the badge and that some browsers will not load image references at all.
You can see the difference in your browser:
A note about --(whole|left|right)-title
The title element is usually displayed as a
pop-up by browsers
but is currently
filtered by Github.
Library usage
pybadges is primarily meant to be used as a Python library.