Generator filter to print a progress bar.

def progressbar(stream, prefix='Loading: ', width=0.5, **options):
    """ Generator filter to print a progress bar. """
    size = len(stream)
    if not size:
        return stream
    if 'width' not in options:
        if width <= 1:
            width = round(shutil.get_terminal_size()[0] * width)
        options['width'] = width
    with ProgressBar(max=size, prefix=prefix, **options) as b:
        b.set(0)
        for i, x in enumerate(stream, 1):
            yield x
            b.set(i)