Skip to main content

En/Decode unicode country flags emoji

Project description

flag

foodemoji on PyPI Python Versions Coverage Status Codacy Badge Maintainability Quality Gate Status

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

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-2.1.0.tar.gz (81.1 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-2.1.0-py3-none-any.whl (25.8 kB view details)

Uploaded Python 3

File details

Details for the file emoji_country_flag-2.1.0.tar.gz.

File metadata

  • Download URL: emoji_country_flag-2.1.0.tar.gz
  • Upload date:
  • Size: 81.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for emoji_country_flag-2.1.0.tar.gz
Algorithm Hash digest
SHA256 3b4df6a9d9961ab7716090689c2e96405baff68e46849ab2704335d904589f2a
MD5 b913fce8e257353fd77191dffa9e9ea7
BLAKE2b-256 b87ecd3aa382cda168be39cc7ca5f4062dff2ab7c91f58376479c589a949dec5

See more details on using hashes here.

Provenance

The following attestation bundles were made for emoji_country_flag-2.1.0.tar.gz:

Publisher: pypipublish.yml on cvzi/flag

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file emoji_country_flag-2.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for emoji_country_flag-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 224b19583210901b950a624ab0b0896cdf0764b36f8bd1463868b15fb8c10f6a
MD5 fd5d10d0ab58e12db4ab9640d6c64dce
BLAKE2b-256 34e62f6c0164453535379e62cc9a7ccc1a864b8f01ff935d567fe471beeb6f84

See more details on using hashes here.

Provenance

The following attestation bundles were made for emoji_country_flag-2.1.0-py3-none-any.whl:

Publisher: pypipublish.yml on cvzi/flag

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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