RepositoryPythonDEGermany
cvzi

cvzi/flag

Flag emoji from country codes for Python 🏳️‍🌈🌍

67stars
7forks
1issues
0views

flag

foodemoji on PyPI Python Versions Coverage Status Codacy Badge

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 Status

Documentation at https://flag.readthedocs.io

Similar Projects

Discover other similar projects and AI models.

RepositoryJavaScript
thekelvinliu/country-code-emoji

convert country codes (ISO 3166-1 alpha-2) to corresponding emoji flags (unicode regional indicator symbols)

142
Jul 19, 2023
RepositoryJava
blongho/worldCountryData

Android library for country flag, currency, and other country information

102
Oct 14, 2026
RepositoryTypeScript
necessarylion/country-list-with-dial-code-and-flag

Country Flag with Dial Number Code

63
Oct 28, 2026
RepositoryPython
donnemartin/system-design-primer

Learn how to design large-scale systems. Prep for the system design interview. Includes Anki flashcards.

379.9k
Sep 15, 2026
RepositoryPython
vinta/awesome-python

The definitive list that answers "I want to do X in Python, which tool should I use?"

338.6k
Nov 28, 2026
RepositoryPython
practical-tutorials/project-based-learning

Curated list of project-based tutorials

290.9k
Nov 30, 2026
RepositoryPython
TheAlgorithms/Python

All Algorithms implemented in Python

226.6k
Nov 13, 2026
RepositoryPython
yt-dlp/yt-dlp

A feature-rich command-line audio/video downloader

212.4k
Dec 2, 2026
RepositoryPython
521xueweihan/HelloGitHub

:octocat: 分享 GitHub 上有趣、入门级的开源项目。Share interesting, entry-level open source projects on GitHub.

192.6k
Nov 27, 2026