Getting Started with Mastodon API in Python

A crash course in using Python and Mastodon’s API to build bots, analyze data, authorize users, respond to notifications and much more

Martin Heinz
9 min readNov 29, 2022
Background Photo by Pawel Czerwinski on Unsplash

With what’s happening in Twitter, many people are considering moving to Mastodon. Like Twitter, Mastodon also has an API that can be used to create many useful application, bots, to analyze data, respond to notification or simply post some statuses.

In this article we will explore all the things Mastodon API can do and how you can use it to build applications with Python.

Setting Up

First of all, we need an API access to Mastodon to build anything. We have two options that are suitable for development. We can either run our own local instance of Mastodon or we can use a bot-friendly public instance.

If you want to run a local instance, then you can use the repository I created, which has all the info you need and will walk you through the setup, all you need is Docker (and docker-compose).

If that’s too much hassle for you, you can use bot-friendly instance such https://botsin.space/, you simply register there as on any other instance, and then you should be able to set up an app.

--

--