iTranslated by AI
Posting to Bluesky from Python using AT Protocol
I tried posting to Bluesky using Python with "The At Protocol SDK for Python," which is a Python wrapper for the AT Protocol SDK.
Below are links to previous articles where I tried posting to other decentralized social networks:
Tooting from Python using Mastodon.py
Noting from Python using Misskey.py
Cautions
AT Protocol is a protocol for large-scale decentralized social applications currently being developed by Bluesky.
Since it still has fewer features implemented compared to existing decentralized SNS, destructive specification changes may occur in the future.
Furthermore, it is noted that "The At Protocol SDK for Python" used in this article will also continue development without considering backward compatibility until v1.0.0.
The information in this article is based on v0.0.14, so please read it while referring to the latest documentation.
Environment Setup
Setting up the Python environment
If you have not yet set up a Python development environment, please refer to the following articles to do so.
Installing The At Protocol SDK for Python
Install The At Protocol SDK for Python via pip.
pip install atproto
Implementation
Now, let's proceed with the implementation. Here is the official documentation for The At Protocol SDK for Python.
I will implement it according to the Introduction section described in the official documentation.
From Initialization to Post
Now, let's write the code from initialization to posting.
Specify the URL of the Bluesky instance in the argument of the Client constructor.
This argument is optional; if omitted, the connection destination will be bsky.app.
As of writing this article, authentication methods using access tokens etc. are not provided, so the login method performs authentication using the username and password directly.
After that, you can post any text by calling the send_post method.
from atproto import Client
# Initialization
# If the argument is omitted in the Client constructor, it connects to bsky.app
api = Client()
# To specify a specific connection destination, write as follows:
# api = Client('Bluesky instance XRPC URL (e.g., https://bsky.social/xrpc)')
# Login
api.login('username or email address', 'password')
# Post
api.send_post('Hello World')
That's it. Currently, not only The At Protocol SDK for Python but also the AT Protocol SDK itself is not stable. However, an environment where you can easily try it out is provided, so it is interesting to experiment while looking at the reference.
Discussion