Skip to main content

A Python package for converting country names into emoji flags

Project description

countryflag

Countryflag is a Python package to convert country names into emoji flags.

PyPI image image

Motivation

I'm new to Python and to programming in general, and I have lots of things to learn, but instead of exercising on "Hello World"-like trivial examples I wanted to create a "real" project from the beginning.
The idea was to build a simple command to get the correspondent emoji flag starting from a country name.

Installation

Countryflag is registered at PyPI. From the command line:

pip install countryflag --upgrade

Source code is also available on GitHub.

Usage

Use within Python

Convert various country names to emojy flags:

import countryflag
countries = ['Germany', 'BE', 'United States of America', 'Japan']
flags = countryflag.getflag(countries)
print(flags)

The default output is a space separated list of emoji flags, one for each country:

🇩🇪 🇧🇪 🇺🇸 🇯🇵

Command line usage

Countryflag can also be used as a command line tool, specifying one or more country name(s) as command line arguments, separated by spaces.

countryflag Germany BE Spain 'United States of America'

Will result in:

🇩🇪 🇧🇪 🇪🇸 🇺🇸

Country names formats

Country names can be expressed in various classification schemes such as ISO-2, ISO-3, ISO-numeric, official name, etc. The input format is determined automatically, based on ISO two letter, ISO three letter, ISO numeric or regular expression matching. Countryflag uses Country Converter (coco) to convert country names to ISO-2 codes and then Emoji-country-flag to render the emoji flags: please see their documentation for further details.

How it works

All the flag emoji are actually composed of two unicode letters. These are the 26 regional indicator symbols:

🇦 🇧 🇨 🇩 🇪 🇫 🇬 🇭 🇮 🇯 🇰 🇱 🇲 🇳 🇴 🇵 🇶 🇷 🇸 🇹 🇺 🇻 🇼 🇽 🇾 🇿

According to ISO 3166, pairing unicode letters of the country code, compatible browsers/phones/terminals will display the correspondent Emoji flag. For example BE is Belgium: 🇧 + 🇪 = 🇧🇪

So, to encode an ASCII code like :BE: to 🇧🇪, Countrycode converts country names to the corresponding regional indicator symbols.

Compatible terminals

Some terminals, such as iTerm2 on Mac Os, support Emoji country flags very well.

However, many others don't, such as Windows Terminal on Windows or Gnome Terminal on Linux: instead of the flag, they will display unicode letters.
For example, invoking countryflag belgium into Windows Terminal will return 🇧 🇪 as output, instead of the emojy country flag 🇧🇪.

At least on Windows, the reason seems to be political/PR-related, as explained here.

Therefore, Countryflag makes much more sense when used on systems/terminals that can properly render Emoji country flags.

Issues, bugs and enhancements

Please use the issue tracker for documenting bugs, proposing enhancements and all other communication related to countryflag.

Acknowledgements

This package depends on:

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

countryflag-0.1.2b3.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

countryflag-0.1.2b3-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file countryflag-0.1.2b3.tar.gz.

File metadata

  • Download URL: countryflag-0.1.2b3.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for countryflag-0.1.2b3.tar.gz
Algorithm Hash digest
SHA256 6dbb403d4c5bdbc8e72217d9934ad451a82d11a0193abf07f13ec1ba6a5c3fd0
MD5 02d622a7dc4675cb5b8d95319b491a8d
BLAKE2b-256 11ad1fcbd5dbf50065f853d6a0059dcc2efcfa57b175ab528cf60410596f3f45

See more details on using hashes here.

File details

Details for the file countryflag-0.1.2b3-py3-none-any.whl.

File metadata

File hashes

Hashes for countryflag-0.1.2b3-py3-none-any.whl
Algorithm Hash digest
SHA256 10e76a4df5d47bbb431b3e1337cc2f5039b7cbb2f338ad865cc4a948be50f88a
MD5 bd46ffabfca8332c782977e2f466388a
BLAKE2b-256 8357984562ee2d1d6b8438acf9954c7a6510ef13d655b90b668f4c7075e12559

See more details on using hashes here.

Supported by

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