pybadges2
pybadges2 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
pybadges2 can be installed using pip:
pip install pybadges2
To test that installation was successful, try:
python -m pybadges2 --left-text=build --right-text=failure --right-color='#c00' --browser
You will see a badge like this in your browser:
Usage
pybadges2 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 pybadges2 command arguments can be found using
the --help flag:
pybadges2 --help
(or)
python -m pybadges2 --help
But the following usage demonstrates every interesting option:
pybadges2 \
--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" \
--browser
A note about --logo and --embed-logo
Note that the --logo option can attempt include a regular URL:
pybadges2 \
--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 may 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.
from pybadges2 import badge
s = badge(left_text='coverage', right_text='23%', right_color='red')
# s is a string that contains the badge data as an svg image.
print(s[:40]) # => <svg height="20" width="191.0" xmlns="ht
The keyword arguments to badge() are identical to the command flags names
described above except with keyword arguments using underscore instead of
hyphen/minus (e.g. --left-text => left_text=)
Server usage
pybadges2 can be used to serve badge images on the web.
server-example contains an example of serving badge images from a Flask server.
Caveats
-
pybadges2 uses a pre-calculated table of text widths and kerning distances (for Western glyphs) to determine the size of the badge. Eastern European languages may be rendered less well than Western European ones:
And glyphs not present in Deja Vu Sans (the default font) may be rendered very poorly:
-
pybadges2 does not have any explicit support for languages that are written right-to-left (e.g. Arabic, Hebrew) and the displayed text direction may be incorrect:
Development
Testing can be performed using tox:
git clone https://github.com/jdknight/pybadges2.git
cd pybadges2
tox
Users wishing to contribute, please read the contributor guide.
Metadata
Release files for pybadges2 2024.11.23
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pybadges2-2024.11.23.tar.gz | 72.3 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pybadges2-2024.11.23-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 126.5 kB
Release files / pybadges2-2024.11.23.tar.gz
| Download URL | pybadges2-2024.11.23.tar.gz |
|---|---|
| Size | 72.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cf31f0cdbf5554044b10aaacf178a729c5d23f028113ded5c3d61ac2a8c73336
|
|
BLAKE2b-256 checksum How to use checksums |
6785701ce82567fb449906d4f1e8edca8daf51c5987746f3b076f7d809c0e3cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2024.
Transparency logRelease files / pybadges2-2024.11.23-py3-none-any.whl
| Download URL | pybadges2-2024.11.23-py3-none-any.whl |
|---|---|
| Size | 54.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
278c25f5b8ffc59b631f5c6531a34ff1f4c6e7d3322aa593f018893526a55f05
|
|
BLAKE2b-256 checksum How to use checksums |
bf569770b6605a85bc8abc5953a6e39678a1ccdeb65eddde8ca18ac95afe24c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2024.
Transparency logSecurity for pybadges2 2024.11.23
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for pybadges2-2024.11.23.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2024.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.