A Rust SDK for the Notion API.
- Strongly-typed Rust interface for the Notion API
- Async/await support
- Comprehensive type definitions for Notion's data structures
- Error handling with custom error types
- Support for all major Notion API endpoints
Add this to your Cargo.toml
:
[dependencies]
notion-sdk-rs = "0.1.0"
use notion_sdk_rs::{NotionClient, Error};
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Error> {
// Initialize the client with your Notion API token
let client = NotionClient::new("your-notion-api-token")?;
// Get a page
let page = client.get_page("page-id").await?;
println!("Page title: {:?}", page.properties.get("title"));
// Query a database
let query = json!({
"filter": {
"property": "Status",
"select": {
"equals": "Done"
}
}
});
let database = client.query_database("database-id", &query).await?;
println!("Database results: {:?}", database);
// Create a new page
let new_page = json!({
"parent": { "database_id": "database-id" },
"properties": {
"Name": {
"title": [
{
"text": {
"content": "New page"
}
}
]
}
}
});
let created_page = client.create_page(&new_page).await?;
println!("Created page: {:?}", created_page);
Ok(())
}
Check out the examples directory for more usage examples.
For detailed API documentation, run:
cargo doc --open
- Database operations
- Query databases
- Create databases
- Update databases
- Page operations
- Get pages
- Create pages
- Update pages
- Block operations
- Get blocks
- Update blocks
- Delete blocks
- Get block children
- Append block children
- User operations
- List users
- Get user
- Get bot user
- Search
- Search pages and databases
This project uses GitHub Actions for Continuous Integration and Continuous Deployment (CI/CD). The CI/CD pipeline is configured to build, test, and lint the project on every push and pull request to the main
branch.
The GitHub Actions workflow file is located at .github/workflows/ci.yml
. It includes the following steps:
- Checkout repository: Checks out the repository to the GitHub Actions runner.
- Set up Rust: Sets up the Rust toolchain using
actions-rs/toolchain
. - Build: Builds the project using
cargo build
. - Run tests: Runs the tests using
cargo test
. - Run linter: Runs the linter using
cargo clippy
.
You can also run the CI/CD pipeline locally using the following commands:
# Build the project
cargo build
# Run tests
cargo test
# Run linter
cargo clippy -- -D warnings
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.