Skip to main content

Mastodon.py

Python wrapper for the Mastodon ( https://github.com/mastodon/mastodon/ ) API. Feature complete for public API as of Mastodon version 4.7.3 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

https://joss.theoj.org/papers/10.21105/joss.08946/status.svg

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

Metadata

Release files for Mastodon.py 2.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Mastodon.py 2.4.0
File Size Uploaded Provenance Actions
mastodon_py-2.4.0.tar.gz 12.3 MB With provenance Details for mastodon_py-2.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for Mastodon.py 2.4.0
File Interpreter ABI Platform Actions
mastodon_py-2.4.0-py3-none-any.whl Python 3 none any Details for mastodon_py-2.4.0-py3-none-any.whl

Total release size: 12.4 MB

Release files / mastodon_py-2.4.0.tar.gz

Download URL mastodon_py-2.4.0.tar.gz
Size 12.3 MB
Tags Source
SHA-256 checksum
How to use checksums
f21ccd57cc24e454fc2b60f1ec3ab372110bb409e4f3feb664ca129320f27dbd
BLAKE2b-256 checksum
How to use checksums
ccd03eccaab1cb66d8524d1851712e248d8a86be9e57201fcd80233d57da4106
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / mastodon_py-2.4.0-py3-none-any.whl

Download URL mastodon_py-2.4.0-py3-none-any.whl
Size 161.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b4de75b8d2e36acf741bc81184d4ebf91369f7f12fbc6d88ff8ebd3a389f5bdb
BLAKE2b-256 checksum
How to use checksums
c780cd0ac8973328c10d47070c4400f20fe19f8835c6d2808e1df769d6210026
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Security for Mastodon.py 2.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mastodon_py-2.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.4.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page