Skip to content

slugify_batch()

slugany.slugify_batch

slugify_batch(texts: Iterable[str], *, separator: str | None = None, lowercase: bool | None = None, max_length: int = 0, word_boundary: bool = False, stopwords: Iterable[str] | None = None, allow_unicode: bool = False, replacements: Mapping[str, str] | Iterable[tuple[str, str]] | None = None, style: str | None = None, lang: str = 'auto', fallback: str = '', emoji_mode: str = 'strip', css_safe: bool = False, html_entities: bool = True, smart_punctuation: bool = True) -> list[str]

Slugify multiple texts in a single call.

Parameters:

Name Type Description Default
texts Iterable[str]

Iterable of strings to slugify.

required
separator str | None

Separator between words. Defaults to "-" (or the style preset's separator when a style is specified).

None
lowercase bool | None

Whether to lowercase the output. Defaults to True (or the style preset's setting when a style is specified).

None
max_length int

Maximum slug length. 0 means no limit.

0
word_boundary bool

Truncate at the last word boundary within max_length.

False
stopwords Iterable[str] | None

Iterable of words to remove from the output.

None
allow_unicode bool

Preserve Unicode characters instead of transliterating.

False
replacements Mapping[str, str] | Iterable[tuple[str, str]] | None

Mapping or iterable of (old, new) pairs applied pre and post.

None
style str | None

Case style preset (kebab, snake, camel, pascal, dot, train, filename, url).

None
lang str

Language for transliteration (auto, es, pt, de, fr, it).

'auto'
fallback str

String to return when the slug would be empty. This value is returned as-is — it should be a valid slug.

''
emoji_mode str

How to handle emojis (strip, text, keep).

'strip'
css_safe bool

Prefix with s{separator} if the slug starts with a digit.

False
html_entities bool

Decode HTML entities like &.

True
smart_punctuation bool

Normalize smart quotes, dashes, and zero-width characters.

True

Returns:

Type Description
list[str]

A list of slugified strings, one per input text.

Raises:

Type Description
TypeError

If any text is not a string.

ValueError

If an invalid style, lang, emoji_mode, empty separator, or empty replacement key is provided.

Examples:

>>> slugify_batch(["Hello World", "Foo Bar"])
['hello-world', 'foo-bar']
Source code in slugany/_slugify.py
def slugify_batch(
    texts: Iterable[str],
    *,
    separator: str | None = None,
    lowercase: bool | None = None,
    max_length: int = 0,
    word_boundary: bool = False,
    stopwords: Iterable[str] | None = None,
    allow_unicode: bool = False,
    replacements: Mapping[str, str] | Iterable[tuple[str, str]] | None = None,
    style: str | None = None,
    lang: str = "auto",
    fallback: str = "",
    emoji_mode: str = "strip",
    css_safe: bool = False,
    html_entities: bool = True,
    smart_punctuation: bool = True,
) -> list[str]:
    """Slugify multiple texts in a single call.

    Args:
        texts: Iterable of strings to slugify.
        separator: Separator between words. Defaults to ``"-"`` (or the
            style preset's separator when a style is specified).
        lowercase: Whether to lowercase the output. Defaults to ``True``
            (or the style preset's setting when a style is specified).
        max_length: Maximum slug length. ``0`` means no limit.
        word_boundary: Truncate at the last word boundary within ``max_length``.
        stopwords: Iterable of words to remove from the output.
        allow_unicode: Preserve Unicode characters instead of transliterating.
        replacements: Mapping or iterable of ``(old, new)`` pairs applied pre and post.
        style: Case style preset (``kebab``, ``snake``, ``camel``,
            ``pascal``, ``dot``, ``train``, ``filename``, ``url``).
        lang: Language for transliteration
            (``auto``, ``es``, ``pt``, ``de``, ``fr``, ``it``).
        fallback: String to return when the slug would be empty.
            This value is returned as-is — it should be a valid slug.
        emoji_mode: How to handle emojis (``strip``, ``text``, ``keep``).
        css_safe: Prefix with ``s{separator}`` if the slug starts with a digit.
        html_entities: Decode HTML entities like ``&``.
        smart_punctuation: Normalize smart quotes, dashes, and zero-width
            characters.

    Returns:
        A list of slugified strings, one per input text.

    Raises:
        TypeError: If any text is not a string.
        ValueError: If an invalid ``style``, ``lang``, ``emoji_mode``,
            empty ``separator``, or empty replacement key is provided.

    Examples:
        >>> slugify_batch(["Hello World", "Foo Bar"])
        ['hello-world', 'foo-bar']
    """
    return [
        slugify(
            text,
            separator=separator,
            lowercase=lowercase,
            max_length=max_length,
            word_boundary=word_boundary,
            stopwords=stopwords,
            allow_unicode=allow_unicode,
            replacements=replacements,
            style=style,
            lang=lang,
            fallback=fallback,
            emoji_mode=emoji_mode,
            css_safe=css_safe,
            html_entities=html_entities,
            smart_punctuation=smart_punctuation,
        )
        for text in texts
    ]