A lightweight, zero-authentication Python library for extracting and downloading Twitter/X content.
Project description
TwiGram
TwiGram is a lightweight, zero-authentication Python library for extracting and downloading Twitter/X content. It bypasses the need for official API keys by leveraging the Twitter Syndication API to retrieve high-quality media links, clean text, and metadata.
Features
- Multi-Format Extraction: Natively parses standard text, single photos, multi-photo albums, GIFs, and HLS/mp4 videos.
- URL Resolution: Automatically resolves
t.coshort links and sanitizestwitter.comURLs to thex.comformat. - Media Sorting: Parses
.mp4variants and sorts video output arrays by highest resolution automatically. - Network-Efficient Sizing: Calculates human-readable file sizes via HTTP
HEADrequests before initiating full payload downloads.
Requirements
- Python 3.6+
- requests
Installation
pip install TwiGram
Usage
The library exposes a single primary function: download().
Basic Extraction
Pass a valid X (Twitter) status URL to retrieve the payload.
from twigram import download
tweet_data = download("https://x.com/i/status/1481722124855169028")
print(tweet_data)
Media Size Calculation
For applications requiring preemptive storage allocation or user prompts, set show_size=True to execute network-level size calculations.
from twigram import download
tweet_data = download("https://x.com/i/status/1481722124855169028", show_size=True)
if tweet_data.get("status") and tweet_data.get("type_name") == "video":
highest_quality = tweet_data["data"]["video_urls"][0]
print(f"URL: {highest_quality['url']}")
print(f"Resolution: {highest_quality['resolution']}")
print(f"Size: {highest_quality['human_size']}")
Error Handling
Failures (e.g., deleted tweets, private accounts, invalid URLs) return a unified error dictionary:
{
"status": False,
"status_code": 404,
"message": "Tweet is not found. It may have been deleted or made private."
}
License
This project is licensed under the GNU General Public License v3.0 (GPL-3.0) - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file twigram-1.3.2.tar.gz.
File metadata
- Download URL: twigram-1.3.2.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
154e7a3793f04142fdb4f2ed554d459a62f169342beae5a58a400b30ab6f3d7e
|
|
| MD5 |
f541014869d3f6faf4a9b827a4088b0a
|
|
| BLAKE2b-256 |
457d084e53befd882bba5fc3d209a5513a0be9f93217e0f9e362d87e3818d512
|
File details
Details for the file twigram-1.3.2-py3-none-any.whl.
File metadata
- Download URL: twigram-1.3.2-py3-none-any.whl
- Upload date:
- Size: 18.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e13af5f568d57a8921561848a0bce834666a9dcd7478b906c9bb22513c33b78
|
|
| MD5 |
8c7ee35f23bd2e8b97bc55971903acaf
|
|
| BLAKE2b-256 |
12febdd03db108d00b638ccb15759f8b123d792c3aaa37c783e639f3f941fb30
|