# 🐘 tweepy-mastodon: Mastodon API library with Tweepy interface for Python
[![PyPI Version](https://img.shields.io/pypi/v/tweepy-mastodon?label=PyPI)](https://pypi.org/project/tweepy-mastodon/)
[![Python Versions](https://img.shields.io/pypi/pyversions/tweepy?label=Python)](https://pypi.org/project/tweepy/)
[![Twitter API v1.1](https://img.shields.io/endpoint?url=https%3A%2F%2Ftwbadges.glitch.me%2Fbadges%2Fstandard)](https://developer.twitter.com/en/docs/twitter-api/v1)<!-- [![Twitter API v2](https://img.shields.io/endpoint?url=https%3A%2F%2Ftwbadges.glitch.me%2Fbadges%2Fv2)](https://developer.twitter.com/en/docs/twitter-api) -->
[![Documentation Status](https://readthedocs.org/projects/tweepy-mastodon/badge/?version=latest)](https://tweepy-mastodon.readthedocs.io/en/latest/)
[![Test Status](https://github.com/shuuji3/tweepy-mastodon/workflows/Test/badge.svg)](https://github.com/shuuji3/tweepy-mastodon/actions?query=workflow%3ATest)
[![Coverage Status](https://img.shields.io/coveralls/shuuji3/tweepy-mastodon/mastodon.svg?style=flat)](https://coveralls.io/github/shuuji3/tweepy-mastodon?branch=mastodon)
![cherry blossom photo](https://files.mastodon.social/accounts/headers/000/936/436/original/4d6989a698953e80.jpg)
> ⚠ 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` <br> (previously `tweepy.OAuthHandler` ) | ✅ | |
| `api.verify_credentials()` | ✅ | |
| `api.update_status()` | ✅ | partially implemented |
| `api.destroy_status()` | 📝 TODO | |
| `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()` <br> (a.k.a. follow) | ✅ | |
| `api.destroy_friendship()` <br> (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 | |
| `api.update_status_with_media()` | 📝 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).
```py
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](https://pip.pypa.io/):
pip install tweepy-mastodon
<!--
To use the `tweepy.asynchronous` subpackage, be sure to install with the
`async` extra:
pip install tweepy-mastodon[async]
-->
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
-----
- [tweepy-mastodon Documentation](https://tweepy-mastodon.readthedocs.io/en/latest/) (TODO: update)
- [Tweepy Documentation](https://tweepy.readthedocs.io/en/latest/)
- [halcy/Mastodon.py: Python wrapper for the Mastodon API](https://github.com/halcy/Mastodon.py/)
- [Twitter API Documentation](https://developer.twitter.com/en/docs/twitter-api)
Raw data
{
"_id": null,
"home_page": "https://github.com/shuuji3/tweepy-mastodon",
"name": "tweepy-mastodon",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "mastodon library",
"author": "TAKAHASHI Shuuji",
"author_email": "shuuji3@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/89/21/970e487e5988b82fa0d93e8e31097a6d9bf1b6c4e668f00c3c4d62c7ba4d/tweepy-mastodon-0.5.0.tar.gz",
"platform": null,
"description": "# \ud83d\udc18 tweepy-mastodon: Mastodon API library with Tweepy interface for Python\n\n[![PyPI Version](https://img.shields.io/pypi/v/tweepy-mastodon?label=PyPI)](https://pypi.org/project/tweepy-mastodon/)\n[![Python Versions](https://img.shields.io/pypi/pyversions/tweepy?label=Python)](https://pypi.org/project/tweepy/)\n [![Twitter API v1.1](https://img.shields.io/endpoint?url=https%3A%2F%2Ftwbadges.glitch.me%2Fbadges%2Fstandard)](https://developer.twitter.com/en/docs/twitter-api/v1)<!-- [![Twitter API v2](https://img.shields.io/endpoint?url=https%3A%2F%2Ftwbadges.glitch.me%2Fbadges%2Fv2)](https://developer.twitter.com/en/docs/twitter-api) -->\n[![Documentation Status](https://readthedocs.org/projects/tweepy-mastodon/badge/?version=latest)](https://tweepy-mastodon.readthedocs.io/en/latest/)\n[![Test Status](https://github.com/shuuji3/tweepy-mastodon/workflows/Test/badge.svg)](https://github.com/shuuji3/tweepy-mastodon/actions?query=workflow%3ATest)\n[![Coverage Status](https://img.shields.io/coveralls/shuuji3/tweepy-mastodon/mastodon.svg?style=flat)](https://coveralls.io/github/shuuji3/tweepy-mastodon?branch=mastodon)\n\n![cherry blossom photo](https://files.mastodon.social/accounts/headers/000/936/436/original/4d6989a698953e80.jpg)\n\n> \u26a0 This library is under development! Only partial features are implemented.\n\nAn 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.\n\n## Implemented API\n\n| API | Implemented? | Note |\n| --- | -- | -- |\n| `tweepy.OAuth1UserHandler` <br> (previously `tweepy.OAuthHandler` ) | \u2705 | |\n| `api.verify_credentials()` | \u2705 | |\n| `api.update_status()` | \u2705 | partially implemented |\n| `api.destroy_status()` | \ud83d\udcdd TODO | |\n| `api.home_timeline()` | \u2705 | partially implemented |\n| `api.get_user()` | \u2705 | partially implemented |\n| `api.user_timeline()` | \u2705 | partially implemented |\n| `api.get_status()` | \u2705 | partially implemented |\n| `api.create_favorite()` | \u2705 | partially implemented |\n| `api.destroy_favorite()` | \u2705 | partially implemented |\n| `api.retweet()` | \u2705 | partially implemented |\n| `api.unretweet()` | \u2705 | partially implemented |\n| `api.create_friendship()` <br> (a.k.a. follow) | \u2705 | |\n| `api.destroy_friendship()` <br> (a.k.a. unfollow) | \u2705 | |\n| `api.create_mute()` | \u2705 | |\n| `api.destroy_mute()` | \u2705 | |\n| `api.create_block()` | \u2705 | partially implemented |\n| `api.destroy_block()` | \u2705 | partially implemented |\n| `api.create_list()` | \ud83d\udcdd TODO | |\n| `api.destroy_list()` | \ud83d\udcdd TODO | |\n| `api.update_status_with_media()` | \ud83d\udcdd TODO | |\n| ... | \ud83d\udcdd TODO | |\n| `api.mastodon` | \u2705 | Bonus: You can use any Mastodon.py API \u2728 |\n\n## Example usage\n\nPlease prepare your Mastodon API credentials from the developer settings page (example URL: https://mastodon.social/settings/applications).\n\n```py\nimport datetime\n\nimport tweepy_mastodon as tweepy\n\napi_base_url = 'mastodon.social'\nmastodon_client_id = 'xxxxxxx'\nmastodon_client_secret = 'xxxxxxx'\nmastodon_access_token = 'xxxxxxx'\n\nauth = tweepy.OAuth1UserHandler(\n consumer_key=mastodon_client_id,\n consumer_secret=mastodon_client_secret,\n api_base_url=api_base_url\n)\nauth.set_access_token(mastodon_access_token)\napi = tweepy.API(auth)\n\nme = api.verify_credentials()\n\nassert me.screen_name == 'shuuji3'\nassert me.display_name == 'TAKAHASHI Shuuji \ud83c\udf08\u2728'\nassert me.url == 'https://shuuji3.xyz'\nassert me.profile_background_image_url == 'https://files.mastodon.social/accounts/headers/000/936/436/original/4d6989a698953e80.jpg'\nassert me.created_at == datetime.datetime(2019, 10, 8, 0, 0, tzinfo=datetime.timezone.utc)\nassert me.avatar == 'https://files.mastodon.social/accounts/avatars/000/936/436/original/4854d6cf9e12cb8f.png'\n\nassert me.favorited == False\nassert me.retweeted == False\nassert me.status.source == '<a href=\"https://elk.zone\" rel=\"nofollow\">Elk</a>'\n\nuser = api.get_user(user_id=1)\nassert user.id_str == '1'\nassert user.screen_name == 'Gargron'\nassert user.name == 'Eugen Rochko'\n\nuser = api.get_user(screen_name='npr@mstdn.social')\nassert user.id == 1201325\nassert user.screen_name == 'NPR@mstdn.social'\nassert user.name == 'NPR :verified:'\n\nuser_statuses = api.user_timeline(user_id=1, since_id=0, count=10)\nassert len(user_statuses) == 10\n\nstatus_id = 109813536848077879 # ref. https://mastodon.social/@shuuji3/109813536848077879\nstatus = api.get_status(id=status_id)\nassert status.user.screen_name == 'shuuji3'\nassert 'Hello from tweepy-mastodon!' in status.text\n\nstatus = api.create_favorite(id=status_id)\nassert status.favorited\n```\n\n## Installation\n\nThe easiest way to install the latest version from PyPI is by using\n[pip](https://pip.pypa.io/):\n\n pip install tweepy-mastodon\n\n<!--\nTo use the `tweepy.asynchronous` subpackage, be sure to install with the\n`async` extra:\n\n pip install tweepy-mastodon[async]\n-->\n\nYou can also use Git to clone the repository from GitHub to install the latest\ndevelopment version:\n\n git clone https://github.com/shuuji3/tweepy-mastodon.git\n cd tweepy-mastodon\n pip install .\n\nAlternatively, install directly from the GitHub repository:\n\n pip install git+https://github.com/shuuji3/tweepy-mastodon.git\n\nPython 3.7 - 3.11 are supported.\n\nLinks\n-----\n\n- [tweepy-mastodon Documentation](https://tweepy-mastodon.readthedocs.io/en/latest/) (TODO: update)\n- [Tweepy Documentation](https://tweepy.readthedocs.io/en/latest/)\n- [halcy/Mastodon.py: Python wrapper for the Mastodon API](https://github.com/halcy/Mastodon.py/)\n- [Twitter API Documentation](https://developer.twitter.com/en/docs/twitter-api)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Mastodon library with Tweepy interface for Python",
"version": "0.5.0",
"split_keywords": [
"mastodon",
"library"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "72708ee98089de6e476b80812eaf9ed93d9205d79114a4a7ef183195292ca38c",
"md5": "8de8bf0e6a103d254dc138eb364ef73c",
"sha256": "08df8fbecf99b9bed5a8d6d892b2702c19e391bd01eaff91beec72969746ee08"
},
"downloads": -1,
"filename": "tweepy_mastodon-0.5.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8de8bf0e6a103d254dc138eb364ef73c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 131577,
"upload_time": "2023-02-11T15:40:41",
"upload_time_iso_8601": "2023-02-11T15:40:41.797767Z",
"url": "https://files.pythonhosted.org/packages/72/70/8ee98089de6e476b80812eaf9ed93d9205d79114a4a7ef183195292ca38c/tweepy_mastodon-0.5.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "8921970e487e5988b82fa0d93e8e31097a6d9bf1b6c4e668f00c3c4d62c7ba4d",
"md5": "500035ad6c3c28c46271d8f84e60b42d",
"sha256": "d7e2a578ead8d2ae4e21426fa77eec550f79b4b7031fd29c5e0457ff688ede75"
},
"downloads": -1,
"filename": "tweepy-mastodon-0.5.0.tar.gz",
"has_sig": false,
"md5_digest": "500035ad6c3c28c46271d8f84e60b42d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 116948,
"upload_time": "2023-02-11T15:40:42",
"upload_time_iso_8601": "2023-02-11T15:40:42.993087Z",
"url": "https://files.pythonhosted.org/packages/89/21/970e487e5988b82fa0d93e8e31097a6d9bf1b6c4e668f00c3c4d62c7ba4d/tweepy-mastodon-0.5.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-02-11 15:40:42",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "shuuji3",
"github_project": "tweepy-mastodon",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "tweepy-mastodon"
}