Skip to main content

polytypo

polytypo

PyPI version CI PyPI downloads License: MIT

Locale-correct quotes, dashes, ellipses, apostrophes, symbols and no-break spaces —
one portable spec, designed for byte-identical output across runtimes.

Try it live, no install: polytypo.dev

This is the Python implementation. The full spec — all locales, all rules, worked examples in each — lives in polytypo/polytypo. This runtime supports the text and html modes fully, and markdown for the commonmark dialect only — mdx raises POLYTYPO_INVALID_DIALECT (no MDX/JSX parser is available for Python; see Supported dialects).

Install

pip install polytypo

Usage

from polytypo import transform

transform("She said, \"it's fine\" -- but I wasn't sure...", locale="en-US")
# She said, “it’s fine”—but I wasn’t sure…

Same input, one locale changed — quotes, dash spacing and all follow the target locale, not a single hardcoded style:

transform('Sie sagte: "Alles gut" -- aber ich war mir nicht sicher...', locale="de-DE")
# Sie sagte: „Alles gut“ – aber ich war mir nicht sicher…

HTML and Markdown are first-class modes, not an afterthought — tags, attributes and fenced code are left alone; only text content is touched:

from polytypo.html import transform

transform('<a title="test... wait">Wait... she said "go on."</a>', locale="en-US")
# <a title="test... wait">Wait… she said “go on.”</a>

polytypo.text, polytypo.html and polytypo.markdown each exclude the parser dependency the other modes don't need (importing polytypo.text never imports html.parser-based span extraction or tree-sitter). The aggregate polytypo module supports every mode via a mode keyword, defaulting to "text". locale has no default anywhere and must always be passed explicitly — there is no silent fallback to English.

import polytypo

polytypo.transform("...", locale="fr", mode="markdown", dialect="commonmark")

Supported dialects

markdown mode requires a dialect keyword, exactly as the spec requires (no default, detection is forbidden). This runtime supports dialect="commonmark" (CommonMark plus GFM — tables, strikethrough, task lists, autolink literals). dialect="mdx" is a real dialect the spec names, but this runtime has no MDX/JSX parser for it and raises POLYTYPO_INVALID_DIALECT immediately rather than silently mishandling it — a narrower, honest conformance claim, not a port defect.

Licence

MIT. See LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polytypo-1.0.0.tar.gz (246.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polytypo-1.0.0-py3-none-any.whl (90.6 kB view details)

Uploaded Python 3

File details

Details for the file polytypo-1.0.0.tar.gz.

File metadata

  • Download URL: polytypo-1.0.0.tar.gz
  • Upload date:
  • Size: 246.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for polytypo-1.0.0.tar.gz
Algorithm Hash digest
SHA256 aaed31f5053c056a6b51718fdc9c112743d1430855d94259d54b96dd5caa4944
MD5 c07add335a8ca26370e2d7d31940d9e7
BLAKE2b-256 11c8ee4b279efb04a452c3ef8f3a015fe5f71cf93716b6d4ce90b9b435cf4f74

See more details on using hashes here.

Provenance

The following attestation bundles were made for polytypo-1.0.0.tar.gz:

Publisher: release.yml on polytypo/polytypo-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file polytypo-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: polytypo-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 90.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for polytypo-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 47f2fc78f400cde0a8bd5a633aa4244edb12d471802df7fe593d178c53c90724
MD5 3e242da2d1e7f0a7803f3f7fa1c1a411
BLAKE2b-256 711fe5d0ded7fb32a41c48b565a5ea44bb7ce17a9362e8825dbffaad9041e8fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for polytypo-1.0.0-py3-none-any.whl:

Publisher: release.yml on polytypo/polytypo-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.0.1

2 files

This release

1.0.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page