Typing Stubs for python-slugify
This package provides typing stubs for the `python-slugify` library, enabling static type checkers like MyPy or Pyright to validate usage of `python-slugify`. It does not contain any executable code itself. The current version is 8.0.2.20240310. As part of the typeshed project, its releases are typically tied to updates in the upstream `python-slugify` library or typeshed's own update cadence.
Warnings
- gotcha `types-python-slugify` is a stub-only package. It does not contain any runnable code or provide the `slugify` function/class directly. You must install the actual `python-slugify` library to use the functionality.
- gotcha Do not attempt to import `slugify` or `Slugify` from `types_python_slugify` (or any variation of the stub package name). Imports should always come from `from slugify import ...` which refers to the runtime library.
- gotcha The versioning of `types-python-slugify` (e.g., `8.0.2.20240310`) includes a typeshed timestamp (`20240310`). While the `8.0.2` often aligns with the `python-slugify` library version, minor updates to stubs may occur independently of `python-slugify`'s point releases.
Install
-
pip install types-python-slugify -
pip install python-slugify types-python-slugify
Imports
- slugify
from slugify import slugify
- Slugify
from slugify import Slugify
Quickstart
import os
# Install both packages: pip install python-slugify types-python-slugify
from slugify import slugify, Slugify
def process_title(title: str) -> str:
"""Converts a title to a URL-friendly slug."""
# Type checkers (like MyPy) will use types-python-slugify here
return slugify(title)
def create_custom_slugifier() -> Slugify:
"""Creates a custom slugifier instance."""
# Example of using the Slugify class, also type-checked
return Slugify(to_lower=True, separator='_')
# --- Example Usage ---
# Basic slugification
original_text = "My Awesome Article Title!"
slugged_text = process_title(original_text)
print(f"Original: '{original_text}'\nSlugged: '{slugged_text}'")
# Using a custom slugifier
custom_slg = create_custom_slugifier()
custom_slugged = custom_slg("Another-Example String")
print(f"Custom slugged: '{custom_slugged}'")
# To verify type checking, run `mypy your_script_name.py`
# For example, calling process_title(123) would raise a type error.