Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

En/Decode unicode country flags emoji

Project description

flag

foodemoji on PyPI Python Versions Coverage Status Build Status Documentation Status Codacy Badge Maintainability

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 CZ is Czechia: 🇨 + 🇿 = 🇨🇿

So, to encode an ASCII code like :NR: to 🇳🇷, we just need to convert the ASCII N and R to the corresponding regional indicator symbols 🇳 and 🇷.
To reverse it, we translate the regional indicator symbols back to ASCII letters.

Example

    >>> import flag

    >>> flag.flagize("Flag of Israel :IL:")
    'Flag of Israel 🇮🇱'

    >>> flag.dflagize(u"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(u"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/

Documentation

Documentation at https://flag.readthedocs.io

Download files

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

Files for emoji-country-flag, version 1.1.0
Filename, size File type Python version Upload date Hashes
Filename, size emoji_country_flag-1.1.0-py2.py3-none-any.whl (6.5 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size emoji-country-flag-1.1.0.tar.gz (5.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page