Skip to main content

TwiGram

PyPI - Version PyPI - Python Version License

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.co short links and sanitizes twitter.com URLs to the x.com format.
  • Media Sorting: Parses .mp4 variants and sorts video output arrays by highest resolution automatically.
  • Network-Efficient Sizing: Calculates human-readable file sizes via HTTP HEAD requests before initiating full payload downloads.

Requirements

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.

Metadata

Release files for TwiGram 1.3.3

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

Source distribution (sdist)

Source distribution for TwiGram 1.3.3
File Size Uploaded
twigram-1.3.3.tar.gz 17.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for TwiGram 1.3.3
File Interpreter ABI Platform
twigram-1.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 36.1 kB

Release files / twigram-1.3.3.tar.gz

Download URL twigram-1.3.3.tar.gz
Size 17.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e97f9b038462397251acc72eb326c9d84ccb68b2347a2c24b8efe8c38b1c963c
BLAKE2b-256 checksum
How to use checksums
151217d75dbcf56aa53c80baa7efb2de4d04696838fe2e87d2f9337bcbd29e1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / twigram-1.3.3-py3-none-any.whl

Download URL twigram-1.3.3-py3-none-any.whl
Size 18.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a54f6e6e44e6365e4188df6f4f228807bba309a9b6da4c6bb27bedcc239df6f5
BLAKE2b-256 checksum
How to use checksums
e26af57ec9a42f5b932ec344b62403c0b2311f0ec48fb4953a98d9ccfc6fa5ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

1.3.3 This release

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.0

1 release file

1.1.1

1 release file

1.1.0

2 release files

1.0.2

1 release file

1.0.1

2 release files

1.0.0

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