Skip to main content

:snake: Python Client For Twitter API v2

Twitter APi V2 Twitter APi V2



:rocket: Why Twitter Stream ?

Twitter-Stream.py a python API client for Twitter API v2 now supports FilteredStream, SampledStream, RecentSearch, TweetLookUp, and UserLookUp. It makes it easier to get started with Twitter's New API. Let's see an example of how twitter-stream.py handles SampledStream. Sampled Stream delivers about 1% of Twitter's publicly available tweets in real-time and paints a picture of general sentiments, recent trends, and global events.

# sampled_stream.py

import json
from twitter_stream import SampledStream

class Stream(SampledStream):
    user_fields = ['name', 'location', 'public_metrics']
    expansions = ['author_id']
    tweet_fields = ['created_at']

stream = Stream()
for tweet in stream.connect():
    print(json.dumps(tweet, indent=4))

Is this all you have to do to start streaming? Yes. Are these all the data points available to you? No. Let's discuss line number 5-7. Twitter's Official Documentation lists an elaborate set of query parameters. You can use these queries to get the data you need. We are subclassing SampledStream and carefully constructing clear and eloquent queries in line 5-7. And you can do this for all the query parameters listed in the SampledStream API Reference.

To get more insights into other API endpoints. Visit the examples folder and our documentations twitivity.dev.

Installation

~$ pip3 install twitter-stream.py

Credentials

Store Twitter credentials at ~/.twitter-keys.yaml.

~$ vim ~/.twitter-keys.yaml
keys:
  consumer_key: CONSUMER_KEY
  consumer_secret: CONSUMER_SECRET
  access_token: ACCESS_TOKEN
  access_token_secret: ACCESS_TOKEN_SECRET
  bearer_token: BEARER_TOKEN

Release files for twitter-stream.py 0.8.8

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

Source distribution (sdist)

Source distribution for twitter-stream.py 0.8.8
File Size Uploaded
twitter-stream.py-0.8.8.tar.gz 6.2 kB Details

Release files / twitter-stream.py-0.8.8.tar.gz

Download URL twitter-stream.py-0.8.8.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
12cb2fb436037c6817bf924ebfd628a1669c2d37f3b7ef056b5d5e6eae19303e
BLAKE2b-256 checksum
How to use checksums
c7792fc82e1548c0c520d02b597ad5da782219e552e11c044f6705cf4721903a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

Release history Release notifications | RSS feed

This release

0.8.8 This release

1 release file

0.8.4

1 release file

0.7.3

1 release file

0.7.2

1 release file

0.7.1

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.2.0

1 release file

0.1.1

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