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

function join_strings

join_strings(*args: any, separator: str = ", ")  str

Takes multiple strings and an optional separator element and joins them to a single string. Each non-string argument will be ignored.

Args:

  • *args (any): Multiple arguments of any type. Only strings will be joined. Arguments of other types will be ignored.
  • separator (str): The separator element which will be put between all arguments. Defaults to ", ".

Returns:

  • str: A combination of all originally given strings, separated by separator.

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)

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.3.tar.gz (6.8 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.3-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mgpy-0.1.3.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for mgpy-0.1.3.tar.gz
Algorithm Hash digest
SHA256 84ae17bad04f551f27c77bc681e068aa79e1db88f3e4c9aeb290ece774a7b0fe
MD5 bb476285b23e22b1cd32dd8032516a0a
BLAKE2b-256 a4061f7f662657dd827997814664e7e196b50a9e53483b38c8af6ee0445cb47e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mgpy-0.1.3.tar.gz:

Publisher: package-and-release.yml on phistoh/mgpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: mgpy-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for mgpy-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0bd99ecd280ba0ae5965df567f49b631d9e0e5738402d5bdea5dbb86ba2af902
MD5 56c6b9e69c09442c0e83125099eac1de
BLAKE2b-256 dc59ae1f21ef3b5eed4a76118ebb916fb3621ff8945219f99d29ba03af693fa6

See more details on using hashes here.

Provenance

The following attestation bundles were made for mgpy-0.1.3-py3-none-any.whl:

Publisher: package-and-release.yml on phistoh/mgpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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