This is the script I'm using to download tags for my experiments, interfacing with the Danbooru's API. It is a bit slow, but it is to respect the rate limit. It is something you start and then go get a coffee, perhaps a cinnamon bun, and watch an episode of your favorite show while it works in the background. It takes about 45 to 50 minutes with the default delay.
If you use the default settings, you will end up with about 120mb of JSON-files when you're done, all separated by category.
This script - in its default state - returns all tags that has at least 1 post and isn't depreciated. But the parameters can be edited and it should be quite self-explanatory how.
The parameters are:
delay, which sets the delay between each fetch. By default it is set to 4 seconds, which is quite long, but also very polite.
limit, how many rows of data to get in one go. The maximum that Danbooru can handle is 1000, and the lowest is 1.
post_threshold, sets how many minimum posts the specific tag needs to make the list. The default (and minimum) is 1, but if you only want tags with at least 100 posts, set it to 100. This will also drastically reduce the output file sizes.
file_prefix, allows you to set the name of your output files. Default is danbooru_tags_category.json, but if you want to, you can change this to be a date, or something else entirely.
categories, this is a list of categories and the complete category list that Danbooru has. You will notice that there is no category 2, for some reason, but that is by design since that category returns nothing. You can comment out rows of categories you don't want by placing a # in front of it.