Expand description
§Anytype Rust API Client
An ergonomic Anytype API client in Rust.
§Features
- supports Anytype API 2025-11-08
- paginated responses and async Streams
- authentication
- integrates with OS Keyring for secure key storage
- http middleware with retry logic and rate limit handling
- client caching (spaces, properties, types)
- nested filter expression builder
- parameter validation
- metrics
- companion cli tool
§Quick Start
use anytype::prelude::*;
// Initialize the client with file-based keystore.
let mut config = ClientConfig::default().app_name("my-app");
config.keystore = Some("file".to_string());
let client = AnytypeClient::with_config(config)?;
if !client.auth_status()?.http.is_authenticated() {
println!("Not authenticated. Please log in.");
}
// List spaces
let spaces: PagedResult<Space> = client.spaces().list().await?;
for space in spaces.iter() {
println!("{}", &space.name);
}
// Get the first space
let space1 = spaces.iter().next().unwrap();
// Create an object
let obj = client.new_object(&space1.id, "page")
.name("My Document")
.body("# Hello World")
.create().await?;
// Search, with filtering and sorting
let results: PagedResult<Object> = client.search_in(&space1.id)
.text("meeting notes")
.types(["page", "note"])
.sort_desc("last_modified_date")
.limit(10)
.execute().await?;
for doc in results.iter() {
println!("{} {}",
doc.get_property_date("last_modified_date").unwrap_or_default(),
doc.name.as_deref().unwrap_or("(unnamed)"));
}
// delete object
client.object(&space1.id, &obj.id).delete().await?;§API Structure
The API uses a fluent builder pattern. Methods on AnytypeClient return
request builders that are configured with chained method calls and then
executed with a terminal method like get(), create(), update(), delete(),
list(), or search().
Applies to all entity types: - Member, Object, Property, Space, Tag, Template, Type, View, (not all CRUD methods are supported for all types, for example, you can’t delete spaces or members).
§Pattern Examples
use anytype::prelude::*;
// Get/Delete single item: client.<entity>(ids...).get/delete()
let obj = client.object("space_id", "obj_id").get().await?;
client.object("space_id", "obj_id").delete().await?;
// Create: client.new_<entity>(required_args).optional_args().create()
let space = client.new_space("My Space")
.description("Description")
.create().await?;
// Update: client.update_<entity>(ids...).fields().update()
let space = client.update_space("space_id")
.name("New Name")
.update().await?;
// List: client.<entities>(ids...).limit().filter().list()
let objects = client.objects("space_id")
.filter(Filter::type_in(vec!["page"]))
.limit(50)
.list().await?;§Notes on API Design
- Similar structs are combined to keep the API surface small and consistent.
Example: Object and ObjectWithBody are unified as
Object { markdown: Option<String>, ... }. - All methods use a consistent builder flow:
things(..),thing(..),new_thing(..),update_thing(..)+ optional setters + terminal verbs likelist(),get(),create(),update(), ordelete(). - Single-field response wrappers are unwrapped so callers get the inner type directly.
- Parameters accept flexible input types via
Into<String>andIntoIteratorwhere useful. - Property and type keys converted to ids if upstream api requires ids.
- Filter/Condition constructors prevent invalid operator combinations, with escape hatches available for advanced use cases.
- Filters default to AND semantics:
.filter()chains into AND, andVec<Filter>.into()yields an ANDFilterExpression. - Enums represent token types like Color and Layout.
- A single HTTP pipeline handles validation, logging, serialization, retries, and rate limits.
- Pagination uses
PaginatedResponse<T>andPagedResult<T>withinto_stream()andcollect_all()helpers. - Naming exceptions to avoid confusion:
get_type()avoids thetypekeyword (object()andspace()keep the simple name).- View-related APIs use
view_*to disambiguate list/collection/query objects (list_views,view_list_objects,view_add_objects,view_remove_object).
Modules§
- auth
- Anytype client authentication
- cache
- Anytype cache
- chat_
stream - Anytype Chat Streaming (gRPC)
- chats
- Anytype Chats (gRPC)
- client
- Anytype Rust API Client
- error
- Errors returned by AnytypeClient
- files
- Anytype Files (gRPC)
- filters
- Filters and sorting
- keystore
- Secure storage for API keys and credentials
- members
- Anytype Members
- objects
- Anytype Objects
- paged
- Paginated and Stream results for list and search methods.
- prelude
- Prelude module - import (nearly) all the things with
use anytype::prelude::*; - properties
- Anytype Properties
- search
- Anytype Search
- spaces
- Anytype Spaces
- tags
- Anytype Tags
- templates
- Anytype Templates
- types
- Anytype Types
- validation
- Validation functions
- verify
- Verification helpers for eventual consistency.
- views
- Anytype Views (for Collections and Queries)
Constants§
- ANYTYPE_
API_ VERSION - API version
- ANYTYPE_
DESKTOP_ URL - API endpoint (localhost desktop client)
- ANYTYPE_
HEADLESS_ URL - API endpoint (CLI/headless server)
Type Aliases§
- Result
- Result type alias using AnytypeError as the default error.