Skip to main content

A Python library for retrieving tweets from X (f.k.a. Twitter)

Project description

Python Tweet

PyPI - Version PyPI - Python Version PyPI - License Tests

About

pytweet is a simple Python library with one goal: to retrieve tweet information from X for free.

Inspired by React-tweet project.

Key Feature

  • doesn't require an X (formerly known as Twitter) API token

Installation

pip install python-tweet

From source:

make install

or

pip install .

Usage

It may cause conflicts with PyTweet if you are using it in your project.

Async way:

import asyncio
import json

from pytweet import get_tweet


async def main():
    tweet_id = "1803774806980022720"
    data = await get_tweet(tweet_id)
    with open(f"{tweet_id}.json", "w") as f:
        json.dump(data, f, indent=2)


if __name__ == '__main__':
    asyncio.run(main())

Sync way:

import json

from pytweet.sync import get_tweet


def main():
    tweet_id = "1803774806980022720"
    data = get_tweet(tweet_id)
    with open(f"{tweet_id}.json", "w") as f:
        json.dump(data, f, indent=2)


if __name__ == '__main__':
    main()

Pydantic mode:

If you prefer working with object-oriented concepts, you may prefer receiving a class. However, be aware that the returned JSON from syndication is undocumented, so errors or data loss may occur during conversion to a class.

Requires the installation of pydantic.

pip install python-tweet[pydantic]
import asyncio
import json

from pytweet import get_tweet


async def main():
    tweet_id = "1803774806980022720"
    tweet = await get_tweet(tweet_id)
    with open(f"{tweet_id}.json", "w") as f:
        json.dump(tweet.model_dump(mode="json"), f, indent=2)


if __name__ == '__main__':
    asyncio.run(main())

If you are using Pydantic but want to receive a dict, pass the as_dict argument to the get_tweet function.


To-do

  • Return a Tweet class instead a raw dict.

License

python-tweet is released under the MIT License. See the LICENSE file for license information.

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

python_tweet-0.2.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

python_tweet-0.2.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file python_tweet-0.2.0.tar.gz.

File metadata

  • Download URL: python_tweet-0.2.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for python_tweet-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9cc9499b298240055edc26715976437222e97ced3f5ae3b7ea535545ec3ff3a4
MD5 4f82a05c2ed39a77973c20fef91ac91b
BLAKE2b-256 ef76c8c2893e648d8789206af876b3bd2e4edd34cb5377c368969ccbf88fcaa5

See more details on using hashes here.

File details

Details for the file python_tweet-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_tweet-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b1374e230183fcfbfd6de6c48c88c3540a72503b717b38a36798011b0ef2d730
MD5 edb1221d01db087fe1fdaa575d27ed2d
BLAKE2b-256 679ebf3b2f2fb7e332acf449d5dec3ae40549a7915ade1c04b90d5808f18b3ab

See more details on using hashes here.

Supported by

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