Skip to main content

CircleCI pypi versions

pybadges

pybadges is a Python library and command line tool that allows you to create Github-style badges as SVG images. For example:

pip installation pip installation pip installation

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' --browser

You will see a badge like this in your browser:

pip installation

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" \
    --browser

pip installation

A 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'

pip installation

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:

--embed-logo=yes --embed-logo=no

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 pybadges 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

pybadges can be used to serve badge images on the web.

server-example contains an example of serving badge images from a Flask server.

Caveats

  • pybadges uses a pre-calculated table of text widths and kerning distances (for western glyphs) to determine the size of the badge. So Eastern European languages may be rendered less well than Western European ones:

    pip installation

    and glyphs not present in Deja Vu Sans (the default font) may be rendered very poorly:

    pip installation

  • pybadges 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:

    pip installation

Development

git clone https://github.com/google/pybadges.git
cd pybadges
python -m virtualenv venv
source venv/bin/activate
# Installs in edit mode and with development dependencies.
pip install -e .[dev]
nox

If you'd like to contribute your changes back to pybadges, please read the contributor guide.

Versioning

We use SemVer for versioning.

License

This project is licensed under the Apache License - see the LICENSE file for details

This is not an officially supported Google product.

Release files for pybadges 3.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pybadges 3.0.1
File Size Uploaded
pybadges-3.0.1.tar.gz 58.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pybadges 3.0.1
File Interpreter ABI Platform
pybadges-3.0.1-py3-none-any.whl Python 3 none any Details

Total release size:115.9 kB

Release files / pybadges-3.0.1.tar.gz

Download URL pybadges-3.0.1.tar.gz
Size 58.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a29962d3435a5a1b5b775f3f2b89e2d519f39d947d5118c279e36bf890158faa
BLAKE2b-256 checksum
How to use checksums
0e6a6296d49ba2b4b62e7ea97606c6c6b21c291784afd63c56b2390f658c8cb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / pybadges-3.0.1-py3-none-any.whl

Download URL pybadges-3.0.1-py3-none-any.whl
Size 57.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e37f3eacd503143c3110438cf69bc3f2cd988ce4514de23dd5de8cbfa162a05
BLAKE2b-256 checksum
How to use checksums
dca478905bcfa9db1e6402721a2f4a66ac45c2251c7a842cd4aeaec77b37456c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release history Release notifications | RSS feed

This release

3.0.1 This release

2 release files

3.0.0

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.0.1

2 release files

1.1.0

1 release file

1.0.3

1 release file

1.0.2

2 release files

1.0.1

1 release file

1.0.0

2 release files

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page