UnibwSparta/twitterapi
Python implementation of Twitter API v2
SPARTA Twitter API
Welcome to the official GitHub repository for the SPARTA Twitter API, a powerful Python implementation to interact with Twitter's API v2 in a robust and efficient manner.
๐ Features
- Methods for gathering tweets, users and more.
- Asynchronous API calls support.
- Efficient error handling and rate limit management.
- Comprehensive documentation with usage examples.
๐ฆ Installation
We recommend using Poetry for managing the project dependencies. If you don't have Poetry installed, check their official documentation for guidance.
To install the SPARTA Twitter API via Poetry:
poetry add sparta-twitterapior to install it via pip:
pip3 install sparta-twitterapi๐ Quick Start
Here's a simple example to get you started:
import os
os.environ["BEARER_TOKEN"] = "XXXXXXXXXXXXXX"
from sparta.twitterapi.tweets.tweets import get_tweets_by_id
async for tweet_response in get_tweets_by_id(['1511275800758300675', '1546866845180887040']):
print(tweet_response.tweet)For in-depth methods and examples, consult our official documentation.
๐ Development & Contribution
Clone the Repo:
git clone https://github.com/UnibwSparta/twitterapi.git
cd twitterapiInstall Dependencies:
poetry installSubmit Your Changes: Make your improvements and propose a Pull Request!
๐งช Testing
Tests are powered by pytest. Execute tests with:
poetry run pytest tests/โ Support & Feedback
Issues? Feedback? Use the GitHub issue tracker.
๐ License
MIT License. View LICENSE for details.
Create twitter spec
Install datamodel-code-generator
pip3 install datamodel-code-generatorDownload the OpenAPI spec
wget https://api.twitter.com/2/openapi.jsonCreate the model and make the manual changes that are described at the top of models/twitter_v2_spec.py
datamodel-codegen --input openapi.json --input-file-type openapi --output model.py --output-model-type pydantic_v2.BaseModel --collapse-root-models --use-double-quotesProject SPARTA
SPARTA is an interdisciplinary research project at the UniBw M. The Chair of Political Science is responsible for managing the project. The project is funded by dtec.bw (Digitalization and Technology Research Center of the Bundeswehr). dtec.bw is funded by the European Union - NextGenerationEU.