skip to navigation
skip to content

emoji-unicode 0.4

Replace unicode emojis by its corresponding image representation. Supports Unicode 9 standard.

# emoji-unicode

[![Build Status](](
[![Coverage Status](](

Replace unicode emojis in a text. Supports *Unicode 10* standard.

## Compatibility

* Python 2.7 ([wide-build](
3.3, 3.4, 3.5 and +3.6 (recommended)

## Install

$ pip install emoji-unicode

## Usage

### Replace


u'Time to ⛽',
lambda e: u'<img src="{filename}.svg" alt="{raw}">'.format(filename=e.code_points, raw=e.unicode)
# Time to <img src="26fd.svg" alt="⛽">

> Note: the [Emoji.code_points]( are normalized.

### Normalize

This function removes optional characters that may appear depending on
the input source (Android, iOS, etc). For example the emoji variation `\\uFE0F`
may (or may not) appear in between a emoji and a skin tone modifier,
making the code points to be different. It should be used
to rename the image files.


# 1f468-2764-1f468

### Replace (advanced)

PATTERN = re.compile(emoji_unicode.RE_PATTERN_TEMPLATE)

def match_handler(m):
e = emoji_unicode.Emoji('emoji'))
return u'<img src="{filename}.svg" alt="{raw}">'.format(

re.sub(PATTERN, match_handler, u'Time to ⛽')
# Time to <img src="26fd.svg" alt="⛽">

## Docs


## Unicode 8 emojis

If your current emoji package supports unicode 8,
which means it supports skin tones and [sequences](
then [normalizing]( the file names
should be enough. But to handle unsupported emojis, for example future sequences,
they should be displayed as multiple glyphs.

Instead of displaying the `woman-kissing-man` glyph you may
display `woman`, `heart`, `kiss`, `man` glyphs.

Here is a example of how this could be handled:

EMOJI_FILES = set(['1f469', '2764', '1f48b', '1f468']) # A set containing the emoji file names

def _render(unicode, code_points):
return u'<img src="{filename}.svg" alt="{alt}">'.format(filename=code_points, alt=unicode)

def render(e):
Return the rendered html for the passed Emoji.
Return the html as multiple glyphs when the
emoji is a sequence not found within the files.
Return the raw unicode when one or more glyphs
are missing.
if e.code_points in EMOJI_FILES:
return _render(e.unicode, e.code_points)

if any(c not in EMOJI_FILES for u, c in e.as_map()):
return e.unicode

return u''.join(_render(u, c) for u, c in e.as_map())

# This assumes `woman-kissing-man.svg` is missing
# <img src="1f469.svg" alt="\U0001f469"><img src="2764.svg" alt="\u2764"> ...

## Dev

The `./emoji_unicode/` file is generated
by parsing the `./emoji_unicode/emoji-data.txt` file,
then putting the output in a in-memory copy of
`./emoji_unicode/`, and lastly
writing the result into ``.

To generate the `` file, run:

make gen

## Tests

make test

## Benchmark

This will run some silly benchmarks.

make bench

Here is the output on my machine:

text len: 10000

re.sub() (raw match)
text len: 10000

Text with no emojis
text len: 10000

## Acknowledgments

Thanks to [iamcal/emoji-data](
for maintaining an incredible source of emojis that allowed me
to make a robust test suite.

## License
File Type Py Version Uploaded on Size
emoji-unicode-0.4.tar.gz (md5) Source 2017-10-10 24KB