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: 'Information'>)

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.

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.1.tar.gz (7.1 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.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mgpy-0.1.1.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.2

File hashes

Hashes for mgpy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 23cd40f4e6272b044a96adc233427143c92801be86f65611e85d9d67dd63756d
MD5 b4ceffa6fcd8aa89c2c12b93df301620
BLAKE2b-256 aae10f05a08d416f707dc7fe424888480229444257f021531a5a8f60df2093a3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mgpy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.2

File hashes

Hashes for mgpy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 26e0f8ba5cd45415b7551032d3c0247cc89545238165d52156cc20a7d05a3288
MD5 38bc509dadf545f0427c78a44b835a63
BLAKE2b-256 f4f32e32bfa1f8b347474a66b6a9c02b325e1b7b4a5b7a8168dc960b3215510e

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