Rust implementation of slugify with optional PyO3 bindings.
Project description
slugify-rs
Rust implementation of slugify with optional PyO3 bindings.
This crate provides a fast Rust core for string slugification and an
optional Python extension module (via PyO3) for use from Python
projects. The Python module is exposed as python_slugify_pi when the
python Cargo feature is enabled.
Quick start
If you only use Rust, add the crate to your Cargo.toml and call
slugify from Rust. If you want a Python extension, build a wheel with
maturin (instructions below).
Prerequisites
- Rust toolchain: install
rustup(Rust 1.56+ recommended):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Python 3.8+ and a working
pip. - On Debian/Ubuntu install system build deps:
sudo apt update && sudo apt install -y build-essential pkg-config python3-dev libssl-dev
- Install
maturinin your Python virtualenv to build wheels:
python -m venv .venv
. .venv/bin/activate
pip install --upgrade pip
pip install maturin
Note: macOS users should ensure Xcode command line tools are installed.
Build & install Python wheel (recommended)
For development (install directly into the active venv):
maturin develop --release --features python
To build a wheel for distribution and then install it:
maturin build --release -i python --features python
pip install target/wheels/*.whl
develop installs the built extension into your venv for quicker
iteration. build produces a wheel in target/wheels/ for distribution.
Example (Python)
import python_slugify_pi
print(python_slugify_pi.slugify("C'est déjà l'été!"))
# Control icon transliteration (default False for Python parity)
print(python_slugify_pi.slugify("I ♥ 🚀"))
print(python_slugify_pi.slugify("I ♥ 🚀", transliterate_icons=True))
Cargo.toml snippet
Add the optional python feature and set the crate type when building
for Python (example):
[package]
name = "slugify-rs"
version = "0.1.0"
[lib]
crate-type = ["cdylib"]
[features]
default = []
python = ["pyo3/extension-module"]
[dependencies]
pyo3 = { version = "0.26", optional = true, features = ["extension-module"] }
deunicode = "*"
When building with maturin, --features python will enable the
PyO3 extension configuration.
Running tests
Rust unit tests:
cargo test -p slugify-rs --lib
Python integration tests (after installing the wheel or using
maturin develop):
pytest tests/python
Troubleshooting
- Linker errors on Linux: ensure
build-essentialandpython3-devare installed. - If
maturincomplains about the Python interpreter, pass-iwith the interpreter executable or path used to create the venv, e.g.-i /home/user/.venv/bin/python. - If symbol transliteration differs from
python-slugify, see thetransliterate_iconsoption documented below.
Transliteration of icons / emoji
The Rust implementation uses deunicode for transliteration, which may
map certain symbols or emoji to English words (for example ♥ ->
"hearts", 🚀 -> "rocket"). The reference Python implementation
(text-unidecode) handles some symbols differently (often removing
them), which can cause output mismatches.
The PyO3 binding exposes a keyword argument transliterate_icons
(default: False). When True, symbol/emoji characters are
transliterated to words by the Rust code. When False, symbol/emoji
characters are removed before transliteration to match the common
Python behavior.
CI / manylinux
For publishing to PyPI, build manylinux wheels. maturin has a
--manylinux option; see maturin docs for recommended Docker images
and CI workflows. In GitHub Actions you can use the official
maturin/action for cross-platform builds.
License
This crate uses the license(s) MIT.
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.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: slugify_rs-0.1.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.6 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 |
c66e85353e35c33302444007e6fc3301166543e8b8caf9d060c9568bcec0c571
|
|
| MD5 |
dc3f9681464ba9c9db0f48074ff9f389
|
|
| BLAKE2b-256 |
29132eb614725ba3d91a7141c49a11b4bebd7f05dbf81df268a1e3b6db70a54a
|
Provenance
The following attestation bundles were made for slugify_rs-0.1.1-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.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
c66e85353e35c33302444007e6fc3301166543e8b8caf9d060c9568bcec0c571 - Sigstore transparency entry: 551757497
- Sigstore integration time:
-
Permalink:
gmaOCR/slugify-rs@84e77c03ae05b10fc4d2fc01a968c3ef1bec0cf0 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/gmaOCR
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@84e77c03ae05b10fc4d2fc01a968c3ef1bec0cf0 -
Trigger Event:
workflow_dispatch
-
Statement type: