Skip to main content

Tweet counter

Calculate the size that Twitter will consider a tweet to be.

This is not as advanced as the official twitter-text libraries, but attempts to at least take into account the following:

  • Twitter will convert anything that looks like a URL (with a valid TLD) into a Twitter short link, and count it as taking up exactly 23 characters
  • Twitter counts emoji and any unicode character above U+2037 as each taking up 2 characters

Installation

pip3 install tweet-counter

Python usage

from tweet_counter import count_tweet

print(count_tweet("Otters 👪 otters 𝗼𝘁𝘁𝗲𝗿𝘀 otters otters.com/otters"))
# Output => 60

Command-line usage

$ count-tweet "Otters 👪 otters 𝗼𝘁𝘁𝗲𝗿𝘀 otters otters.com/otters"
60

Metadata

Release files for tweet-counter 0.1.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 tweet-counter 0.1.0
File Size Uploaded
tweet-counter-0.1.0.tar.gz 2.8 kB Details

Release files / tweet-counter-0.1.0.tar.gz

Download URL tweet-counter-0.1.0.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
69913254c01397b97f33eb058b887e991d2b2378cfeb3c0cd41d23c33d572221
BLAKE2b-256 checksum
How to use checksums
7997c7f93f13791aeeef1688a305f80c3bf8688c4690f587f715728eb144b27d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release history Release notifications | RSS feed

This release

0.1.0 This release

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