Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/twitivity/twitter-stream.py
Python API Client for Twitter API v2
https://github.com/twitivity/twitter-stream.py
api-client python python3 twitter-api twitter-api-v2 twitter-stream
Last synced: about 2 months ago
JSON representation
Python API Client for Twitter API v2
- Host: GitHub
- URL: https://github.com/twitivity/twitter-stream.py
- Owner: twitivity
- License: mit
- Created: 2020-11-23T23:58:53.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-15T18:14:13.000Z (over 1 year ago)
- Last Synced: 2024-05-06T02:02:41.812Z (about 2 months ago)
- Topics: api-client, python, python3, twitter-api, twitter-api-v2, twitter-stream
- Language: Python
- Homepage: https://repo.twitivity.dev/
- Size: 14.2 MB
- Stars: 35
- Watchers: 3
- Forks: 17
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Lists
- awesome-modern-twitter-api - twitter-stream.py
README
:snake: Python Client For Twitter API v2
# :rocket: Why Twitter Stream ?
[Twitter-Stream.py](https://github.com/twitivity/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.```python
# sampled_stream.pyimport json
from twitter_stream import SampledStreamclass 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](https://developer.twitter.com/en/docs/twitter-api/tweets/sampled-stream/api-reference/get-tweets-sample-stream) 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](https://developer.twitter.com/en/docs/twitter-api/tweets/sampled-stream/api-reference/get-tweets-sample-stream).
To get more insights into other API endpoints. Visit the [examples](https://github.com/twitivity/twitter-stream.py/tree/master/examples) folder and our documentations [twitivity.dev](http://twitivity.dev/docs/).
# Installation
```
~$ pip3 install twitter-stream.py
```
## CredentialsStore Twitter credentials at `~/.twitter-keys.yaml`.
```shell
~$ vim ~/.twitter-keys.yaml
``````yaml
keys:
consumer_key: CONSUMER_KEY
consumer_secret: CONSUMER_SECRET
access_token: ACCESS_TOKEN
access_token_secret: ACCESS_TOKEN_SECRET
bearer_token: BEARER_TOKEN```