/serde_sheets

Easy reading and writing of `serde` structs to/from Google Sheets

Primary LanguageRust

serde_sheets

Read and write structs directly from google sheets using serde and csv

Implement serde::Serialize to write and serde::Deserialize to read. Easy!

Motivation

Google sheets API is somewhat complex and requires lots of boilerplate. Reading and writing involves using lots of Vec<Vec<String>>. We use csv crate to automate creating these payloads and converting them back into your structs

Usage

serde_sheets expects a google service account json to be available as SERVICE_ACCOUNT_JSON:

$ export SERVICE_ACCOUNT_JSON=$(cat my-service-account.json)

Build Sheets object:

let service_account = service_account_from_env().unwrap();
let mut sheets = get_sheets(service_account, Some("token_cache.json"))
    .await
    .unwrap();

Write objects:

serde_sheets::write_page(&mut sheets, "some-document-id", "some-tab-name", &objects)
    .await
    .unwrap();

Read objects:

let returned: Vec<ExampleObject> = serde_sheets::read_all(&mut sheets, DOCUMENT_ID, TAB_NAME)
    .await
    .unwrap();

Check examples/example.rs for full example.

$ cargo run --example example

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.