Skip to main content

Python wrapper for the Mastodon API

Project description

Python wrapper for the Mastodon ( https://github.com/mastodon/mastodon/ ) API. Feature complete for public API as of Mastodon version 4.5.8 and easy to get started with:

from mastodon import Mastodon

# 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:
'''
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, or you can use the persisted information:
mastodon = Mastodon(client_id = 'pytooter_clientcred.secret',)
print(mastodon.auth_request_url())

# open the URL in the browser and paste the code you get
mastodon.log_in(
    code=input("Enter the OAuth authorization code: "),
    to_file="pytooter_usercred.secret"
)

# To post, create an actual API instance:
mastodon = Mastodon(access_token = 'pytooter_usercred.secret')
mastodon.toot('Tooting from Python using #mastodonpy !')

You can install Mastodon.py via pypi:

pip install Mastodon.py

We currently try to support Python 3.7 and above, and try to at least not break Python 3 versions below that. Python 2 support is no longer a goal.

Full documentation and basic usage examples can be found at https://mastodonpy.readthedocs.io/en/stable/ . Some more extensive examples can be found at https://github.com/halcy/MastodonpyExamples

If you have any questions about using the library or think you have found a bug, please feel free to open an issue, a github discussion thread, or to just directly contact @halcy@icosahedron.website on the Fediverse or .halcy on Discord - we’ll try to respond as quickly as possible.

Citing

If you use Mastodon.py as part of your research, please review and cite the following paper:

Diener et al., (2026). Mastodon.py: A Python library for the Mastodon API. Journal of Open Source Software, 11(120), 8946, https://doi.org/10.21105/joss.08946

Acknowledgements

Mastodon.py contains work by a large amount 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.

https://circleci.com/gh/halcy/Mastodon.py.svg?style=svg https://codecov.io/gh/halcy/Mastodon.py/branch/master/graph/badge.svg

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mastodon_py-2.2.1.tar.gz (11.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mastodon_py-2.2.1-py3-none-any.whl (129.9 kB view details)

Uploaded Python 3

File details

Details for the file mastodon_py-2.2.1.tar.gz.

File metadata

  • Download URL: mastodon_py-2.2.1.tar.gz
  • Upload date:
  • Size: 11.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mastodon_py-2.2.1.tar.gz
Algorithm Hash digest
SHA256 b52c85850272b4ff7a666b87c62432c5059f25c29fb485ffa1f608938744d8a4
MD5 ea4e3c9f1c22e9737b334c74fae77d10
BLAKE2b-256 ba870c676d38a315bf659beb9e22952085825e59e87fece35ad44e0ccd26d799

See more details on using hashes here.

Provenance

The following attestation bundles were made for mastodon_py-2.2.1.tar.gz:

Publisher: publish.yml on halcy/Mastodon.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mastodon_py-2.2.1-py3-none-any.whl.

File metadata

  • Download URL: mastodon_py-2.2.1-py3-none-any.whl
  • Upload date:
  • Size: 129.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mastodon_py-2.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eb2a815ccc0c4b62417c531e07c02414e000c419abd319326843eb6370b772b3
MD5 f9b22eca3dc7fcdc778765755b2a0606
BLAKE2b-256 e60309b2f7a490ff60ee4f8e1a9ea4d34578bc7a288365ce5b3f4f606a9f4e47

See more details on using hashes here.

Provenance

The following attestation bundles were made for mastodon_py-2.2.1-py3-none-any.whl:

Publisher: publish.yml on halcy/Mastodon.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page