skillfed

escapism

Simple, generic API for escaping strings.

escapism v1.1.0 292.6K downloads/30d#7,961 on PyPI3
Permissive license MIT Active released

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 escapism

uv

uv add escapism

poetry

poetry add escapism

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersIntended Audience :: Science/ResearchIntended Audience :: System AdministratorsProgramming Language :: PythonProgramming Language :: Python :: 3

Tags

escape unescape stringstext escaping librarysafe slug generatorkubernetes valid identifierscharacter escaping utilitystring sanitizationescape sequences python
string-escapingkubernetesslug-generation

More Text Processing packages