Skip to main content

Mastodon library with Tweepy interface for Python

Project description

🐘 tweepy-mastodon: Mastodon API library with Tweepy interface for Python

PyPI Version Python Versions Twitter API v1.1 Documentation Status Test Status Coverage Status

cherry blossom photo

⚠ This library is under development! Only partial features are implemented.

An attempt to provide Mastodon API library with Tweepy-like interface, to help developers to migrate their good bot/service built with Tweepy to Mastodon easily.

Implemented API

API Implemented? Note
tweepy.OAuth1UserHandler
(previously tweepy.OAuthHandler )
api.verify_credentials()
api.update_status() partially implemented
api.media_upload() partially implemented / video not supported
api.destroy_status() partially implemented
api.home_timeline() partially implemented
api.get_user() partially implemented
api.user_timeline() partially implemented
api.get_status() partially implemented
api.create_favorite() partially implemented
api.destroy_favorite() partially implemented
api.retweet() partially implemented
api.unretweet() partially implemented
api.create_friendship()
(a.k.a. follow)
api.destroy_friendship()
(a.k.a. unfollow)
api.create_mute()
api.destroy_mute()
api.create_block() partially implemented
api.destroy_block() partially implemented
api.create_list() 📝 TODO
api.destroy_list() 📝 TODO
... 📝 TODO
api.mastodon Bonus: You can use any Mastodon.py API ✨

Example usage

Please prepare your Mastodon API credentials from the developer settings page (example URL: https://mastodon.social/settings/applications).

import datetime

import tweepy_mastodon as tweepy

api_base_url = 'mastodon.social'
mastodon_client_id = 'xxxxxxx'
mastodon_client_secret = 'xxxxxxx'
mastodon_access_token = 'xxxxxxx'

auth = tweepy.OAuth1UserHandler(
    consumer_key=mastodon_client_id,
    consumer_secret=mastodon_client_secret,
    api_base_url=api_base_url
)
auth.set_access_token(mastodon_access_token)
api = tweepy.API(auth)

me = api.verify_credentials()

assert me.screen_name == 'shuuji3'
assert me.display_name == 'TAKAHASHI Shuuji 🌈✨'
assert me.url == 'https://shuuji3.xyz'
assert me.profile_background_image_url == 'https://files.mastodon.social/accounts/headers/000/936/436/original/4d6989a698953e80.jpg'
assert me.created_at == datetime.datetime(2019, 10, 8, 0, 0, tzinfo=datetime.timezone.utc)
assert me.avatar == 'https://files.mastodon.social/accounts/avatars/000/936/436/original/4854d6cf9e12cb8f.png'

assert me.favorited == False
assert me.retweeted == False
assert me.status.source == '<a href="https://elk.zone" rel="nofollow">Elk</a>'

user = api.get_user(user_id=1)
assert user.id_str == '1'
assert user.screen_name == 'Gargron'
assert user.name == 'Eugen Rochko'

user = api.get_user(screen_name='npr@mstdn.social')
assert user.id == 1201325
assert user.screen_name == 'NPR@mstdn.social'
assert user.name == 'NPR :verified:'

user_statuses = api.user_timeline(user_id=1, since_id=0, count=10)
assert len(user_statuses) == 10

status_id = 109813536848077879 # ref. https://mastodon.social/@shuuji3/109813536848077879
status = api.get_status(id=status_id)
assert status.user.screen_name == 'shuuji3'
assert 'Hello from tweepy-mastodon!' in status.text

status = api.create_favorite(id=status_id)
assert status.favorited

Installation

The easiest way to install the latest version from PyPI is by using pip:

pip install tweepy-mastodon

You can also use Git to clone the repository from GitHub to install the latest development version:

git clone https://github.com/shuuji3/tweepy-mastodon.git
cd tweepy-mastodon
pip install .

Alternatively, install directly from the GitHub repository:

pip install git+https://github.com/shuuji3/tweepy-mastodon.git

Python 3.7 - 3.11 are supported.

Links

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

tweepy-mastodon-0.6.0.tar.gz (118.6 kB view details)

Uploaded Source

Built Distribution

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

tweepy_mastodon-0.6.0-py3-none-any.whl (133.1 kB view details)

Uploaded Python 3

File details

Details for the file tweepy-mastodon-0.6.0.tar.gz.

File metadata

  • Download URL: tweepy-mastodon-0.6.0.tar.gz
  • Upload date:
  • Size: 118.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for tweepy-mastodon-0.6.0.tar.gz
Algorithm Hash digest
SHA256 7d816a15b2d236728aefcb9a042df0c5dfb4e3428a3afdb5af2a648be7c20c1b
MD5 ef91ba07999b81b1667d09e5b55501c4
BLAKE2b-256 b9c0e8a9e0f10fe6f11e541ff07a23f89122479a8837365a84201b9765029798

See more details on using hashes here.

File details

Details for the file tweepy_mastodon-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tweepy_mastodon-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e4b8a92d0a73a2c000d926aa7f1ba00aaf51461e494b6da59eba58745cda7844
MD5 e989d937f6e45006e540ffd607f1d50c
BLAKE2b-256 f64889958df90dcbb782dca96b016443e9dc2f729deaee0cff9d02da76862d17

See more details on using hashes here.

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