Post to Twitter from Python
in 5 Lines of Code
No Tweepy. No OAuth. No X developer account. Just requests.post() and you're live.
7-day free trial • No credit card required
Why Not Tweepy?
To post to Twitter from Python, use the requests library with OpenTweet's REST API. Send a POST request to the /api/v1/posts endpoint with your API key as a Bearer token and the tweet text as JSON. No Tweepy, no OAuth tokens, no X developer account required. Works with any Python version 3.6+.
Tweepy was the standard way to interact with Twitter from Python for years. But in 2026, it requires an X developer account ($200/month or pay-per-use), OAuth 2.0 setup with consumer keys and access tokens, and manual rate limit handling. For most developers who just want to post tweets, that's unnecessary complexity.
OpenTweet's API gives you a single API key, JSON payloads, and built-in scheduling. No developer portal applications, no OAuth token management, no callback URLs.
# The old way (Tweepy + X API)
import tweepy
# Step 1: Get X developer account ($200/month)
# Step 2: Create OAuth tokens
client = tweepy.Client(
consumer_key="...",
consumer_secret="...",
access_token="...",
access_token_secret="..."
)
# Step 3: Post (no scheduling built in)
client.create_tweet(text="Hello world")
# Need your own cron job for scheduling# The new way (OpenTweet API)
import requests
requests.post(
"https://opentweet.io/api/v1/posts",
headers={"Authorization": "Bearer ot_your_api_key"},
json={
"text": "Hello world",
"scheduled_date": "2026-04-23T10:00:00Z"
}
)
# Done. Scheduled. No OAuth. No dev account.Step-by-Step: Python to Twitter
Get Your OpenTweet API Key
Sign up for OpenTweet, connect your X account, and go to the API section in your dashboard. Generate an API key — it starts with ot_ and is the only credential you need. No developer portal, no OAuth tokens, no callback URLs.
Post Your First Tweet
Install the requests library and post a tweet in 5 lines. That's it — no client setup, no token exchange, no configuration files.
import requests
response = requests.post(
"https://opentweet.io/api/v1/posts",
headers={"Authorization": "Bearer ot_your_api_key"},
json={"text": "Hello from Python!"}
)
print(response.status_code) # 201 = successSchedule Tweets for Later
Add a scheduled_date parameter in ISO 8601 format. OpenTweet handles the scheduling — no cron jobs, no background workers on your end.
import requests
requests.post(
"https://opentweet.io/api/v1/posts",
headers={"Authorization": "Bearer ot_your_api_key"},
json={
"text": "Scheduled from Python!",
"scheduled_date": "2026-04-23T10:00:00Z"
}
)Create Threads
Post multi-tweet threads with a single API call. Pass an array of tweet texts and OpenTweet chains them together as a native X thread. Up to 25 tweets per thread.
import requests
requests.post(
"https://opentweet.io/api/v1/posts",
headers={"Authorization": "Bearer ot_your_api_key"},
json={
"tweets": [
"Thread: 5 Python tips you need to know",
"1. Use f-strings instead of .format()",
"2. List comprehensions > for loops for simple transforms",
"3. pathlib > os.path for file operations",
"4. dataclasses for simple data containers",
"5. That's it. Now go ship something."
]
}
)Batch Schedule a Week of Content
Create tweets as drafts first, then schedule up to 50 at once with the batch-schedule endpoint. Plan your whole week in a single script run.
import requests
from datetime import datetime, timedelta
API_KEY = "ot_your_api_key"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}
BASE = "https://opentweet.io/api/v1"
tweets = [
"Monday motivation: ship something today.",
"Tuesday tip: write tests before refactoring.",
"Wednesday wisdom: simplicity beats cleverness.",
"Thursday thought: your users don't care about your tech stack.",
"Friday flex: just deployed v2.0.",
"Saturday side project: building in public.",
"Sunday reflection: consistency > intensity."
]
# Create drafts and collect IDs
post_ids = []
for text in tweets:
r = requests.post(f"{BASE}/posts", headers=HEADERS, json={"text": text})
post_ids.append(r.json()["id"])
# Batch schedule across the week at 9 AM UTC
start = datetime(2026, 4, 27, 9, 0, 0)
schedules = [
{"post_id": pid, "scheduled_date": (start + timedelta(days=i)).isoformat() + "Z"}
for i, pid in enumerate(post_ids)
]
requests.post(f"{BASE}/batch-schedule", headers=HEADERS, json={"schedules": schedules})
print(f"Scheduled {len(schedules)} tweets")List and Manage Tweets
Fetch your scheduled, posted, and draft tweets with GET requests. Filter by status to see what's queued up or what's already gone out.
import requests
HEADERS = {"Authorization": "Bearer ot_your_api_key"}
# Get scheduled tweets
scheduled = requests.get(
"https://opentweet.io/api/v1/posts?status=scheduled",
headers=HEADERS
)
for tweet in scheduled.json()["posts"]:
print(f"{tweet['scheduled_date']} — {tweet['text'][:50]}...")Complete Working Example
Copy this script, replace the API key, run it. You'll have a week of tweets scheduled in under 10 seconds.
"""
Schedule a week of tweets from Python.
Usage: pip install requests && python schedule_week.py
"""
import os
import requests
from datetime import datetime, timedelta
API_KEY = os.environ.get("OPENTWEET_API_KEY", "ot_your_api_key")
BASE_URL = "https://opentweet.io/api/v1"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}
# Your tweets for the week
tweets = [
"Starting the week strong. What are you shipping today?",
"Hot take: the best code is the code you don't write.",
"Reminder: your side project doesn't need a microservices architecture.",
"The hardest part of programming isn't the code. It's deciding what to build.",
"Friday deploy? Living dangerously. I respect it.",
"Weekend project idea: automate something you do manually every week.",
"Sunday reset. Planning next week's content in 10 minutes flat."
]
# Schedule each tweet at 9:00 AM UTC, starting tomorrow
start_date = datetime.utcnow().replace(hour=9, minute=0, second=0) + timedelta(days=1)
for i, text in enumerate(tweets):
scheduled = (start_date + timedelta(days=i)).strftime("%Y-%m-%dT%H:%M:%SZ")
response = requests.post(
f"{BASE_URL}/posts",
headers=HEADERS,
json={"text": text, "scheduled_date": scheduled}
)
if response.status_code == 201:
print(f"Scheduled for {scheduled}: {text[:50]}...")
else:
print(f"Error: {response.status_code} — {response.text}")
print(f"\nDone. {len(tweets)} tweets scheduled.")Pro Tips
Store API Keys in Environment Variables
Use os.environ.get("OPENTWEET_API_KEY") instead of hardcoding keys. Add them to a .env file locally and to your CI/CD secrets for production.
Use Batch Schedule for 50+ Tweets
Create tweets as drafts first, then schedule them all at once with the batch-schedule endpoint. One request instead of fifty.
Add Error Handling
Always check response.status_code == 201 for success. Log failures with response.text for debugging. Wrap API calls in try/except for network errors.
Combine with AI APIs
Use Claude or GPT to generate tweet content, then pipe the output to OpenTweet to publish. Build a content pipeline that runs on autopilot.
Common Mistakes to Avoid
Committing API Keys to Git
Use .env files and add them to .gitignore. Leaked keys can be used to post unauthorized content to your X account. Rotate immediately if exposed.
Using Tweepy Because Old Tutorials Say So
Most Python + Twitter tutorials are outdated. The X API landscape changed significantly — Tweepy now requires expensive developer accounts. Simpler options exist in 2026.
Building Your Own Scheduler
Don't write cron jobs to post tweets at specific times. OpenTweet handles scheduling, retries, and rate limits. Pass scheduled_date and move on.
Frequently Asked Questions
How do I post to Twitter from Python?
Use the requests library with OpenTweet's REST API. Send a POST request to opentweet.io/api/v1/posts with your API key as a Bearer token and the tweet text as JSON. No Tweepy, no OAuth tokens, no X developer account required. Works with any Python version 3.6+.
Do I need Tweepy to post tweets from Python?
No. Tweepy requires an X developer account ($200/month or pay-per-use) and OAuth setup. OpenTweet's REST API works with Python's built-in requests library. Bearer token auth, JSON payloads, built-in scheduling. Tweepy is no longer the easiest option in 2026.
Can I schedule tweets from Python?
Yes. Pass a scheduled_date parameter (ISO 8601 format) when creating a tweet via OpenTweet's API. You can also batch-schedule up to 50 tweets in a single API call. No need to build your own cron-based scheduler.
How much does the OpenTweet Python API cost?
OpenTweet Pro plan costs $5.99/month with up to 10 posts/day and full API access. The Advanced plan ($11.99/month) offers unlimited posts. Both include scheduling, threads, batch operations, and a 7-day free trial.
Can I create Twitter threads from Python?
Yes. Use OpenTweet's create_thread endpoint with an array of tweet texts. The API chains them together as a native X thread. Supports up to 25 tweets per thread, media attachments, and scheduling.
Is there a Python SDK for OpenTweet?
OpenTweet uses a standard REST API that works with any HTTP library. No SDK installation needed. Python's requests library is all you need. The API uses Bearer token auth and returns JSON responses.
Start Posting from Python Today
Get your API key in 2 minutes. Post your first tweet in 5 lines.