Unicode Code Points for Python
Until Python 3.3, the Python runtime could be compiled in one of two Unicode modes:
sys.maxunicode == 0x10FFFF
In this mode, Python’s Unicode strings support the full range of Unicode code points from U+0000 to U+10FFFF. One code point is represented by one string element:
>>> import sys >>> hex(sys.maxunicode) '0x10ffff' >>> len(u'\U0001F40D') 1 >>> [c for c in u'\U0001F40D'] [u'\U0001f40d']
This is the default for Python 2.7 on Linux, as well as universally on Python 3.3 and later across all operating systems.
sys.maxunicode == 0xFFFF
In this mode, Python’s Unicode strings only support the range of Unicode code points from U+0000 to U+FFFF. Any code points from U+10000 through U+10FFFF are represented using a pair of string elements in the UTF-16 encoding:
>>> import sys >>> hex(sys.maxunicode) '0xffff' >>> len(u'\U0001F40D') 2 >>> [c for c in u'\U0001F40D'] [u'\ud83d', u'\udc0d']
This is the default for Python 2.7 on macOS and Windows.
This runtime difference makes writing Python modules to manipulate Unicode strings as series of codepoints quite inconvenient.
The codepoints module
This module solves the problem by exposing APIs to convert Unicode strings to and from lists of code points, regardless of the underlying setting for sys.maxunicode:
>>> hex(sys.maxunicode) '0xffff' >>> snake = tuple(codepoints.from_unicode(u'\U0001F40D')) >>> len(snake) 1 >>> snake[0] 128013 >> hex(snake[0]) '0x1f40d' >>> codepoints.to_unicode(snake) u'\U0001f40d'
Metadata
Release files for codepoints 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| codepoints-1.0.zip | 6.1 kB | Without provenance | Details for codepoints-1.0.zip |
Release files / codepoints-1.0.zip
| Download URL | codepoints-1.0.zip |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
241fa77a03e6f0340cc6d18a875ef4888d10b20aa67f0128d0603482a11e16eb
|
|
BLAKE2b-256 checksum How to use checksums |
8d2849bbe1e81240ca9cfa825c02cee48bac2facd0f8cdf6a5a17f71856a19a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for codepoints 1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.