39 releases (20 breaking)

new 0.21.2 May 17, 2024
0.21.0 Apr 18, 2024
0.20.0 Mar 27, 2024
0.15.0 Dec 23, 2023
0.4.0 Jun 30, 2023

#503 in Network programming

Download history 10/week @ 2024-01-19 5/week @ 2024-01-26 22/week @ 2024-02-02 21/week @ 2024-02-09 470/week @ 2024-02-16 305/week @ 2024-02-23 362/week @ 2024-03-01 451/week @ 2024-03-08 268/week @ 2024-03-15 287/week @ 2024-03-22 200/week @ 2024-03-29 74/week @ 2024-04-05 273/week @ 2024-04-12 108/week @ 2024-04-19 22/week @ 2024-04-26 5/week @ 2024-05-03

411 downloads per month
Used in 2 crates

MIT license

540KB
13K SLoC

ATrium API: Rust library for Bluesky's atproto services

Rust

ATrium API is a Rust library that includes the definitions of XRPC requests and their associated input/output model types. These codes are generated from the Lexicon schema on atproto.com.

Usage

Any HTTP client that implements atrium_xrpc::HttpClient can be used to handle XRPC requests. Since atrium_xrpc_client provides several implementations, it is recommended to use one of them that fits your project requirements.

use atrium_api::client::AtpServiceClient;
use atrium_api::com::atproto::server::create_session::Input;
use atrium_xrpc_client::reqwest::ReqwestClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = AtpServiceClient::new(ReqwestClient::new("https://bsky.social"));
    let result = client
        .service
        .com
        .atproto
        .server
        .create_session(Input {
            auth_factor_token: None,
            identifier: "alice@mail.com".into(),
            password: "hunter2".into(),
        })
        .await;
    println!("{:?}", result);
    Ok(())
}

AtpAgent

While AtpServiceClient can be used for simple XRPC calls, it is better to use AtpAgent, which has practical features such as session management.

use atrium_api::agent::{store::MemorySessionStore, AtpAgent};
use atrium_xrpc_client::reqwest::ReqwestClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let agent = AtpAgent::new(
        ReqwestClient::new("https://bsky.social"),
        MemorySessionStore::default(),
    );
    agent.login("alice@mail.com", "hunter2").await?;
    let result = agent
        .api
        .app
        .bsky
        .actor
        .get_profile(atrium_api::app::bsky::actor::get_profile::Parameters {
            actor: "bsky.app".parse()?,
        })
        .await?;
    println!("{:?}", result);
    Ok(())
}

Dependencies

~6–9.5MB
~163K SLoC