Rust implementation of slugify with optional PyO3 bindings.
Project description
slugify-rs — simple and fast slugs for text
This project provides a small Rust library that turns text into a "slug" — a short, URL-friendly string. For example, "Hello World!" becomes "hello-world". There is also an optional Python extension so Python programs can use the same fast Rust logic.
This README explains how to use the library, how to build the Python extension, and how to run tests. Instructions are written for readers who may not be familiar with Rust or Python packaging.
Quick summary
- Rust users: call the library from your Rust code.
- Python users: build and install the small extension (wheel) using
maturin(instructions below), then callpython_slugify_pi.slugify().
Basic example (Python)
import python_slugify_pi
print(python_slugify_pi.slugify("C'est déjà l'été!"))
# control emoji handling: default keeps compatibility with Python
print(python_slugify_pi.slugify("I ♥ 🚀"))
print(python_slugify_pi.slugify("I ♥ 🚀", transliterate_icons=True))
Quick test after installing the extension
python -c "import python_slugify_pi; print(python_slugify_pi.slugify(\"C'est déjà l'été!\"))"
Prerequisites (short)
- A recent Rust toolchain (install
rustup). - Python 3.8 or newer when you want the Python extension.
maturin(a small tool to build Python extension wheels) if you want the Python module.
If you use Linux, you may also need system build tools (see the BUILD instructions below for exact commands).
How to build and install the Python extension (developer mode)
- Create and activate a Python virtual environment (recommended):
python3 -m venv .venv
source .venv/bin/activate
- Install
maturininto the virtual environment:
pip install --upgrade pip
pip install maturin
- Build and install the extension into the venv for development:
maturin develop --release --features python
This command compiles the Rust code and installs a small Python package
called python_slugify_pi into your virtual environment. You can then
import and use it from Python immediately.
How to build a distributable wheel
maturin build --release -i python --features python
pip install target/wheels/*.whl
This produces a wheel file in target/wheels/ that you can share or
upload to PyPI.
Running tests
- Rust unit tests (run from the project root):
cargo test -p slugify-rs --lib
- Python integration tests (after installing the wheel or using
maturin develop):
pytest tests/python
Notes and troubleshooting (simple)
- If
maturincannot find your Python interpreter, tell it which one to use by adding-i /path/to/pythonto thematurincommand. - On Debian/Ubuntu you may need to install system tools before
building:
sudo apt install build-essential pkg-config python3-dev. - Emoji and symbols: the library tries to match Python behavior by
default, but you can change how emoji are handled with
transliterate_icons(see examples).
How the pre-translations work
There is a small table of language-specific replacements (for
Cyrillic, German, Greek). These are not applied automatically. You can
either pass them as initial replacements or call
apply_pre_translations() before slugifying if you want the same
behavior as the original Python library.
License
This project is available under the MIT license.
Golden tests — simple explanation (for anyone)
What are golden tests?
- Golden tests compare the output of this Rust implementation to the output of the reference Python implementation. The goal is to ensure the Rust behaviour matches the Python behaviour for a set of representative examples.
Why this matters (plain language)
- If you change the code, golden tests help confirm we didn't accidentally change how text is slugified. They are especially useful for tricky cases like emoji, accents or custom replacements.
How to run golden tests locally (easy)
- Create a Python virtual environment and install tools and the reference Python package. From the project root:
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install maturin
pip install python-slugify
- Build and install the Rust Python binding into the venv (so the harness can import it):
.venv/bin/maturin develop --release --features python
- Run the golden harness (it will compare Python vs Rust outputs):
.venv/bin/python tests/golden_harness.py # returns 0 on success
If the harness reports differences, it will print a small diff and exit with a non-zero code. The CI is configured to upload the harness log so we can inspect it when a run fails.
How to regenerate golden outputs
- The golden outputs are produced by the Python reference and stored
by the harness when you ask it to regenerate. To regenerate (and
overwrite the saved goldens), set the environment variable
REGEN_GOLDEN=1and run the harness:
REGEN_GOLDEN=1 .venv/bin/python tests/golden_harness.py
- Only regenerate goldens when you intentionally want to accept new behavior (for example after a deliberate improvement). Ask a reviewer to confirm the change before committing regenerated goldens.
If you want help
- If the harness shows differences and you are not sure why, copy
the
golden_run.logfile into the issue or PR and someone will help triage it. The CI is set up to always upload that log when the golden step runs.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file slugify_rs-0.1.21-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: slugify_rs-0.1.21-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a42532a4050c4fcf5a3988ccd2d1594085a3b9d740db8fc9caf15f8c446a04a3
|
|
| MD5 |
cb3e0bb80116a184e5ffb60f5ff518da
|
|
| BLAKE2b-256 |
9835045c6897d2b2744bd8cfca56b0758c50ee41c88140d3bacf8e02bbb34c79
|
Provenance
The following attestation bundles were made for slugify_rs-0.1.21-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish-pypi.yml on gmaOCR/slugify-rs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
slugify_rs-0.1.21-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
a42532a4050c4fcf5a3988ccd2d1594085a3b9d740db8fc9caf15f8c446a04a3 - Sigstore transparency entry: 561022662
- Sigstore integration time:
-
Permalink:
gmaOCR/slugify-rs@195ca584f90d994f270125afcc7bc8d16204fbd1 -
Branch / Tag:
refs/tags/v0.1.21 - Owner: https://github.com/gmaOCR
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@195ca584f90d994f270125afcc7bc8d16204fbd1 -
Trigger Event:
push
-
Statement type: