How to delete all old tweets using Python

I don’t like the idea of putting too many “historic” tweets with all the stupid things I tweeted.

So I decided to delete them all.

To this end, I requested from the Twitter settings to save an archive of all my tweets on Twitter.

The archive may take several days to generate. My archive dates back to 2015, even though I started using Twitter in 2007. Maybe I have deleted the past tweets in 2015, but I don't remember.

I got the archive, downloaded it, then unzipped the folder, and ran

python -m venv .venv
source .venv/bin/
python -m pip install delete-tweets

Then, I created environment variables to set the keys of the Twitter application needed to run the entire process, as described above.

export TWITTER_CONSUMER_KEY="your_consumer_key"
export TWITTER_CONSUMER_SECRET="your_consumer_secret"
export TWITTER_ACCESS_TOKEN="your_access_token"
export TWITTER_ACCESS_TOKEN_SECRET="your_access_token_secret"

I used the consumer and access keys of a Twitter app I already had (Twitter now has a process to create new apps, so you must be reviewed and approved to do the same if you don’t have an app already there).

Tip: when you define environment variables in this way, they are recorded by default in the shell history. To avoid that with the Fish shell, run a new shell with fish --private to start the shell in private mode.

Then I ran:

delete-tweets --until 2021-01-01 tweet.js

to delete all the tweets I tweeted before 2021. It took a little while, but it worked.

It took way more to get the archive from Twitter than to delete the tweets, but in the end I got a clean slate.