emoji-country-flag
raw JSON → 2.1.0 verified Fri May 01 auth: no python
Encode/decode unicode country flag emoji. Version 2.1.0; supports Python >=3.10. Regularly updated to match ISO 3166-1 changes.
pip install emoji-country-flag Common errors
error AttributeError: module 'emoji_country_flag' has no attribute 'get_flag' ↓
cause Importing from the wrong submodule or using incorrect function name; get_flag may not exist in newer versions.
fix
Use
from emoji_country_flag import get_flag (if version <1.2.0) or use Flag class. error ValueError: Invalid country code: us ↓
cause Country code must be uppercase.
fix
Use uppercase letters, e.g., 'US' instead of 'us'.
Warnings
breaking Version 2.0.0+ requires Python 3.10 or later. Python 3.6-3.9 no longer supported. ↓
fix Upgrade to Python 3.10+ or pin to version 1.x (e.g., pip install 'emoji-country-flag<2')
deprecated The function `get_flag()` is deprecated in favor of `Flag()` class in version 1.2.0+. ↓
fix Use `Flag(code).emoji` instead of `get_flag(code)`.
gotcha Country codes must be ISO 3166-1 alpha-2 uppercase. Lowercase or full country names are not recognized. ↓
fix Always use uppercase two-letter codes (e.g., 'US', 'GB').
Imports
- Flag wrong
from emoji_country_flag.flags import Flagcorrectfrom emoji_country_flag import Flag - get_flag wrong
from emoji_country_flag.flag import get_flagcorrectfrom emoji_country_flag import get_flag - decode_flag wrong
from emoji_country_flag.utils import decode_flagcorrectfrom emoji_country_flag import decode_flag
Quickstart
from emoji_country_flag import Flag
flag = Flag(code='US')
print(flag.emoji) # 🇺🇸
# or using get_flag
from emoji_country_flag import get_flag, decode_flag
emoji = get_flag('US')
print(emoji) # 🇺🇸
code = decode_flag(emoji)
print(code) # US