Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

xproapi (Python)

Python client for the Xproapi X (Twitter) data API. Python 3.8+, standard library only.

Install

pip install ../xproapi-code-examples/xproapi-python

Usage

import 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 links

Methods return the API's JSON as dicts. The response keys are listed in the root README.

Options

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
)

Errors

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)

Rate limit

x.rate_limit  # {"limit": 60, "remaining": 57} from the last response

Anything else

x.get("/twitter/user/info", {"userName": "jack"}) calls any GET endpoint with the same auth, retries and errors.

Tests

python -m unittest discover -s tests -v

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages