A Python library for the BlueSky Social Network API
Project description
bsky-bridge
A Python library for the BlueSky Social Network API.
Features
- Simple authentication with automatic session persistence
- Automatic token refresh and rate limit handling
- Post text with mentions, links, and hashtags (auto-detected)
- Post up to 4 images per post with alt text support
- Automatic image optimization (resize, compress, EXIF stripping)
- Language specification for multilingual posts
- Reply controls (threadgate) - restrict who can reply to your posts
Installation
pip install bsky-bridge
Quick Start
from bsky_bridge import BskySession, post_text
session = BskySession("your_handle.bsky.social", "your_app_password")
post_text(session, "Hello BlueSky!")
Usage
Authentication
Create a session using your BlueSky handle and an App Password (not your main password):
from bsky_bridge import BskySession
session = BskySession("your_handle.bsky.social", "your_app_password")
Sessions are automatically saved to .bsky_sessions/ and reused. To use a custom directory:
session = BskySession("your_handle.bsky.social", "your_app_password", session_dir="/path/to/sessions")
Posting Text
from bsky_bridge import BskySession, post_text
session = BskySession("your_handle.bsky.social", "your_app_password")
# Simple post
post_text(session, "Hello BlueSky!")
# Mentions, links, and hashtags are automatically detected
post_text(session, "Hey @friend.bsky.social check out https://example.com #coding")
Posting a Single Image
from bsky_bridge import BskySession, post_image
session = BskySession("your_handle.bsky.social", "your_app_password")
post_image(
session,
"Check out this photo!",
"/path/to/image.jpg",
alt_text="A beautiful sunset"
)
Posting Multiple Images
Post up to 4 images in a single post:
from bsky_bridge import BskySession, post_images
session = BskySession("your_handle.bsky.social", "your_app_password")
post_images(session, "My photo gallery!", [
{"path": "/path/to/image1.jpg", "alt": "First image"},
{"path": "/path/to/image2.jpg", "alt": "Second image"},
{"path": "/path/to/image3.jpg", "alt": "Third image"},
{"path": "/path/to/image4.jpg", "alt": "Fourth image"},
])
Specifying Languages
Help BlueSky's feed algorithms by specifying post languages:
from bsky_bridge import post_text, post_image
# Multilingual text post
post_text(session, "Bonjour! Hello!", langs=["fr", "en-US"])
# Image post with languages
post_image(
session,
"Belle photo! Beautiful photo!",
"/path/to/image.jpg",
alt_text="Landscape",
langs=["fr", "en-US"]
)
Reply Controls (Threadgate)
Control who can reply to your posts using the reply_to parameter:
from bsky_bridge import post_text
# No one can reply
post_text(session, "This is a statement.", reply_to="nobody")
# Only mentioned users can reply
post_text(session, "Hey @friend.bsky.social what do you think?", reply_to="mentions")
# Only people you follow can reply
post_text(session, "Question for my friends", reply_to="following")
# Only your followers can reply
post_text(session, "Followers only discussion", reply_to="followers")
# Combine multiple rules
post_text(session, "Limited discussion", reply_to=["mentions", "following"])
Available options:
| Option | Description |
|---|---|
None |
Anyone can reply (default) |
"nobody" |
No one can reply |
"mentions" |
Only mentioned users |
"following" |
Only people you follow |
"followers" |
Only your followers |
["option1", "option2"] |
Combine multiple rules |
Works with all post functions (post_text, post_image, post_images).
Making Custom API Calls
Use the session to make authenticated calls to any AT Protocol endpoint:
# GET request
profile = session.api_call(
"app.bsky.actor.getProfile",
method="GET",
params={"actor": "someone.bsky.social"}
)
# POST request
session.api_call(
"com.atproto.repo.createRecord",
method="POST",
json={
"repo": session.did,
"collection": "app.bsky.feed.like",
"record": {
"$type": "app.bsky.feed.like",
"subject": {"uri": "at://...", "cid": "..."},
"createdAt": "2024-01-01T00:00:00Z"
}
}
)
Logging Out
session.logout() # Clears tokens and deletes session file
Image Handling
Images are automatically processed before upload:
| Feature | Details |
|---|---|
| Max size | 1 MB (auto-compressed if larger) |
| Max dimensions | 3840x2160 (auto-resized if larger) |
| EXIF data | Automatically stripped for privacy |
| Aspect ratio | Preserved and sent to API |
| Formats | JPEG, PNG (transparency preserved) |
Rate Limiting
The library automatically handles BlueSky's rate limits:
- Detects HTTP 429 responses
- Reads
Retry-AfterandRateLimit-Resetheaders - Falls back to exponential backoff (1s, 2s, 4s...)
- Retries up to 3 times before raising an error
API Reference
BskySession
BskySession(handle: str, app_password: str, session_dir: str = None)
| Method | Description |
|---|---|
api_call(endpoint, method, json, data, headers, params) |
Make authenticated API call |
get_auth_header() |
Get Authorization header dict |
logout() |
Clear session and delete stored tokens |
Functions
| Function | Description |
|---|---|
post_text(session, text, langs=None, reply_to=None) |
Post text content |
post_image(session, text, image_path, alt_text="", langs=None, reply_to=None) |
Post single image |
post_images(session, text, images, langs=None, reply_to=None) |
Post up to 4 images |
set_threadgate(session, post_uri, reply_to) |
Set reply controls on existing post |
Contributing
Contributions are welcome! Please submit issues for bugs and pull requests for new features.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bsky_bridge-1.1.0.tar.gz.
File metadata
- Download URL: bsky_bridge-1.1.0.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f9feb4114a62a053e47e738c51281082d165e4fc68e785968c8a9592dcd19be
|
|
| MD5 |
efaf1ba6a034706318dd46c419e300e7
|
|
| BLAKE2b-256 |
d94d00931182742177380a6895504025dea6c868dfa94f7fcf2697952c7a0635
|
File details
Details for the file bsky_bridge-1.1.0-py3-none-any.whl.
File metadata
- Download URL: bsky_bridge-1.1.0-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
193201539ab8e04828552969d61a3c8c57ac0ff6450119969da6ed5e57671b68
|
|
| MD5 |
d86e360c54ec7a9ce2a7f5c738ccce69
|
|
| BLAKE2b-256 |
f7349063bd62aa00098e2cdc4f775e33d8c9d6b597895ebb4e72003a92330ac2
|