Skip to main content

En/Decode unicode country flags emoji

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:'

Install

pip install emoji-country-flag

See: https://pypi.org/project/emoji-country-flag/

Python 3.6 or higher is required for the latest release. 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


Download files

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

Source Distribution

emoji-country-flag-1.3.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

emoji_country_flag-1.3.0-py2.py3-none-any.whl (8.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file emoji-country-flag-1.3.0.tar.gz.

File metadata

  • Download URL: emoji-country-flag-1.3.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for emoji-country-flag-1.3.0.tar.gz
Algorithm Hash digest
SHA256 e6a789b221abd44945c0491a7242a46d9fb8f1b100d3839ddb8954e2f4f67929
MD5 2b0e618f96034609bb35e6bcf7807d78
BLAKE2b-256 3e9420f7f07d033064c7c0c86acb27f58314d5dfe75c5585d86b10a905010352

See more details on using hashes here.

File details

Details for the file emoji_country_flag-1.3.0-py2.py3-none-any.whl.

File metadata

  • Download URL: emoji_country_flag-1.3.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for emoji_country_flag-1.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5de298f7454cb6b838bebf7b001523e53c06b7d08de2fe38ab14770a91ea314c
MD5 817e2ba7e70447952ddc40b025dad872
BLAKE2b-256 a2d82a45d735cf9d74f1d74346486fd3c54cf42f13d3dd292334d228a58377ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page