5 stable releases

1.0.5 Nov 4, 2024
1.0.4 Sep 22, 2024
1.0.3 Aug 30, 2024
1.0.2 Jul 18, 2024
0.1.9 Feb 20, 2024

#1841 in Database interfaces

Download history 32/week @ 2024-08-16 5/week @ 2024-08-23 183/week @ 2024-08-30 14/week @ 2024-09-06 90/week @ 2024-09-13 260/week @ 2024-09-20 57/week @ 2024-09-27 25/week @ 2024-10-04 46/week @ 2024-10-11 29/week @ 2024-10-18 41/week @ 2024-10-25 174/week @ 2024-11-01 46/week @ 2024-11-08 21/week @ 2024-11-15 21/week @ 2024-11-22 11/week @ 2024-11-29

117 downloads per month

MIT license

115KB
3.5K SLoC

notion-client

Build Notion API Crates.io

Notion API client library for rust. Now, this library supports all endpoints except authentication!

Getting Started

Example for Query a Database


use notion_client::endpoints::{
    databases::query::request::{QueryDatabaseRequest, Sort, SortDirection, Timestamp},
    Client,
};

const NOTION_DB_ID: &str = ""; // ⚠️ Set your DB id which can be accessible from API
const NOTION_TOKEN: &str = ""; // ⚠️ Set your notion token

#[tokio::main]
async fn main() {
    // Initialize client
    let client = Client::new(NOTION_TOKEN.to_string(), None);
    let Ok(client) = client else {
        panic!("error");
    };

    // Set up request parameters
    let request = QueryDatabaseRequest {
        sorts: Some(vec![Sort::Timestamp {
            timestamp: Timestamp::CreatedTime,
            direction: SortDirection::Ascending,
        }]),
        ..Default::default()
    };

    // Send request
    let res = client
        .databases
        .query_a_database(NOTION_DB_ID, request)
        .await;

    // See result
    print!("{:#?}", res);
}

See more examples

TODO

  • support threadsafe
  • add more examples
  • support blocks endpoint
  • support pages endpoint
  • support databases endpoint
  • support users endpoint
  • support comments endpoint
  • support search endpoint
  • support authentication endpoint
  • add test to blocks endpoint
  • add test to pages endpoint
  • add test to databases endpoint
  • add test to users endpoint
  • add test to comments endpoint
  • add test to search endpoint
  • support builder pattern

Contributing

Contributions are always welcome! If you have an idea, it's best to float it by us before working on it to ensure no effort is wasted. If there's already an open issue for it, knock yourself out.

If you have any questions, feel free to use Discussions. Please don't hesitate to ask questions!

Dependencies

~6–22MB
~265K SLoC