57 releases (23 breaking)

new 0.24.9 Dec 10, 2024
0.24.8 Nov 19, 2024
0.24.7 Oct 28, 2024
0.23.2 Jul 3, 2024
0.4.0 Jun 30, 2023

#166 in Network programming

Download history 34/week @ 2024-08-22 133/week @ 2024-08-29 56/week @ 2024-09-05 528/week @ 2024-09-12 599/week @ 2024-09-19 207/week @ 2024-09-26 56/week @ 2024-10-03 125/week @ 2024-10-10 70/week @ 2024-10-17 228/week @ 2024-10-24 153/week @ 2024-10-31 145/week @ 2024-11-07 484/week @ 2024-11-14 328/week @ 2024-11-21 398/week @ 2024-11-28 376/week @ 2024-12-05

1,605 downloads per month
Used in 9 crates (7 directly)

MIT license

780KB
17K 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_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(
            atrium_api::com::atproto::server::create_session::InputData {
                auth_factor_token: None,
                identifier: "alice@mail.com".into(),
                password: "hunter2".into(),
            }
            .into(),
        )
        .await;
    println!("{:?}", result);
    Ok(())
}

AtpAgent (agent feature)

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
        .com
        .atproto
        .server
        .get_session()
        .await?;
    println!("{:?}", result);
    Ok(())
}

Features

The AtpAgent used in the above example is included in the agent feature. atrium-api enables the agent and bluesky features by default. It is possible to opt-out if not needed.

  • agent: enable the agent module.
  • bluesky: enable bluesky-specific lexicon definitions and XRPC methods.
    • It is also possible to enable only the namespace specified by namespace-*.

Dependencies

~7–14MB
~183K SLoC