3 releases (breaking)

new 0.4.0 Feb 13, 2025
0.3.0 Oct 25, 2024
0.1.0 Sep 6, 2024

#1707 in Network programming

Download history 129/week @ 2024-10-23 71/week @ 2024-10-30 98/week @ 2024-11-06 55/week @ 2024-11-13 100/week @ 2024-11-20 80/week @ 2024-11-27 78/week @ 2024-12-04 96/week @ 2024-12-11 52/week @ 2024-12-18 3/week @ 2024-12-25 55/week @ 2025-01-01 90/week @ 2025-01-08 46/week @ 2025-01-15 5/week @ 2025-01-22 32/week @ 2025-01-29 29/week @ 2025-02-05

139 downloads per month
Used in 2 crates

MIT license

105KB
2.5K SLoC

Rust 2K SLoC // 0.0% comments JavaScript 439 SLoC // 0.1% comments

Pubky

Rust implementation implementation of Pubky client.

Quick Start

use pkarr::mainline::Testnet;
use pkarr::Keypair;
use pubky_homeserver::Homeserver;
use pubky::Client;

#[tokio::main]
async fn main () {
  // Mainline Dht testnet and a temporary homeserver for unit testing.
  let testnet = Testnet::new(10);
  let server = Homeserver::run_test(&testnet).await.unwrap();

  let client = Client::test(&testnet);

  // Uncomment the following line instead if you are not just testing.
  // let client Client::new().unwrap(); 

  // Generate a keypair
  let keypair = Keypair::random();

  // Signup to a Homeserver
  let keypair = Keypair::random();
  client.signup(&keypair, &server.public_key()).await.unwrap();

  // Write data.
  let url = format!("pubky://{}/pub/foo.txt", keypair.public_key());
  let url = url.as_str();

  client.put(url, &[0, 1, 2, 3, 4]).await.unwrap();

  // Read using a Public key based link
  let response = client.get(url).await.unwrap().unwrap();

  assert_eq!(response, bytes::Bytes::from(vec![0, 1, 2, 3, 4]));

  // Delete an entry.
  client.delete(url).await.unwrap();

  let response = client.get(url).await.unwrap();

  assert_eq!(response, None);
}

Example code

Check more examples for using the Pubky client.

Dependencies

~11–24MB
~369K SLoC