Skip to main content

A small package containing simple, useful methods I regularly use and don't want to manually copy into several projects. Most methods are probably to be found in other modules.

Project description

mgpy ("Magpie")

linting: pylint Code style: black Tests Coverage

A small package containing simple, useful methods I regularly use and don't want to manually copy into several projects.

Contains the following modules:

mgstr ("Magister")

Contains methods relating to strings.

function log_print

log_print(s: str, level: Loglevel = Loglevel.INFO, time_format: str = "%Y-%m-%d %H:%M:%S")

Takes a string and outputs it with an additional prefix indicating importance.

Args:

  • s (str): The string which will be output
  • level (Loglevel, optional): The prefix indicating importance. Defaults to Loglevel.INFO.
  • time_format (str, optional): A (C-time adherent) string to format the time. Defaults to %Y-%m-%d %H:%M:%S

function truncate_string

truncate_string(s: str, length: int, ellipsis: str = '...')  str

Takes a string, truncates it to the given length, adding a given ellipsis.

Args:

  • s (str): The string which will be shortened.
  • length (int): The length of the shortened string including the length of the ellipsis.
  • ellipsis (str, optional): An optional ellipsis which will be appended. Defaults to "...".

Returns:

  • str: A truncated version of the string with given length (and ellipsis)

function insert_line_into_string

insert_line_into_string(line: str, s: str, pos: int)  str

Takes two strings and inserts the first one into the second one as a new line at the given position.

Args:

  • line (str): The line to insert.
  • s (str): The (potential multi-line) string in which to insert line.
  • pos (int): The line number of the newly inserted line. Uses Python's List.insert() position syntax—negative indices, e.g. -1, inserts line before the last element.

Returns:

  • str: A new string containing line at the given line number.

class Loglevel

A string enum defining importance levels for usage in the 'log_print' method

Members:

  • INFO = "Information": Used to indicate an informational output.
  • WARNING = "Warning": Used to indicate a warning.
  • ERROR = "ERROR": Used to indicate an error.

mgcl ("Magical")

Contains methods to work with colors and convert between different representations.

tbd.

mgnet ("Magnet")

Contains network related methods.

tbd.

mgnum ("Magnum")

Contains methods relating to numbers and their representation.

function generate_human_readable_number

generate_human_readable_number(
    number: int,
    suffixes: list[str] = None,
    decimal_separator: str = '.'
)  str

Takes a number and returns a 'human readable' string. E.g., 15000001.5M

Args:

  • number (int): The number to represent.
  • suffixes (list[str], optional): A list of ascendingly sorted suffixes for each order of magnitude. Defaults to ["k", "M", "G", "T"].
  • decimal_separator (str, optional): The decimal separator. Defaults to ".".

Returns:

  • str: The human readable string.

mgte ("Mogote")

Contains methods to work with time and date.

tbd.

mgmin ("Megumin")

Contains methods which don't fall into the other categories.

tbd.


Module descriptions were automatically generated via lazydocs.

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

mgpy-0.1.2.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

mgpy-0.1.2-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file mgpy-0.1.2.tar.gz.

File metadata

  • Download URL: mgpy-0.1.2.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.4

File hashes

Hashes for mgpy-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8d0404cf7b0997fd0b691dcce17e8ba4b3ab5747e3f1236b34f2efb2c767ccc9
MD5 b2196f4ba814f71e79e980bdc76f714b
BLAKE2b-256 1797ba0d3861edf1252544dfdc061b5b8c3621676cf8e32fd05596e73310ddef

See more details on using hashes here.

File details

Details for the file mgpy-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mgpy-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.4

File hashes

Hashes for mgpy-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2cc8fcb37743000a5d16f9602a221a445c8f7cce913279b5b0de0deb84d614a8
MD5 7d0facde0bf06b01bd5bf958b5a6255f
BLAKE2b-256 d44e42956778029f0efee6d3b8ba52c71e94ec1cc92335af89b5004e1f027b5a

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