Skip to main content

A Python package for various utilities

Project description

A simple package containing various command-line utilities.

Table of Contents

Caution

This package does not have any tests. It is not recommended to use it in production. I wrote this package for my own personal use. I don't have any immediate plans to add tests and make it production-ready. Use it at your own risk.

Installation

  pip install mizue

Utilities (Work in Progress)

Grid

This class can be used to print a table/grid in the terminal.

from mizue.printer.grid import Grid, ColumnSettings, Alignment
from mizue.file import FileUtils
import os

column2 = ColumnSettings(title='File', alignment=Alignment.RIGHT)
column3 = ColumnSettings(title='Size', alignment=Alignment.CENTER, width=50)
columns = [column2, column3]


filelist = FileUtils.list_files(".", recursive=True, fullpath=True)
grid_data = list(map(lambda f: [f, FileUtils.get_readable_file_size(os.stat(f).st_size)], filelist))
grid = Grid(columns, grid_data)
grid.print()

ColumnSettings allows the following attributes to be set:

  • title: The title of the column
  • alignment: The alignment of the column. Can be one of the following:
    • Alignment.LEFT
    • Alignment.CENTER
    • Alignment.RIGHT
  • width: The width of the column
  • renderer: A function that takes in an object of type CellRendererArgs and returns a string to be displayed in the column.

Grid allows the following attributes to be set:

  • border_color: The color of the border in hex format
  • border_style: The style of the border. Can be one of the following:
    • BorderStyle.SINGLE
    • BorderStyle.DOUBLE
    • BorderStyle.BASIC
    • BorderStyle.NONE
  • cell_renderer: A function that takes in an object of type CellRendererArgs and returns a string to be displayed in the cell.

Printer

This class contains various static methods for printing text in different colors.

from mizue.printer import Printer

Printer.print('Hello World!', '#ff0000')
Printer.print('Hello World!', (255, 0, 0))

Following is a list of some of the methods available in this class:

  • print(text, text_color, background_color=None, bold=False, underline=False)
  • error(text)
  • warning(text)
  • info(text)
  • success(text)

Using the colorize method from Colorizer class, you can format a text and use it later. For example:

from mizue.printer import Colorizer
colored_text = Colorizer.colorize('Hello World!', '#ff0000')
print(colored_text)

Progress

This is a simple class for displaying progress bars in the terminal.

from mizue.progress import Progress
from time import sleep

progress = Progress(0, 1200, 0) # (start, end, current)
progress.label = 'Progress: ' # This text is displayed before the progress bar
progress.info_text = '(in progress)' # This text is displayed after the progress bar
progress.start()

for i in range(1200):
  progress.update_value(i)
  sleep(0.01)

progress.stop()

Progress allows the following attributes to be set:

  • info_separator: The character to be used to separate the info text from the progress bar
  • info_separaotr_renderer: A function that takes in an object of type InfoSeparatorRendererArgs and returns a string to be used to separate the info text from the progress bar
  • info_text: Text to be displayed after the progress bar
  • info_text_renderer: A function that takes in an object of type InfoTextRendererArgs and returns a string to be displayed after the progress bar
  • label: Text to be displayed before the progress bar
  • label_renderer: A function that takes in an object of type LabelRendererArgs and returns a string to be displayed before the progress bar
  • progress_bar_renderer: A function that takes in an object of type ProgressBarRendererArgs and returns a string to be displayed as the progress bar
  • percentage_renderer: A function that takes in an object of type PercentageRendererArgs and returns a string to be displayed as the percentage
  • spinner_renderer: A function that takes in an object of type SpinnerRendererArgs and returns a string to be displayed as the spinner

An example of rendering a custom label (appears before the progress bar):

from mizue.progress import Progress
from mizue.progress import LabelRendererArgs
from mizue.printer import Colorizer
from time import sleep

def label_renderer(args: LabelRendererArgs) -> str:
  return Colorizer.colorize(args.label, '#ff0000') \
    if args.percentage < 50 \ 
    else Colorizer.colorize(args.label, '#00ff00')

progress = Progress(0, 1200, 0)
progress.label_renderer = label_renderer
progress.start()

for i in range(1200):
  progress.update_value(i)
  sleep(0.1)

progress.stop()

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

mizue-0.7.3.tar.gz (28.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mizue-0.7.3-py3-none-any.whl (35.1 kB view details)

Uploaded Python 3

File details

Details for the file mizue-0.7.3.tar.gz.

File metadata

  • Download URL: mizue-0.7.3.tar.gz
  • Upload date:
  • Size: 28.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for mizue-0.7.3.tar.gz
Algorithm Hash digest
SHA256 f3fa6ac6145a9fa980d905b348a619212e36b21ea31ff285bb86ef88f3e9037b
MD5 65e2427ecc49eb67dff0ae0a4b9be5ad
BLAKE2b-256 345db5f3935a9c2d7fc12ced33cdd526c10893c5604f515fbdd8d7b7b47f335a

See more details on using hashes here.

File details

Details for the file mizue-0.7.3-py3-none-any.whl.

File metadata

  • Download URL: mizue-0.7.3-py3-none-any.whl
  • Upload date:
  • Size: 35.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for mizue-0.7.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5e359249b49df1d9b4da3ea1424040f50ccda59fc30a1fff912b0f1842ed7d8e
MD5 76163a0b53c355d89cfe3538c93076d9
BLAKE2b-256 1672f056b57e2a180490eaa852e12fe262435a6f535c113e32c2a67ddb1f5455

See more details on using hashes here.

Supported by

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