Python client for the Xproapi X (Twitter) data API. Python 3.8+, standard library only.
pip install ../xproapi-code-examples/xproapi-pythonimport os
from xproapi import Xproapi
x = Xproapi(os.environ["XPROAPI_KEY"])
user = x.user_info("jack")["data"]
print(f"{user['name']} has {user['followers']:,} followers")
# One page (up to 200)
page = x.followers("jack", page_size=200)
next_page = x.followers("jack", cursor=page["next_cursor"])
# Every page, capped at 5 requests (params use the API's own names)
for follower in x.paginate("followers", {"userName": "jack"}, max_pages=5):
print(follower["userName"])
# Tweets
x.last_tweets(user_name="jack", include_replies=False)
x.advanced_search("from:jack min_faves:100", query_type="Top")
x.tweets_by_ids(["20", "1800000000000000000"])
x.replies("https://x.com/jack/status/20") # ids or linksMethods return the API's JSON as dicts. The response keys are listed in the root README.
Xproapi(
"xp_...",
base_url="https://xproapi.com/api", # default
timeout=30, # seconds per request
max_retries=2, # for 429 / 502 / 503 / network errors; 0 = off
)import time
from xproapi import InsufficientCreditsError, NotFoundError, RateLimitError, XproapiError
try:
x.user_info("someone")
except NotFoundError:
pass # no such user
except InsufficientCreditsError:
pass # top up; nothing was charged
except RateLimitError as error:
time.sleep(error.retry_after)
except XproapiError as error:
print(error.status, error)x.rate_limit # {"limit": 60, "remaining": 57} from the last responsex.get("/twitter/user/info", {"userName": "jack"}) calls any GET endpoint with the same auth, retries and errors.
python -m unittest discover -s tests -v