escapism
Simple, generic API for escaping strings.
What it is and what it does
Escapism is a lightweight string escaping library that converts unsafe characters into escape sequences using a configurable escape character (default: underscore). It provides two main APIs: a reversible escape/unescape pair for general text escaping, and a lossy slug generator designed for Kubernetes resource naming that enforces strict validity rules (lowercase, alphanumeric plus hyphens, length 1–63, starting with a letter). The slug function is useful when you need a valid identifier but don't need to recover the original string; it applies hashing to ensure uniqueness when the input violates validity constraints.
The package has no runtime dependencies and installs as a pure Python wheel. It's actively maintained and used in production by JupyterHub-related projects. The API is minimal—just two functions with optional arguments for customizing the escape character and safe-character set—making it straightforward to integrate into any text-processing pipeline that needs controlled character escaping or identifier generation.
Use it for:
- Escape special characters in strings for use in URLs, filenames, or configuration keys while preserving reversibility.
- Generate valid Kubernetes object names and label values from arbitrary user input with automatic hashing for collision avoidance.
- Sanitize usernames or identifiers to meet strict naming constraints (length, character set, start/end rules) in distributed systems.
- Encode text for storage in systems with restricted character sets while maintaining the ability to decode it later.
- Create URL-safe slugs from user-provided strings for web applications or APIs.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Escapism provides two functions to escape and unescape text using a customizable escape character and safe-character set, plus a lossy slug generator that produces valid Kubernetes-compatible identifiers.
Yes. Escapism is a stable, dependency-free utility with a clear, minimal API and active maintenance. It's well-suited for any project needing string escaping or Kubernetes-compatible slug generation. No known vulnerabilities, permissive license, and low install friction make it a safe choice.
Install
escapism on PyPI
pip
pip install escapismuv
uv add escapismpoetry
poetry add escapismInstalling escapism
Before you install
Low install friction with no runtime dependencies. Actively maintained as of 2026-08-01 with a stable release history since 2015. Requires Python 3.9 or later.
License in practice
MIT license permits use in proprietary and open-source projects with minimal restrictions; attribution required.
Quickstart
import escapism
escaped = escapism.escape('string to escape')
# 'string_20to_20escape'
original = escapism.unescape(escaped)
# For Kubernetes-compatible slugs:
slug = escapism.safe_slug('my-identifier')
# 'my-identifier'
Requires Python 3.9 or later.
Verify before relying
- Whether safe_slug's trim-and-hash behavior (appending hash after '---') is suitable for all use cases beyond Kubernetes.
- Performance characteristics when escaping very large strings or with large safe-character sets.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 246 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 292,593/month — #7,961 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: escapism-1.1.0-py3-none-any.whl
Keywords: escape
Tags
More Text Processing packages
A drop-in replacement for Python's standard…
permissive · top 100 on PyPI
pyparsingpyparsing provides a library for building text…
permissive · top 1,000 on PyPI
docutilsDocutils converts plaintext documentation in…
unclear · top 1,000 on PyPI
RapidFuzzRapidFuzz provides fast fuzzy string matching…
permissive · top 1,000 on PyPI
tinycss2tinycss2 parses CSS strings into token and…
permissive · top 1,000 on PyPI
llama-parseLlamaParse parses complex documents (PDFs,…
permissive · top 1,000 on PyPI
slugifyConverts text strings into URL-safe slugs by…
unclear · top 15,000 on PyPI
UnidecodeConverts Unicode text to ASCII-safe…
copyleft · top 1,000 on PyPI
python-slugifyConverts text strings—including unicode, HTML…
permissive · top 1,000 on PyPI
MarkupSafeMarkupSafe provides a text object that escapes…
permissive · top 100 on PyPI
anyasciiConverts Unicode text to ASCII-only equivalents…
permissive · top 5,000 on PyPI
random-slugsGenerates random word-based slugs with…
unclear · top 15,000 on PyPI
unicode-slugifyConverts strings into URL-friendly slugs while…
permissive · top 15,000 on PyPI
django-autoslugProvides a Django model field that…
copyleft · top 15,000 on PyPI
coolnameGenerates random human-readable names and…
permissive · top 5,000 on PyPI
sqidsSqids encodes numbers into short, unique,…
permissive · top 15,000 on PyPI