API referenceΒΆ
Everything lives in the emojet module, and all optional parameters are keyword-only.
Functions that take a language parameter accept any language code from LANGUAGES, or "alias" for the English aliases used on GitHub and Slack, like :thumbsup:.
Unsupported language codes raise ValueError.
Emoji names include their delimiters, ":" by default, so a full name looks like :thumbs_up:.
The names and data match those of the emoji package - see History and benchmarks for how the two libraries relate.
Strings must be well-formed Unicode: lone surrogates raise UnicodeEncodeError.
ConversionΒΆ
- emojet.emojize(string, *, language='en', delimiters=(':', ':'), variant=None)ΒΆ
Return string with delimited emoji names replaced by the emoji themselves. Unknown names are left unchanged.
>>> emojet.emojize("Python is fun :thumbs_up:") 'Python is fun π' >>> emojet.emojize("Python is fun :thumbsup:", language="alias") 'Python is fun π' >>> emojet.emojize("Python ist toll :daumen_hoch:", language="de") 'Python ist toll π' >>> emojet.emojize("An :unknown_name: stays") 'An :unknown_name: stays'
delimitersis a tuple of two non-empty strings that surround each name:>>> emojet.emojize("Python is fun __thumbs_up__", delimiters=("__", "__")) 'Python is fun π'
variantmay be"text_type"or"emoji_type"to force a text or emoji presentation, for emoji that support both. It appends the relevant Unicode variation selector, U+FE0E or U+FE0F:>>> emojet.emojize(":red_heart:", variant="text_type") 'β€οΈ' >>> emojet.emojize(":red_heart:", variant="emoji_type") 'β€οΈ'
- emojet.demojize(string, *, language='en', delimiters=(':', ':'))ΒΆ
Return string with emoji replaced by their delimited names. The inverse of
emojize(): emojizing the result returns the original string.>>> emojet.demojize("Python is fun π") 'Python is fun :thumbs_up:' >>> emojet.demojize("Python is fun π", language="de") 'Python is fun :daumen_hoch:' >>> emojet.demojize("Python is fun π", delimiters=("__", "__")) 'Python is fun __thumbs_up__'
Matching is greedy: at each position, the longest known emoji sequence wins. Multi-code-point sequences like family emoji or flags convert to a single name:
>>> emojet.demojize("π¨βπ©βπ§βπ¦") ':family_man_woman_girl_boy:' >>> emojet.demojize("π«π·") ':France:'
- emojet.replace_emoji(string, replace='')ΒΆ
Return string with emoji replaced.
replacemay be a string, or a callable that receives each emoji and returns its replacement.>>> emojet.replace_emoji("Python is fun π") 'Python is fun ' >>> emojet.replace_emoji("Python is fun π", replace="?") 'Python is fun ?' >>> emojet.replace_emoji("Python is fun π", replace=lambda e: f"<{e}>") 'Python is fun <π>'
SearchingΒΆ
- emojet.emoji_list(string)ΒΆ
Return a list of dicts describing each emoji in string, with its start and end indexes.
>>> emojet.emoji_list("Unicode is tricky π―, very tricky π€―") [{'emoji': 'π―', 'match_start': 18, 'match_end': 19}, {'emoji': 'π€―', 'match_start': 33, 'match_end': 34}]
- emojet.distinct_emoji_list(string)ΒΆ
Return the distinct emoji in string, in order of first appearance.
>>> emojet.distinct_emoji_list("Some emoji repeat ππππ") ['π', 'π']
- emojet.emoji_count(string, *, unique=False)ΒΆ
Return the number of emoji in string. Pass
unique=Trueto count each distinct emoji once.>>> emojet.emoji_count("Some emoji repeat ππππ") 4 >>> emojet.emoji_count("Some emoji repeat ππππ", unique=True) 2
- emojet.is_emoji(string)ΒΆ
Return whether string is exactly one emoji.
>>> emojet.is_emoji("π") True >>> emojet.is_emoji("ππ") False
- emojet.purely_emoji(string)ΒΆ
Return whether string consists only of emoji.
>>> emojet.purely_emoji("ππ") True >>> emojet.purely_emoji("Python π") False
LookupΒΆ
- emojet.version(string)ΒΆ
Return the Unicode emoji version of the first emoji or delimited English name in string, as a float. Versions match those in Unicodeβs
emoji-test.txt, where 0.6 and 0.7 mark emoji that predate the versioned releases. RaisesValueErrorif string contains no emoji.>>> emojet.version("π") 0.6 >>> emojet.version("Python π€―") 5.0 >>> emojet.version(":thumbs_up:") 0.6
- emojet.get_emoji_by_name(name, *, language='en')ΒΆ
Return the emoji for an exact delimited name, or
Noneif the name is unknown.>>> emojet.get_emoji_by_name(":thumbs_up:") 'π' >>> emojet.get_emoji_by_name(":daumen_hoch:", language="de") 'π' >>> emojet.get_emoji_by_name(":not_a_real_name:") is None True
- emojet.emoji_status(string)ΒΆ
Return the Unicode qualification status of an emoji:
"component","fully_qualified","minimally_qualified", or"unqualified". RaisesValueErrorif string is not exactly one emoji.>>> emojet.emoji_status("π") 'fully_qualified' >>> emojet.emoji_status("βΊ") 'unqualified' >>> emojet.emoji_status("\N{EMOJI MODIFIER FITZPATRICK TYPE-1-2}") 'component'
DataΒΆ
- emojet.LANGUAGESΒΆ
The supported language codes, as a list of strings.
>>> sorted(emojet.LANGUAGES) ['ar', 'de', 'en', 'es', 'fa', 'fr', 'id', 'it', 'ja', 'ko', 'pt', 'ru', 'tr', 'zh']
- emojet.UNICODE_VERSIONΒΆ
The Unicode version that the emoji data was built from, as a string.
>>> emojet.UNICODE_VERSION '17.0.0'