Skip to content

Add twitter-bot-python-tweepy materials folder - #1016

Open
realpython-bot wants to merge 1 commit into
masterfrom
maintenance/twitter-bot-python-tweepy-20261206
Open

realpython-bot wants to merge 1 commit into
masterfrom
maintenance/twitter-bot-python-tweepy-20261206

Conversation

@realpython-bot

Copy link
Copy Markdown
Collaborator

Adds the companion code for the full update of How to Make an X (Twitter) Bot in Python With Tweepy, which moves the tutorial to X API v2 via tweepy.Client and to OAuth 2.0 Authorization Code with PKCE (X disabled OAuth 1.0a for new apps on 2026-12-01 and retires it on 2027-01-31).

Contents

  • authorize.py: one-time PKCE authorization with tweepy.OAuth2UserHandler, writes token.json
  • bots/config.py: OAuth2Client (a tweepy.Client subclass that refreshes the two-hour access token before each request and persists the rotated refresh token) and create_client()
  • bots/followfollowers.py, bots/likerepost.py, bots/autoreply.py: the three polling bots
  • Dockerfile, requirements.txt (pinned, tweepy==4.17.0), README.md

Verification

  • Files are byte-identical to the code fences in the update draft (https://realpython.com/pbjt/blog/post/2536/change/).
  • Python 3.15.2 + tweepy 4.17.0: an offline harness drove the real Tweepy client and OAuth2UserHandler against a mocked token endpoint and API v2, covering the PKCE exchange, refresh-token rotation and persistence, a mid-run refresh inside a bot, and one iteration of each bot. No live X API calls (pay-per-use; no credentials).
  • ruff format --check, ruff check (ruff 0.14.1, repo config) and dircheck.py pass; pip install -r requirements.txt resolves on 3.15.2.

Maintenance card: https://trello.com/c/PVAoysST

🤖 Generated with Claude Code

Companion code for the OAuth 2.0 update of the Tweepy bot tutorial:
one-time authorize.py, a token-refreshing config module, and the three
polling bots, pinned to tweepy==4.17.0 on Python 3.15.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant