#api #bibliography #library #api-bindings #batch #zotero

zotero-rs

A Rust library for interacting with the Zotero API

8 releases

new 0.2.5 Feb 17, 2025
0.2.4 Feb 13, 2025
0.1.1 Feb 9, 2025

#466 in Web programming

Download history 259/week @ 2025-02-05 680/week @ 2025-02-12

939 downloads per month

MIT license

34KB
816 lines

zotero-rs

A Rust library for interacting with the Zotero API, providing both synchronous and asynchronous versions of the Zotero struct.

Installation

cargo add zotero-rs

Usage

Synchronous Example

Get collections info.

use zotero_rs::Zotero;

fn main() {
    let zotero = Zotero::user_lib("your_user_id", "your_api_key").unwrap();
    let collections = zotero.get_collections(None).unwrap();
    println!("{:?}", collections);
}

Get items in batches. This will allow iterating over all items since a given version. The library will automatically fetch items in batches until no more items are available.

use dotenv::dotenv;
use std::env;
use zotero_rs::Zotero;

fn main() {
    dotenv().ok();
    let api_key = env::var("ZOTERO_API_KEY").expect("ZOTERO_API_KEY not found");
    let lib_id = env::var("ZOTERO_LIBRARY_ID").expect("ZOTERO_LIBRARY_ID not found");
    let zotero = Zotero::group_lib(&lib_id, &api_key).unwrap();
    for item in zotero.get_items_in_batch(0, 100) {
        match item {
            Ok(value) => println!("Item: {:?}", value),
            Err(e) => println!("Error: {:?}", e),
        }
    }
}

Asynchronous Example

use zotero_rs::ZoteroAsync as Zotero;

#[tokio::main]
async fn main() {
    let zotero = Zotero::user_lib("your_user_id", "your_api_key").await.unwrap();
    let collections = zotero.get_collections(None).await.unwrap();
    println!("{:?}", collections);
}

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Dependencies

~7–18MB
~233K SLoC