A lightweight Python application that automatically syncs your Mastodon posts to your X (formerly Twitter) account. Perfect for maintaining presence across both platforms without manual cross-posting.
- π Automatic Syncing: Checks for new Mastodon posts and cross-posts to X
- πΌοΈ Media Support: Handles images attached to Mastodon posts (up to 4 images)
- π·οΈ Hashtag Preservation: Converts Mastodon tags to X hashtags
- π Content Cleaning: Intelligently formats HTML content for X
- β‘ Lightweight: Simple Python script with minimal dependencies
- π Self-Hosted: Your data remains under your control
- β° Scheduling Ready: Easy to set up with cron or similar schedulers
Before installing Masto2X, make sure you have:
- Python 3.7 or higher
- A Mastodon account
- An X Developer account (for API access)
- Basic command-line knowledge
-
Clone or download this repository
git clone https://github.com/yourusername/masto2x.git cd masto2x -
Create a virtual environment
python -m venv .masto2x-venv
-
Activate the virtual environment
On Windows:
.masto2x-venv\Scripts\activate
On macOS/Linux:
source .masto2x-venv/bin/activate -
Install required dependencies
pip install tweepy feedparser requests beautifulsoup4
-
Set up X API Access
- Apply for a developer account at developer.twitter.com
- Create a new Project with Read/Write permissions
- Navigate to your Project > Settings > User authentication set up
- Set OAuth 1.0a with Read/Write permissions
- For callback URL, use your Mastodon instance URL
- Generate API keys and access tokens
-
Create
config.json
Create aconfig.jsonfile in the project directory:{ "mastodon_rss": "https://mastodon.social/@yourusername.rss", "api_key": "YOUR_API_KEY", "api_secret": "YOUR_API_SECRET", "access_token": "YOUR_ACCESS_TOKEN", "access_secret": "YOUR_ACCESS_SECRET" } -
Initialize
last_post.json{}
python mastodon_to_x.pySet up a cron job to run the script periodically:
# Run every 15 minutes
*/15 * * * * cd /path/to/masto2x && ./.masto2x-venv/bin/python mastodon_to_x.pymasto2x/
β
ββ .masto2x-venv/ # virtual environment
ββ config.json # store your API keys and settings
ββ mastodon_to_x.py # main script
ββ last_post.json # keeps track of last posted Mastodon toot
API Authentication Errors
- Verify your X API keys have write permissions
- Check that your access tokens are valid
RSS Feed Not Loading
- Ensure your Mastodon RSS URL is correct
- Verify your Mastodon profile is public
Character Limit Issues
- Mastodon allows 500 characters while X limits to 280
- Long posts will be automatically truncated
Media Upload Failures
- Check internet connection for image downloads
- Verify X API media permissions
| Service | Price | Limitations |
|---|---|---|
| dlvr.it | $8.29/month | Unlimited posts |
| CircleBoom | $5.99-$17/month | Free tier: 3 posts/day |
| SocialOomph | $15/month | No RSS in free tier |
| Hootsuite RSS AutoPublisher | $5.99/month | App subscription required |
If this tool has saved you time, consider supporting its development:
If you find this useful, please give it a star! β It helps others discover the project.
Found a bug or have a feature request? Please open an issue or submit a pull request!
We welcome contributions for:
- Support for more social media platforms (Bluesky, Threads, etc.)
- Improved error handling
- Additional features
This project is licensed under the MIT License - see the LICENSE file for details.
- Mastodon API team for the RSS feed format
- X API for posting capabilities
- Python community for excellent libraries
Disclaimer: This tool is not affiliated with, endorsed by, or connected to Mastodon gGmbH or X Corp. Use at your own risk. API limitations and changes may affect functionality.
Happy Cross-Posting! π
