joeymckenzie / bluesky-php
A PHP client for the Bluesky API.
Requires
- php: ^8.3
- php-http/discovery: ^1.19.2
- php-http/multipart-stream-builder: ^1.3.0
- psr/http-client: ^1.0.3
- psr/http-client-implementation: *
- psr/http-factory-implementation: *
- psr/http-message: ^2.0.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.9
- laravel/pint: ^1.18
- mockery/mockery: ^1.6
- nesbot/carbon: ^3.8
- pestphp/pest: ^v3.5.1
- pestphp/pest-plugin-faker: ^3.0
- pestphp/pest-plugin-type-coverage: ^v3.2.0
- pestphp/pest-plugin-watch: ^v3.0.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^1.12
- phpstan/phpstan-deprecation-rules: ^1.2
- phpstan/phpstan-phpunit: ^1.4
- phpstan/phpstan-strict-rules: ^1.6
- rector/rector: ^1.2
- vlucas/phpdotenv: ^5.6
README
Bluesky PHP
🚧 This package is still in early development, with no major releases at the moment. Use with precaution!
A Bluesky PHP client compatible with your HTTP client of choice. The goal of this project is to provide a simple, easy-to-use PHP HTTP client to interact with Bluesky's API, providing methods for calling both the authenticated and public endpoints.
Current API coverage status
ℹ️ Current progress: 26/165 endpoints covered
The Bluesky API surface is fairly large, and we'll be doing our best to cover as many of the endpoints as possible to provide a friendly client experience. In terms of currently covered resources:
App namespace
- Actor
- Feed
- Graph
- Notification
- Video
Chat namespace
- Actor
- Convo
- moderation
AT Proto
- Admin
- Identity
- Repo
- Server (only session create/refresh done as of now)
- Sync
Tools namespace
- Communication
- Moderation
- Server
- Setters
- Signature
- Team
Bluesky PHP in action
<?php declare(strict_types=1); use Bluesky\Bluesky; require_once __DIR__.'/../vendor/autoload.php'; $dotenv = Dotenv\Dotenv::createImmutable(__DIR__.'/../'); $dotenv->load(); // By default, the client assumes we're going to authenticate as a valid user $username = $_ENV['BLUESKY_USERNAME']; $password = $_ENV['BLUESKY_PASSWORD']; // Construct the client using the default builder with no customizations $client = Bluesky::client($username); // It's also possible to use the public API as well $publicApi = Bluesky::publicClient(); // Next, create a new session for the API $session = $client->newSession($password); var_dump($session); $profile = $client->bsky()->actor()->getProfile($username); var_dump($profile); // Create a post $post = $client->bsky()->feed()->post('This post was brought to you by PHP. Working on yet another Bluesky client for PHP, heavily inspired Nuno\'s OpenAI client. Coming to a Packagist feed near you... 🤠');
Getting started
To get started, install Bluesky from Packagist
$ composer install joeymckenzie/bluesky-php
Within your code, instantiate a new instance of the client:
$client = Bluesky::client('username.bsky.social'); // To use the client, you'll need to create a new session that'll grab some JWTs for authentication $client->newSession('password123'); // Or, build a new client with a session $clientWithSession = Bluesky::clientWithSession('username.bsky.social', 'password123'); // Or, using the public API client that doesn't require authentication $publicClient = Bluesky::publicClient();
Status
The API surface of Bluesky's API is fairly large encompassing some odd 160ish different endpoints. A complete list can be found within the TODO list, containing simple tracking of endpoints that have been implemented and those yet to be implemented.
Testing
To run tests
$ composer run test
Bluesky PHP uses Pest for testing, where each endpoint contains a test that:
- Verifies the call as we expect to Bluesky
- Verifies the properties on the response
You'll find test data within the fixtures folder, container stubs with randomly generated fake data mimicking data received from the API at various endpoints.