Python bindings for ICU4C
Project description
icupy
Python bindings for ICU4C.
Installation
Prerequisites
Building from source
-
If installing icupy on Windows or if ICU is located in a non-regular place, set the
ICU_ROOT
environment variable to the root of the ICU installation. (e.g.,set ICU_ROOT=C:\icu
) -
Installing from PyPI:
pip install icupy
Alternatively, installing from the git repository:
git clone --recursive https://github.com/miute/icupy.git pip install ./icupy
Changes
- Naming Rules
- Renamed C functions and C++ class methods from mixed case to snake case. (e.g.,
findAndReplace()
→find_and_replace()
) - Renamed C++ enumerators to upper snake case without "k" prefix. (e.g.,
kDateOffset
→DATE_OFFSET
)
- Renamed C functions and C++ class methods from mixed case to snake case. (e.g.,
Examples
-
icu::UnicodeString with error callback
>>> import icupy as icu >>> cnv = icu.ucnv_open("utf-8") >>> action = icu.UCNV_TO_U_CALLBACK_ESCAPE >>> context = icu.ConstVoidPtr(icu.UCNV_ESCAPE_C) >>> icu.ucnv_set_to_u_call_back(cnv, action, context) >>> utf8 = b"\x61\xfe\x62" # Impossible bytes >>> s = icu.UnicodeString(utf8, -1, cnv) >>> str(s) 'a\\xFEb'
-
icu::IDNA (UTS #46)
>>> import icupy as icu >>> uts46 = icu.IDNA.create_uts46_instance(icu.UIDNA_NONTRANSITIONAL_TO_ASCII) >>> dest = icu.UnicodeString() >>> info = icu.IDNAInfo() >>> uts46.name_to_ascii(icu.UnicodeString("faß.ExAmPlE"), dest, info) UnicodeString("xn--fa-hia.example") >>> str(dest) 'xn--fa-hia.example'
-
See also tests directory.
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
icupy-0.8.0.post2.tar.gz
(403.1 kB
view details)
File details
Details for the file icupy-0.8.0.post2.tar.gz
.
File metadata
- Download URL: icupy-0.8.0.post2.tar.gz
- Upload date:
- Size: 403.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 151cdf247c22d75bab175b2d9a270c5c34c451f400f4c42da6c0125cb4d05100 |
|
MD5 | df5e6377538ff586d7a7f3219df6cfaf |
|
BLAKE2b-256 | e112c6118dae90c0a667c4ba6e5484857e4e9265e2d87239f2b7fe90920e5666 |