Registry / serialization / smartypants

smartypants

JSON →
library2.0.2pypypi✓ verified 94d ago

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.

pip install smartypants
INSTALL
IMPORT
SIG · SMARTYPANTS
S
smartypants
serializationpythonv2.0.2
Install
1.5s avg
Import
—
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v2.0.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

smartypants
✓ import smartypants
Attr
✓ from smartypants import Attr

Demonstrates basic usage of the smartypants function to convert ASCII punctuation to typographic entities, and how to use attributes to control conversions.

import smartypants text = '"SmartyPants" is smart, so is <code>smartypants</code> -- a Python port...' processed_text = smartypants.smartypants(text) print(processed_text) # Example with attributes from smartypants import Attr attrs = Attr.q | Attr.d # Enable quotes and dashes processed_text_with_attrs = smartypants.smartypants(text, attrs) print(processed_text_with_attrs)
Debug
Known issues
breakingVersion 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`.
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.
affects: 2.0.0 and later
gotchaSmartyPants 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.
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.
affects: All
gotchaTo prevent 'smart' conversions for literal straight quotes, hyphens, or periods (e.g., '6\'2"' instead of '6\u20192\u201d'), use backslash escapes (`\`, `\-`, `\.`).
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."`.
affects: All
Errors
Common errors & fixes
NameError: name 'smartypants' is not defined
The `smartypants` module was not imported before use.
fix
Add `import smartypants` at the top of your Python file.
TypeError: smartypants() takes X positional arguments but Y were given (where X and Y are numbers, often 1 and 2)
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.
fix
Use the `Attr` enum for specifying processing options. For example, `from smartypants import Attr; smartypants.smartypants(text, attrs=Attr.q | Attr.d)`.
UnicodeDecodeError: 'charmap' codec can't decode byte X in position Y: character maps to <undefined>
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).
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()`.
Upgrade
Version history
2.0.2latest on PyPI · released Jun 17, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
16
Anthropic
1
Resources
smartypants — pip install smartypants · libregistry