Twitter's official API requires an approval process that can take weeks, costs $100+/mo, and limits what you can do on lower tiers.
Here's how to get Twitter data in 3 lines of Python — no developer portal, no approval, no waiting.
Install the SDK
pip install apitwitter
3 Lines. That's it.
from apitwitter import ApiTwitter
client = ApiTwitter("your-api-key")
user = client.get_user("elonmusk")
Output:
{
"id": "44196397",
"userName": "elonmusk",
"name": "Elon Musk",
"followers": 236446942,
"following": 1294,
"statuses_count": 99031,
"is_blue_verified": true,
"profile_image_url": "https://pbs.twimg.com/profile_images/..."
}
No OAuth dance. No token refresh. No 40-page documentation to read first.
Where to get the API key
- Sign up at apitwitter.com
- You get 10,000 free credits instantly
- Go to Dashboard → API Keys → Create Key
That's your "your-api-key" string. It starts with tda_.
More examples
Search tweets
results = client.search("python programming", count=5)
for tweet in results["tweets"]:
print(f"@{tweet['author']['userName']}: {tweet['text'][:100]}")
Get user's tweets
tweets = client.get_user_tweets("elonmusk")
for tweet in tweets["tweets"]:
print(tweet["text"][:120])
print(f" ❤️ {tweet.get('likes', 0)} 🔁 {tweet.get('retweets', 0)}")
print()
Get followers
result = client.get_followers("elonmusk", count=10)
for follower in result["followers"]:
print(f"@{follower['userName']} — {follower['name']}")
Pagination
all_followers = []
cursor = None
while True:
result = client.get_followers("username", count=200, cursor=cursor)
all_followers.extend(result["followers"])
cursor = result.get("next_cursor")
if not cursor:
break
print(f"Total: {len(all_followers)} followers")
Write operations
Read endpoints (above) use a server-side pool — you only need your API key.
For write operations (posting tweets, liking, following, DMs), you need your own Twitter cookies and a proxy:
COOKIE = "ct0=...;auth_token=..."
PROXY = "http://user:pass@host:port"
# Post a tweet
client.create_tweet("Hello from Python!", COOKIE, PROXY)
# Like a tweet
client.like("1234567890", COOKIE, PROXY)
# Follow someone
client.follow("44196397", COOKIE, PROXY)
# Send a DM
client.send_dm("44196397", "Hey!", COOKIE, PROXY)
Error handling
from apitwitter.exceptions import (
AuthenticationError,
InsufficientCreditsError,
RateLimitError,
)
try:
user = client.get_user("someone")
except AuthenticationError:
print("Check your API key")
except InsufficientCreditsError:
print("Time to top up credits")
except RateLimitError as e:
print(f"Slow down — retry in {e.retry_after}s")
What's available
The SDK covers all 56 endpoints:
| Category | Endpoints |
|---|---|
| Users | get by username, get by ID, batch, followers, following, likes, media, replies, blocked, muted |
| Tweets | user tweets, lookup by ID, create, delete, retweet, pin/unpin |
| Search | full search with filters (Top, Latest, People, Photos, Videos) |
| Engagement | like, unlike, follow, unfollow |
| DM | send message, block, unblock |
| Bookmarks | add, remove, list |
| Timeline | For You, Latest |
| Lists | full CRUD, members, subscribers |
| Communities | explore, join, leave, tweets, media |
| Topics | info, follow, unfollow |
Pricing
Pay-per-use. No subscriptions.
- Read operations: $0.14 per 1,000 requests
- User profiles: $0.16 per 1,000 requests
- Write operations: $2.25 per 1,000 requests
- 10,000 free credits on signup
If your server errors out (5xx), credits are auto-refunded.
Also available for JavaScript/TypeScript
npm install @apitwitter/sdk
import { ApiTwitter } from "@apitwitter/sdk";
const client = new ApiTwitter("your-api-key");
const user = await client.getUser("elonmusk");
console.log(user.name, user.followers);
Links
Questions? Drop a comment — happy to help.
Top comments (0)