Escapism is a Python library providing a simple, generic API for escaping strings. It offers functions for reversible escaping, ideal for preserving string content across systems, and a 'safe_slug' API for creating unique, URL-safe or filesystem-safe strings which are not necessarily reversible. The current version is 1.1.0, and it is part of the Project Jupyter ecosystem, with development continuing as needed.
pip install escapismVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the core functionalities: `escape` for reversible encoding/decoding, `unescape` to revert `escape` operations, and `safe_slug` for creating valid, unique, and often lossy identifiers suitable for system names like Kubernetes object names or filenames. It shows how to customize safe characters and escape characters for precise control.
Do not attempt to `unescape` strings produced by `safe_slug`. Use `escape` and `unescape` for reversible encoding/decoding, and `safe_slug` only when a canonical, safe, and unique representation is needed.
Always pass the `escape_char` argument to `unescape()` if you customized it during the `escape()` call. Example: `escapism.unescape(escaped_string, escape_char=my_char)`.
Always review the default `safe` characters or `is_valid` rules. If your use case requires different characters to remain unescaped or different validity constraints for slugs, provide custom `safe` (for `escape`) or `is_valid` (for `safe_slug`) arguments. For `safe_slug`, you can also provide `max_length` and `slug_char`.
Install the library using pip: `pip install escapism`
Ensure you are using the correct function names as defined in the library, such as `escapism.escape()` or `escapism.safe_slug()`.
Provide the `safe` argument as a string containing allowed characters or a set of characters. For example, `escapism.escape('my string', safe='abc')` or `escapism.escape('my string', safe={'a', 'b', 'c'})`.Ensure the `escape_char` argument is a string with exactly one character. For example, `escapism.escape('my string', escape_char='_')`.Choose an `escape_char` that is not included in the `safe` string or set of characters you provide to `escapism.escape()`.