Bulk-update post flairs in a subreddit using Python and PRAW. Designed for moderators to easily update existing posts after renaming or reorganizing flair templates.
This repository contains two separate scripts:
list_flairs.py
— Lists all flair templates and their IDs for a subreddit.update_flairs.py
— Updates old flairs to new templates on posts based on a user-provided flair map.
- Features
- Prerequisites
- Installation
- Configuration (
praw.ini
&config.json
) - Listing Flairs
- Updating Post Flairs
- Tips and Safety
- Security
- Lists all link flair templates with their IDs
- Updates old flairs to new templates on existing posts
- Modular design with
main()
functions for clean code and safe importing - Fully configurable via
config.json
- Python 3.8+
- A Reddit account with moderator permissions on the subreddit
- A Reddit API app (script type)
- Clone the repository:
git clone https://github.com/YOUR_USERNAME/reddit-flair-updater.git
cd reddit-flair-updater
- Create a Python virtual environment and activate it:
python -m venv venv
# macOS/Linux
source venv/bin/activate
# Windows
venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
Create a file named praw.ini
in the project folder with the following content:
[default]
client_id=YOUR_CLIENT_ID
client_secret=YOUR_CLIENT_SECRET
username=YOUR_REDDIT_USERNAME
password=YOUR_REDDIT_PASSWORD
user_agent=FlairUpdater by u/YOUR_REDDIT_USERNAME
Replace placeholders:
YOUR_CLIENT_ID
→ from your Reddit script app (string below your app name)YOUR_CLIENT_SECRET
→ from your Reddit script appYOUR_REDDIT_USERNAME
→ your Reddit usernameYOUR_REDDIT_PASSWORD
→ your Reddit passworduser_agent
→ can be any descriptive string, e.g.,"FlairUpdaterBot by u/YourUsername"
Test your credentials:
import praw
reddit = praw.Reddit("default")
print(reddit.user.me()) # Should print your Reddit username
Create a file named config.json
in the project folder with placeholders:
{
"subreddit": "YOUR_SUBREDDIT",
"flair_map": {
"OLD_FLAIR_1": "NEW_FLAIR_TEMPLATE_ID_1",
"OLD_FLAIR_2": "NEW_FLAIR_TEMPLATE_ID_2"
}
}
How to replace placeholders:
YOUR_SUBREDDIT
→ the subreddit you want to update (withoutr/
)OLD_FLAIR_1
,OLD_FLAIR_2
→ the current flair text of posts you want to changeNEW_FLAIR_TEMPLATE_ID_1
, etc. → the flair template IDs for the new flairs (uselist_flairs.py
to get them)
Example after replacing placeholders:
{
"subreddit": "YourSubreddit",
"flair_map": {
"Old_Discussion_Flair": "d373b1ba-5e7e-11f0-870e-7aef208a0ad8",
"Old_Video_Flair": "61220302-bbac-11ef-b53d-22870e36641c"
}
}
- The scripts read
subreddit
andflair_map
directly fromconfig.json
, so no changes to the Python scripts are needed for different subreddits. - Always verify flair IDs using
list_flairs.py
before runningupdate_flairs.py
.
If you don’t know your flair template IDs:
- Run the listing script:
python list_flairs.py
- It reads the
subreddit
fromconfig.json
and prints all link flair templates in the format:
New_Discussion_Flair — d373b1ba-5e7e-11f0-870e-7aef208a0ad8
New_Video_Flair — 61220302-bbac-11ef-b53d-22870e36641c
...
- Copy the IDs into
config.json
to build yourflair_map
.
- Ensure
config.json
contains yoursubreddit
andflair_map
. - Run the update script:
python update_flairs.py
- The script loops through posts and updates old flairs to new templates. Progress is printed to the console.
- Test first: use
limit=10
inupdate_flairs.py
during testing. - API rate limits: the script includes
time.sleep(2)
between updates. - Filtering posts: you can modify the script to target
.new()
,.top()
, or.search()
results. - Dry-run option: modify the script to print matched posts without updating for safety.
- Never commit
praw.ini
orconfig.json
to public repositories, they contain sensitive credentials and flair IDs. .gitignore
is already configured to exclude them.
MIT License – free to use, modify, and distribute.