Skip to main content

A lightweight, zero-authentication Python library for extracting and downloading Twitter/X content.

Project description

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](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](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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

twigram-1.3.1.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

twigram-1.3.1-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file twigram-1.3.1.tar.gz.

File metadata

  • Download URL: twigram-1.3.1.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

Hashes for twigram-1.3.1.tar.gz
Algorithm Hash digest
SHA256 ebee188de714590ee8836026338d0e237a6065b2688cdc9f0d9f3bbddc13986c
MD5 9dc1056b32578c083f9cb81631ae61b6
BLAKE2b-256 1dfd7d445879bf39bb1e370e0b01301c01248e4769c37ccf8f540bf4786b31ff

See more details on using hashes here.

File details

Details for the file twigram-1.3.1-py3-none-any.whl.

File metadata

  • Download URL: twigram-1.3.1-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

Hashes for twigram-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 69ab3387e7120bfd94bd59a4997e2cae2172d95b9dcc57524b5b46d35210b3cf
MD5 fc4431d9def07bab372c91ceaabe063b
BLAKE2b-256 362d7250c6809ca2caf1a03dc61e2a8c17b2b0dbe2e9f3396b3290a2748741ec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page