Skip to content

remove_prefix

faststream.cli.utils.parser.remove_prefix #

remove_prefix(text, prefix)

Removes a prefix from a given text.

Python 3.8 compatibility function

PARAMETER DESCRIPTION
text

The text from which the prefix will be removed.

TYPE: str

prefix

The prefix to be removed from the text.

TYPE: str

RETURNS DESCRIPTION
str

The text with the prefix removed. If the text does not start with the prefix, the original text is returned.

TYPE: str

Source code in faststream/cli/utils/parser.py
def remove_prefix(text: str, prefix: str) -> str:
    """Removes a prefix from a given text.

    Python 3.8 compatibility function

    Args:
        text (str): The text from which the prefix will be removed.
        prefix (str): The prefix to be removed from the text.

    Returns:
        str: The text with the prefix removed. If the text does not start with the prefix, the original text is returned.
    """
    if text.startswith(prefix):
        return text[len(prefix) :]
    return text