Skip to main content

A library and command-line tool for generating Github-style badges

Project description

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 gh-badges 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.

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

pip installation

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

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=)

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 contributer 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pybadges-1.0.0.tar.gz (26.4 kB view details)

Uploaded Source

Built Distribution

pybadges-1.0.0-py3-none-any.whl (27.7 kB view details)

Uploaded Python 3

File details

Details for the file pybadges-1.0.0.tar.gz.

File metadata

  • Download URL: pybadges-1.0.0.tar.gz
  • Upload date:
  • Size: 26.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

File hashes

Hashes for pybadges-1.0.0.tar.gz
Algorithm Hash digest
SHA256 571c89ff5a7a9968c9f81b7541d34a16765cc96ea82eacb92dd1d85e83ac3c45
MD5 54b17e248ca4ab337fb0d43ee00b7f3a
BLAKE2b-256 2eec975a009148b22067bd74ec75f0f9855e03fcb1ec8aede9262a91c158768a

See more details on using hashes here.

Provenance

File details

Details for the file pybadges-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pybadges-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 27.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

File hashes

Hashes for pybadges-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 492ee0b18965ac5a646ee2ce874845194a6e8c2a3b0e4c42415e5f7be624f36c
MD5 594b6520b4c655ac0a588e367fd833d1
BLAKE2b-256 96c9ae3e2595a5074502f2e7ecd2a9a2b12d903ce4b73b049ac67d9807e43606

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page