{"id":8651,"library":"smartypants","title":"SmartyPants","description":"SmartyPants is a Python library that converts plain ASCII punctuation in text to \"smart\" typographic HTML entities. It transforms straight quotes to \"curly\" quotes, backticks-style quotes, -- and --- to en- and em-dashes, and three consecutive dots to an ellipsis entity. The current version is 2.0.2, and it is actively maintained with recent fixes for Python 3.12+ compatibility.","status":"active","version":"2.0.2","language":"en","source_language":"en","source_url":"https://github.com/justinmayer/smartypants.py","tags":["text processing","typography","punctuation","html"],"install":[{"cmd":"pip install smartypants","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"smartypants","correct":"import smartypants"},{"symbol":"Attr","correct":"from smartypants import Attr"}],"quickstart":{"code":"import smartypants\n\ntext = '\"SmartyPants\" is smart, so is <code>smartypants</code> -- a Python port...'\nprocessed_text = smartypants.smartypants(text)\nprint(processed_text)\n\n# Example with attributes\nfrom smartypants import Attr\nattrs = Attr.q | Attr.d # Enable quotes and dashes\nprocessed_text_with_attrs = smartypants.smartypants(text, attrs)\nprint(processed_text_with_attrs)","lang":"python","description":"Demonstrates basic usage of the smartypants function to convert ASCII punctuation to typographic entities, and how to use attributes to control conversions."},"warnings":[{"fix":"Update your code to use `smartypants.Attr` for specifying processing options (e.g., `Attr.q | Attr.d`) instead of string arguments. Refer to the official documentation for the updated API.","message":"Version 2.0.0 introduced significant breaking changes, including dropping Pyblosxom support, removing string-type attributes in favor of `Attr` enums, and deprecating old function names like `smartyPants`, `educateQuotes`, and `processEscapes`.","severity":"breaking","affected_versions":"2.0.0 and later"},{"fix":"If smart punctuation appears unexpectedly in specific HTML tags, check if the tag is in the `tags_to_skip` list. You can modify `smartypants.tags_to_skip` or `smartypants._tags_to_skip_regex()` for advanced customization, but be aware of potential side effects.","message":"SmartyPants processes most plain text, but it deliberately skips certain HTML elements (e.g., `<pre>`, `<code>`, `<span>`, `<script>`, `<style>`) by default to prevent unintended conversion of code or other literal content.","severity":"gotcha","affected_versions":"All"},{"fix":"Prepend a backslash before any punctuation character that you wish to remain as a literal ASCII character. For example, `text = \"It's 6\\'2\\\" tall.\"`.","message":"To prevent 'smart' conversions for literal straight quotes, hyphens, or periods (e.g., '6\\'2\"' instead of '6\\u20192\\u201d'), use backslash escapes (`\\`, `\\-`, `\\.`).","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Add `import smartypants` at the top of your Python file.","cause":"The `smartypants` module was not imported before use.","error":"NameError: name 'smartypants' is not defined"},{"fix":"Use the `Attr` enum for specifying processing options. For example, `from smartypants import Attr; smartypants.smartypants(text, attrs=Attr.q | Attr.d)`.","cause":"You are likely attempting to pass a string or incorrect type as an attribute argument to `smartypants.smartypants()`, which was removed in version 2.0.0.","error":"TypeError: smartypants() takes X positional arguments but Y were given (where X and Y are numbers, often 1 and 2)"},{"fix":"Ensure your input text is consistently encoded, typically UTF-8. Explicitly decode input if reading from a file, for example, `text = open('input.txt', encoding='utf-8').read()`.","cause":"This error can occur when processing text with unexpected encodings, particularly when running on systems with default encodings that don't match the input text (e.g., Python 3 with specific locales handling Unicode characters).","error":"UnicodeDecodeError: 'charmap' codec can't decode byte X in position Y: character maps to <undefined>"}]}