Typing Stubs for Emoji

2.1.0.3 · active · verified Tue Apr 14

`types-emoji` provides static type checking definitions for the popular `emoji` Python library. It enables type checkers like MyPy to understand the types used in `emoji.emojize()`, `emoji.demojize()`, and other functions, improving code reliability and developer experience. This package is part of the `typeshed` project, which maintains external type annotations for numerous Python libraries and the standard library. `types-emoji` follows the release cadence of `typeshed`, which is often independent of the runtime `emoji` library's release schedule.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic usage of the `emoji` library's core functions: `emojize` to convert text shortcodes into Unicode emojis, `demojize` to reverse this process, `is_emoji` to detect emojis, and how to use language-specific shortcodes or presentation variants.

import emoji
import os

# Example 1: Convert shortcode to emoji
text_with_emoji = emoji.emojize("Python is fun :red_heart:")
print(f"Emojized: {text_with_emoji}")

# Example 2: Convert emoji to shortcode
text_with_shortcode = emoji.demojize("Python is fun ❤️")
print(f"Demojized: {text_with_shortcode}")

# Example 3: Check if a string contains an emoji
has_emoji = emoji.is_emoji("👍")
print(f"Is '👍' an emoji? {has_emoji}")

# Example 4: Using language-specific shortcodes (e.g., Spanish)
spanish_text_emojized = emoji.emojize("Python es :pulgar_hacia_arriba:", language='es')
print(f"Spanish emojized: {spanish_text_emojized}")

spanish_text_demojized = emoji.demojize("Python es 👍", language='es')
print(f"Spanish demojized: {spanish_text_demojized}")

# Example 5: Using variant for emoji presentation (if supported)
heart_emoji_type = emoji.emojize("Python is fun :red_heart:", variant="emoji_type")
print(f"Heart emoji type: {heart_emoji_type}")

view raw JSON →