En/Decode unicode country flags emoji
Reason this release was yanked:
Unnecessary print() of debug information in flag() and Flag.flag(), use v2.0.1 instead
Project description
flag
Flag emoji for Python.
Converts flag emoji to ASCII and other way round.
This is based on http://schinckel.net/2015/10/29/unicode-flags-in-python/ by schinckel
How it works
All the flag emoji are actually composed of two unicode letters. These are the 26 regional indicator symbols.
Alone they look like this:
🇦 🇧 🇨 🇩 🇪 🇫 🇬 🇭 🇮 🇯 🇰 🇱 🇲 🇳 🇴 🇵 🇶 🇷 🇸 🇹 🇺 🇻 🇼 🇽 🇾 🇿
If you pair them up according to ISO 3166 some browsers and phones will display a flag.
For example TW is Taiwan: 🇹 + 🇼 = 🇹🇼
So, to encode an ASCII code like :TW:
to 🇹🇼, we just need to convert the ASCII T and W to the corresponding regional indicator symbols 🇹 and 🇼.
To reverse it, we translate the regional indicator symbols back to ASCII letters.
Example
>>> import flag
>>> flag.flag("IL")
'🇮🇱'
>>> flag.flag("GBENG")
'🏴'
>>> flag.flagize("Flag of Israel :IL:")
'Flag of Israel 🇮🇱'
>>> flag.dflagize("Flag of Israel 🇮🇱")
'Flag of Israel :IL:'
>>> flag.flagize("England :gb-eng: is part of the UK :GB:", subregions=True)
'England 🏴 is part of the UK 🇬🇧'
>>> flag.dflagize("England 🏴 is part of the UK 🇬🇧", subregions=True)
'England :gb-eng: is part of the UK :GB:'
>>> my_flags = flag.Flag(only_supported=True, allow_subregions=True)
>>> my_flags.flagize("Convert actual flags like :US: but not unsupported ones like :XX:")
'Convert actual flags like 🇺🇸 but not unsupported ones like :XX:'
Install
pip install emoji-country-flag
See: https://pypi.org/project/emoji-country-flag/
Python 3.10 or higher is required for the latest release. The last release for Python 3.7 to 3.9 was v1.3.2. The last release for Python 2.7, 3.4 and 3.5 was v1.2.4.
Documentation
Documentation at https://flag.readthedocs.io
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
Built Distribution
Hashes for emoji_country_flag-2.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff887dccf17df055ecfe999401e11f037a76f9a1cd51fde98b0b791d64c1b860 |
|
MD5 | 452f43f1561e88111ad10947d36af89d |
|
BLAKE2b-256 | 794dba550e2fb1776e1c07255d49b6e919ee77d45781647af7d0e50b03d93fff |