slugify()
slugany.slugify ¶
slugify(text: 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) -> str
Convert text into a URL-friendly slug.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to slugify. Must be a string. |
required |
separator
|
str | None
|
Separator between words. Defaults to |
None
|
lowercase
|
bool | None
|
Whether to lowercase the output. Defaults to |
None
|
max_length
|
int
|
Maximum slug length. |
0
|
word_boundary
|
bool
|
Truncate at the last word boundary within |
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 |
None
|
style
|
str | None
|
Case style preset ( |
None
|
lang
|
str
|
Language for transliteration
( |
'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'
|
css_safe
|
bool
|
Prefix with |
False
|
html_entities
|
bool
|
Decode HTML entities like |
True
|
smart_punctuation
|
bool
|
Normalize smart quotes, dashes, and zero-width characters. |
True
|
Returns:
| Type | Description |
|---|---|
str
|
The slugified string. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If an invalid |
Examples:
>>> slugify("Hello World!")
'hello-world'
>>> slugify("Café résumé", lang="fr")
'cafe-resume'
>>> slugify("hello world", style="camel")
'helloWorld'