Skip to main content

twitter-text-python

Documentation Status https://travis-ci.com/swen128/twitter-text-python.svg?branch=master

This is a Python port of the twitter/twitter-text libraries, fully compliant with the official conformance test suite.

Features

This library calculates length of a tweet message according to the documentation from Twitter Developers, so that you can validate the tweet without calling the Web API at all. Although counting characters might seem an easy task, in actual fact it is very complicated, especially when the text contains CJK characters, URLs, or emojis.

The original twitter-text libraries have hit-highlighting and auto-linking features as well, however they are not yet supported by this Python port.

Usage

Installation

$ pip install twitter-text-parser

Examples

See the API reference for more details.

from twitter_text import parse_tweet, extract_emojis_with_indices, extract_urls_with_indices

text = 'english text 日本語 😷 https://example.com'

assert parse_tweet(text).asdict() == {
    'weightedLength': 46,
    'valid': True,
    'permillage': 164,
    'validRangeStart': 0,
    'validRangeEnd': 38,
    'displayRangeStart': 0,
    'displayRangeEnd': 38
}

assert extract_urls_with_indices(text) == [{
    'url': 'https://example.com',
    'indices': [19, 38]
}]

assert extract_emojis_with_indices(text) == [{
    'emoji': '😷',
    'indices': [17, 18]
}]

Metadata

Release files for twitter-text-parser 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for twitter-text-parser 3.0.0
File Size Uploaded
twitter_text_parser-3.0.0.tar.gz 61.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for twitter-text-parser 3.0.0
File Interpreter ABI Platform
twitter_text_parser-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 131.6 kB

Release files / twitter_text_parser-3.0.0.tar.gz

Download URL twitter_text_parser-3.0.0.tar.gz
Size 61.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9426e4fb9393c8c1adfb36ff5d91495ff4524782e85f80748f6ae0bc1efffcda
BLAKE2b-256 checksum
How to use checksums
a6e6332b2a4a8e29c773274099e0fa92fb68d72cd276b0e7f960780bc7898881
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.1 CPython/3.11.3

Release files / twitter_text_parser-3.0.0-py3-none-any.whl

Download URL twitter_text_parser-3.0.0-py3-none-any.whl
Size 69.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b36bd22e147db2234e79c73b021f10c3073e8c54f22b68c31696239b6917cdd3
BLAKE2b-256 checksum
How to use checksums
49107ef9bd301d70cb92a35eee7d38a6378c8b327dc16bdac3089386bd5f3231
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.1 CPython/3.11.3

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 release files

2.0.1

2 release files

2.0.0

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page