string_py package

Submodules

string_py.string_py module

class string_py.string_py.Color[source]

Bases: object

Color variations for prints

basic = '\x1b[37m'
bold = ('\x1b[1m',)
error = ('\x1b[31m',)
force = ('\x1b[0m',)
reset = ('\x1b[0m',)
underline = ('\x1b[4m',)
class string_py.string_py.Format[source]

Bases: object

Format texts

static align(values: dict[str, str])[source]

Align a text

Parameters:

valuesdict[str, str] Texts to align {“Left side”: “Right side”}

Returns:

Returns a string with the key aligned left and the value right dependent from the keys

Examples

values = {"Username:": "John", "Register Date:": "01.01.2001"}

Username:        John
Register Date:   01.01.2001
static embed(title: str, description: str | None = None, url: str | None = None, fields: list[dict[str, str]] | None = None, footer: str | None = None, author: str | None = None, image: str | None = None)[source]

Create an embed

Parameters:
  • titlestr Title of the embed

  • descriptionstr Description of the embed

  • urlstr Url of the embed

  • fieldslist[dict[str, str]] Fields of the embed

  • footerstr Footer of the embed

  • authorstr Author of the embed

  • imagestr Image of the embed

Returns:

str

static surround(values: str | list[str], all_: str | None = None, left: str = '│', top: str = '─', bottom: str = '─', top_left: str = '┌', top_right: str = '┐', bottom_left: str = '└', bottom_right: str = '┘') str[source]

Surround a text with chars

Parameters:
  • bottom – Char to surround the bottom with

  • top – Char to surround the top with

:param values:str

Text to surround

Parameters:
  • all – Char to surround everything with (Overrides all other chars)

  • bottom_right – Char to surround the bottom right corner with

  • bottom_left – Char to surround the bottom left corner with

  • top_right – Char to surround the top right corner with

  • top_left – Char to surround the top left corner with

  • left – Char to surround the left side with

Returns:

Returns a string with the text surrounded with certain chars

static table(values: list[list[str]], border: bool = True) str[source]

Create a table

Parameters:
  • valueslist[list[str]] The values to create the table with

  • borderTrue Set to False to remove the border

Returns:

Returns the table as string

class string_py.string_py.Printer(active: bool = True)[source]

Bases: object

Adds new print methods to work with.

Parameters:

activeTrue If set to False, no more prints are executed. Exception: force Parameter is set to True.

async aio_slow(args: str, speed: float = 0.1, force: bool = False, error: bool = False) None[source]

Async slow print: Char after char gets printed in a certain speed

Parameters:
  • argsstr The text to print.

  • speed0.1 The speed in wich the chars will get printed out

  • forceFalse Set to True to print always, even if active is set to False.

  • errorFalse Set to True to print always, even if active is set to False, gets highlighted with red color.

slow(args: str, speed: float = 0.2, force: bool = False, error: bool = False) None[source]

Slow print: Char after char gets printed in a certain speed

Parameters:
  • argsstr The text to print.

  • speed0.1 The speed in wich the chars will get printed out

  • forceFalse Set to True to print always, even if active is set to False.

  • errorFalse Set to True to print always, even if active is set to False, gets highlighted with red color.

time(args: str, dt: bool = True, force: bool = False, error: bool = False) None[source]

Timestamp print: Print with the current day and time.

Parameters:
  • argsstr The text to print.

  • dtTrue Set to False to turn off timestamp.

  • forceFalse Set to True to print always, even if active is set to False.

  • errorFalse Set to True to print always, even if active is set to False, gets highlighted with red color.

class string_py.string_py.Str(values: str | int)[source]

Bases: str

Functions to work with strings

Parameters:

valuesstr The value you want to work with

first(length: int = 1, remove=False) str[source]

A simplification for getting/removing the first chars in a string

Parameters:
  • length – The amount of chars

  • remove – If set to True removes length of values

generate(length: int | None = None, min_: int | None = None, max_: int | None = None) str[source]

Generate a random string out of values

Parameters:
  • length – Generate with certain length

  • min – Generate with random length, max_ required

  • max – Generate with random length, min_ required

Returns:

Returns random string out of values with length out of parameters

get_lower(chars: bool = True, index: bool = False) int | list[str] | dict[int, str][source]

Get how many lower chars are in values

Parameters:
  • charsTrue If set to True, returns a list of all lower chars If set to False, returns the number of lower chars

  • indexFalse If set to True, also returns the Indexes of lower chars (chars MUST be True)

get_numeric(chars: bool = True, index: bool = False) int | list[str] | dict[int, str][source]

Get how many numeric chars are in values

Parameters:
  • charsTrue If set to True, returns a list of all numeric chars If set to False, returns the number of numeric chars

  • indexFalse If set to True, also returns the Indexes of numeric chars (chars MUST be True)

get_punctuation(chars: bool = True, index: bool = False) int | list[str] | dict[int, str][source]

Get how many punctuation chars are in values

Parameters:
  • charsTrue If set to True, returns a list of all punctuation chars If set to False, returns the number of punctuation chars

  • indexFalse If set to True, also returns the Indexes of punctuation chars (chars MUST be True)

get_upper(chars: bool = True, index: bool = False) int | list[str] | dict[int, str][source]

Get how many upper chars are in values

Parameters:
  • charsTrue If set to True, returns a list of all uppercase chars If set to False, returns the number of uppercase chars

  • indexFalse If set to True, also returns the Indexes of lower chars (chars MUST be True)

last(length: int = 1, remove=False) str[source]

A simplification for getting/removing the last chars in a string

Parameters:
  • length – The amount of chars

  • remove – If set to True removes length of values

remove(*chars: str) str[source]

Remove chars from string

Parameters:

chars – The chars you want to remove

split(each: int | None = None, chars: str | None = None) list[str][source]

An extension of the built-in .split method. Also split on certain index

Parameters:
  • each – The index you want to split at

  • chars – The char or word you want to split at

Returns:

Returns list with splittet values

Module contents