Mastodon.py¶
Usage¶
Register your app! This only needs to be done once (per server, or when distributing rather than hosting an application, most likely per device and server). Uncomment the code and substitute in your information:
from mastodon import Mastodon
'''
Mastodon.create_app(
'pytooterapp',
api_base_url = 'https://mastodon.social',
to_file = 'pytooter_clientcred.secret'
)
'''
Then, log in. This can be done every time your application starts (e.g. when writing a simple bot), or you can use the persisted information:
from mastodon import Mastodon
mastodon = Mastodon(client_id = 'pytooter_clientcred.secret',)
mastodon.log_in(
'my_login_email@example.com',
'incrediblygoodpassword',
to_file = 'pytooter_usercred.secret'
)
Note that this won’t work when using 2FA - you’ll have to use OAuth, in that case. To post, create an actual API instance:
from mastodon import Mastodon
mastodon = Mastodon(access_token = 'pytooter_usercred.secret')
mastodon.toot('Tooting from Python using #mastodonpy !')
Introduction¶
Mastodon is an ActivityPub-based Twitter-like federated social network node. It has an API that allows you to interact with its every aspect. This is a simple Python wrapper for that API, provided as a single Python module.
Mastodon.py aims to implement the complete public Mastodon API. As of this time, it is feature complete for Mastodon version 3.5.5. The Mastodon compatible API layers of various other pieces of software as well as forks, while not an official target, should also be basically compatible, and Mastodon.py does make some allowances for behaviour that isn’t strictly like that of Mastodon, and attempts to support extensions to the API.
Some usage examples (not neccesarily following app development best practices, but enough to get you started if you learn best by example) can be found at https://github.com/halcy/MastodonpyExamples
Acknowledgements¶
Mastodon.py contains work by a large number of contributors, many of which have put significant work into making it a better library. You can find some information about who helped with which particular feature or fix in the changelog.
- Mastodon.py
- General information
- Return values
- User / account dicts
- Toot / Status dicts
- Status edit dicts
- Mention dicts
- Scheduled status / toot dicts
- Poll dicts
- Conversation dicts
- Hashtag dicts
- Hashtag usage history dicts
- Emoji dicts
- Application dicts
- Relationship dicts
- Filter dicts
- Notification dicts
- Context dicts
- List dicts
- Media dicts
- Card dicts
- Search result dicts
- Instance dicts
- Activity dicts
- Report dicts
- Push subscription dicts
- Push notification dicts
- Preference dicts
- Featured tag dicts
- Read marker dicts
- Announcement dicts
- Familiar follower dicts
- Admin account dicts
- Admin domain block dicts
- Admin measure dicts
- Admin dimension dicts
- Admin retention dicts
- Error handling