Working With Emoji in Python

There’s a package for pretty much everything you can think of in the Python ecosystem, all installable with a simple pip command. So it shouldn’t surprise anyone that there’s a package to work with emoji in Python, too.

You can install the emoji package with:

$ pip3 install emoji

After installation, you can import the module with import emoji. This package allows you to convert Unicode emoji to a string version, and vice versa:

import emoji
result = emoji.emojize('Python is :thumbs_up:')
print(result)
# 'Python is ????'

# You can also reverse this:
result = emoji.demojize('Python is ????')
print(result)
# 'Python is :thumbs_up:'

There are several useful use-cases for working with the Python emoji package. For example, it may come in handy when doing data science on social media. It will also help when you don’t want to store emojis in a database: you can use the package to convert them to a text representation first.

Get certified with our courses

Our premium courses offer a superior user experience with small, easy-to-digest lessons, progress tracking, quizzes to test your knowledge, and practice sessions. Each course will earn you a downloadable course certificate.

Learn more

This article is part of the free Python tutorial. You can head over to the start of the tutorial here. You can navigate this tutorial using the buttons at the top and bottom of the articles. To get an overview of all articles in the tutorial, please use the fold-out menu at the top.

If you liked this article, you might also like to read the following articles:

Leave a Comment

Share to...