https://github.com/goshatch/atproto-clojure
🦋 atproto Clojure SDK
https://github.com/goshatch/atproto-clojure
atproto atprotocol bluesky clojure sdk
Last synced: 11 months ago
JSON representation
🦋 atproto Clojure SDK
- Host: GitHub
- URL: https://github.com/goshatch/atproto-clojure
- Owner: goshatch
- Created: 2024-11-22T14:28:42.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-27T17:11:47.000Z (over 1 year ago)
- Last Synced: 2024-11-30T14:26:09.622Z (over 1 year ago)
- Topics: atproto, atprotocol, bluesky, clojure, sdk
- Language: Clojure
- Homepage:
- Size: 158 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# atproto Clojure SDK
⚠️ Work on this SDK has been paused (see [this bsky post](https://bsky.app/profile/gosha.net/post/3lhstloh6s22n)). If anyone would like to fork the project and continue the work, you are very welcome to do so!
## Progress
| Feature | Status |
| ------------ | ------ |
| http client | 🟡 |
| identifiers | 🔴 |
| bsky | 🔴 |
| crypto | 🔴 |
| mst | 🔴 |
| lexicon | 🔴 |
| identity | 🔴 |
| streaming | 🟡 |
| service auth | 🔴 |
| plc | 🔴 |
| oauth server | 🔴 |
## Usage
### HTTP client
The client is using [Martian](https://github.com/oliyh/martian/) under the hood to handle the HTTP endpoints [published](https://github.com/bluesky-social/bsky-docs/tree/main/atproto-openapi-types) by the Bsky team in OpenAPI format
```clojure
(require '[net.gosha.atproto.client :as at])
;; Unauthenticated client
(def session (at/init :base-url "https://public.api.bsky.app"))
;; Authenticated client
(def session (at/init :username "me.bsky.social"
:app-password "SECRET"
:base-url "https://bsky.social"))
;; Bluesky endpoints and their query params can be found here:
;; https://docs.bsky.app/docs/category/http-reference
(let [resp (at/call session :app.bsky.actor.get-profile {:actor "gosha.net"})]
(select-keys (:body @resp) [:handle :displayName :createdAt :followersCount]))
;; => {:handle "gosha.net",
;; :displayName "Gosha ⚡",
;; :createdAt "2023-05-08T19:08:05.781Z",
;; :followersCount 617}
```
### Jetstream
Connect to Bluesky's [Jetstream service](https://docs.bsky.app/blog/jetstream) to get real-time updates of public network data. Jetstream provides a JSON-based alternative to the binary CBOR firehose, making it easier to work with post streams, likes, follows, and other events.
```clojure
(require '[net.gosha.atproto.jetstream :as jetstream]
'[clojure.core.async :as async]
'[examples.jetstream-analysis :as analysis]))
;; Connect with default settings (subscribes to posts)
(def conn (jetstream/connect-jetstream (async/chan 1024)))
;; Print out a single post (with 5 second timeout)
(let [event (async/alt!!
(:events conn) ([v] v)
(async/timeout 5000) :timeout)]
(clojure.pprint/pprint event))
;; Start analyzing the stream
(def analysis (analysis/start-analysis conn))
;; Get current statistics about post rates, sizes, etc
(analysis/get-summary @(:state analysis))
;; Save sample messages for offline analysis
(analysis/collect-samples conn
{:count 10
:filename "samples/my-samples.json"})
;; Cleanup
(analysis/stop-analysis analysis)
(jetstream/disconnect conn)
```
Check out the `examples.jetstream-analysis` namespace for a complete example of stream processing and analysis.
## References
- [Existing SDKs](https://atproto.com/sdks)
- [What goes in to a Bluesky or atproto SDK?](https://github.com/bluesky-social/atproto/discussions/2415)
- [atproto Interop Test Files](https://github.com/bluesky-social/atproto-interop-tests)
## Contribute
Help is very much welcomed!
Before submitting a pull request, please take a look at the [Issues](https://github.com/goshatch/atproto-clojure/issues) to see if the topic you are interested in is already being discussed, and if it is not, please create an Issue to discuss it before making a PR.
For anything else, please reach out on 🦋: [@gosha.net](https://bsky.app/profile/gosha.net)!
## License
MIT, see LICENSE file