This directory contains executable example scripts and projects demonstrating how to interact with AT Protocol and Bluesky using Swift.
| Example | Type | Description | Authentication |
|---|---|---|---|
FirehoseDemo.swift |
Standalone script | Connects to the Bluesky firehose WebSocket and decodes event frames in real time | None required |
SimplePostCLI.swift |
Standalone script | Posts to Bluesky using direct HTTPS XRPC requests via Foundation | App password |
PostCLIDemo/ |
Swift Package CLI | Interactive CLI that uses the Petrel SDK to authenticate, post messages, and inspect profiles | App password |
- Swift 6.0 or later
- macOS 15.0 or later (or Linux with Swift 6.0 toolchain installed)
FirehoseDemo.swift subscribes to the unauthenticated firehose stream (com.atproto.sync.subscribeRepos) and parses incoming commit events.
To run the script:
swift Examples/FirehoseDemo.swiftTo stop the stream, press Ctrl+C.
SimplePostCLI.swift demonstrates direct HTTP XRPC requests against Bluesky servers without depending on the Petrel package. It creates a session via com.atproto.server.createSession and creates a record via com.atproto.repo.createRecord.
To run the script:
swift Examples/SimplePostCLI.swiftWhen prompted:
- Enter your handle (for example,
alice.bsky.social). - Enter an app password generated from your account settings (passwords are entered securely without terminal echo).
- Enter your post text.
PostCLIDemo is a full Swift Package executable that depends on the local Petrel library target. It demonstrates client initialization, password authentication (loginWithPassword), record creation with AppBskyFeedPost, and profile lookup with app.bsky.actor.getProfile.
To build and run PostCLIDemo:
cd Examples/PostCLIDemo
swift run PostCLIDemoThe interactive menu lets you:
- Compose and submit a post to Bluesky.
- View your profile information (display name, description, followers count, follows count, posts count).
- Exit the application.
Posting examples require an app-specific password rather than your primary account credentials.
To create an app password:
- Open your account settings at https://bsky.app/settings/app-passwords.
- Select Add App Password.
- Enter a label (for example,
Petrel CLI Demo). - Copy the generated password token (
xxxx-xxxx-xxxx-xxxx).
App passwords can be revoked at any time from the same settings page without modifying your main account password.
Interactive example scripts prompt for secrets securely on standard input with terminal echo disabled (termios). Do not pass passwords or credentials via command-line arguments, environment variables, or shell scripts where they may be exposed in process listings or shell history.
These command-line demos use app password authentication (AuthMode.legacy). For production user-facing applications, use OAuth with DPoP (AuthMode.publicOAuth or AuthMode.gateway). See Sources/Petrel/Petrel.docc/Authentication.md and GETTING_STARTED.md for details on configuring OAuth flows.