Get started with Bluesky API and Python API

One of the first moves Elon Musk made when he took over X, formerly Twitter, was to slap a $42,000-per-month price tag on the enterprise Twitter API, while neutering the capabilities of the API's developer tier.

In contrast to X, Bluesky social network's APIs are completely free to use, and without the need to register as a developer and obtain an API key, it's significantly easier to use the Bluesky APIs.

As the programming community expands across multiple social media platforms, especially Bluesky, here's a quick walkthrough on how to automate posts using the Bluesky API and Python.

Bluesky APIs are different

With the Bluesky APIs and Python SDK, you can connect to Bluesky's Authenticated Transfer Protocol (ATProto) and post a skeet with just the following four lines of code:

from atproto import Client

client = Client()
client.login('cameronmckenzie.com', 'likeandsubscribe')

post = client.send_post('The Bluesky Python SDK is so cool!')

When the code runs, the Python API logs in to the Bluesky network and a new skeet is posted to my timeline.

Bluesky post CID and URI values screenshot.
The URI and CID values from a Bluesky post indicate that your skeet was published successfully.

Bluesky CID and PID values

Currently our application doesn't log any data or provide any local indication of success when it runs. However, the post object returned by the Python API includes both the URI of the new skeet and the unique hash that identified the record itself. Both of those can be easily printed to the console, as so:

print(post.uri)

print(post.cid)

These values also become important if you ever want to reply to an existing Bluesky post.

Posting with the Bluesky Python API screenshot.
This skeet was posted to the network using the Bluesky Python APIs.

Bluesky Python and JavaScript SDKs

If you ever want to automate your social media posts, but Twitter's barriers to entry were too high -- or you just want to move to a different platform altogether -- give the Bluesky Python or JavaScript APIs a try. The Bluesky SDKs make automating your social media posts incredibly easy.

Cameron McKenzie has been a Java EE software engineer for 20 years. His current specialties include Agile development; DevOps; Spring; and container-based technologies such as Docker, Swarm and Kubernetes.

View All Videos