Skip to content

Instantly share code, notes, and snippets.

@pchalasani
Created November 24, 2024 22:44
Show Gist options
  • Save pchalasani/c52fdf6bd778dc5242eb44deeef3f516 to your computer and use it in GitHub Desktop.
Save pchalasani/c52fdf6bd778dc5242eb44deeef3f516 to your computer and use it in GitHub Desktop.
get bluesky data via python client lib "atproto"
# Simple example of getting bsky data via `atproto` python client
#
# First install: atproto, python-dotenv
# See python client docs here:
# https://github.com/MarshalX/atproto
#
from atproto import Client, IdResolver
import os
from dotenv import load_dotenv
load_dotenv() # take environment variables from .env
env = os.environ
client = Client()
# authenticate with handle = your email addr (or whatever Id you used for bsky).
client.login("[email protected]", env.get("BSKY_APP_PASSWORD"))
# above works if you do NOT have 2FA, but if you do, you must first create a
# bluesky App Password, then use that for `password` above
resolver = IdResolver()
did = resolver.handle.resolve("pchalasani.bsky.social")
# get posts by an author
posts = client.get_author_feed(did, filter="posts_no_replies")
# see here for a list of filters:
# https://docs.bsky.app/docs/api/app-bsky-feed-get-author-feed
# and see the main docs page for all the other things you can do with the client:
# https://docs.bsky.app/
# get timeline -- i.e. the home feed as seen by the above-authenticated user
tl = client.get_timeline()
# examine the first post
tl.feed[0].post.record.text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment