Anytype.rs
THIS IS CURRENTLY ALL VIBE CODED AND SHOULD NOT BE TRUSTED. It is not comprehensive and I wouldn't run it on any spaces you care about. It will be improved over time, but for now, it is just a starting point. Created with Claud Sonnet 4 (Preview) in GitHub Copilot.
Anytype API Client and CLI for Rust
A comprehensive Rust library and CLI tool for interacting with your local Anytype application via its API.
Overview
This project provides a Rust interface to interact with Anytype's local API server, which runs on http://localhost:31009. It's a single crate that provides both a library for programmatic access and a command-line interface for direct usage.
Project Structure
This is a single crate with two main modules:
src/api/: Core library for interacting with the Anytype APIsrc/cli/: Command-line interface that uses the API module- Binary: The CLI is exported as the
anytypebinary
Features
Library (anytype_rs)
- JWT Bearer token authentication with challenge-response flow
- Async/await support with tokio
- Full CRUD operations for spaces and objects
- Search functionality
- Template, type, property, and tag management
- Comprehensive error handling
- Type-safe API interactions
CLI Tool (anytype)
- Interactive authentication flow
- List and manage spaces
- Search across objects
- Template and type management
- Property and tag operations
- Comprehensive help system
- Interactive authentication flow
- Space management commands
- Object search capabilities
- Configuration management
- Detailed error reporting
Installation
Prerequisites
- Rust 1.70 or later
- Anytype application running locally (default port: 31009)
Build from Source
The CLI binary will be available at target/release/anytype.
Install from Cargo
This will install the anytype binary to your Cargo bin directory.
Usage
CLI Quick Start
-
Authenticate:
This will start the authentication flow with your local Anytype app. You'll receive a 4-digit code via email or your Anytype app.
-
List your spaces:
-
Search for objects:
-
List templates for a type:
-
Get template details:
-
List tags for a property:
-
List properties in a space:
-
Get help:
Library Usage
Add this to your Cargo.toml:
[]
= "0.1.0"
= { = "1.0", = ["full"] }
Basic usage:
use ;
async
Library Architecture
The anytype-core library is organized into modules that mirror the official Anytype API structure:
anytype-core/src/client/
├── mod.rs # Main client and shared functionality
├── auth.rs # Authentication (challenges, API keys)
├── spaces.rs # Space management
├── objects.rs # Object CRUD operations
├── search.rs # Search functionality
├── properties.rs # Property management (TODO)
├── lists.rs # List operations (TODO)
├── members.rs # Member management (TODO)
├── tags.rs # Tag operations (TODO)
├── types.rs # Type management (TODO)
└── templates.rs # Template operations (TODO)
This modular structure makes it easy to:
- Navigate and maintain the codebase
- Add new API endpoints in logical groups
- Find functionality quickly
- Keep related operations together
API Coverage
Authentication
- ✅ Create challenge (
/v1/auth/challenges) - ✅ Create API key (
/v1/auth/api_keys)
Spaces
- ✅ List spaces (
/v1/spaces) - ✅ Get space details (
/v1/spaces/{id})
Objects
- ✅ List objects (
/v1/spaces/{space_id}/objects) - ✅ Get object details (
/v1/spaces/{space_id}/objects/{object_id}) - ✅ Create objects (
/v1/spaces/{space_id}/objects)
Search
- ✅ Global search (
/v1/search)
Members
- ✅ List members (
/v1/spaces/{space_id}/members) - ✅ Get member details (
/v1/spaces/{space_id}/members/{member_id})
Templates
- ✅ List templates for a type (
/v1/spaces/{space_id}/types/{type_id}/templates) - ✅ Get template details (
/v1/spaces/{space_id}/types/{type_id}/templates/{template_id})
Types
- ✅ List types (
/v1/spaces/{space_id}/types)
Properties
- ✅ List properties (
/v1/spaces/{space_id}/properties)
Tags
- ✅ List tags for a property (
/v1/spaces/{space_id}/properties/{property_id}/tags)
Planned Features
- Property management
- List operations
- Tag operations
- File uploads
- File uploads
Local Development
This client is designed to work with your local Anytype application. Make sure:
- Anytype is running: The Anytype desktop application must be running on your machine
- API Server is active: The local API server should be accessible at
http://localhost:31009 - Authentication: You'll need to authenticate through the challenge-response flow
Checking Your Local Setup
You can verify your local Anytype API is accessible:
# Check if the API server is running
# Or use the CLI to check status
Configuration
The CLI stores configuration in your system's standard config directory:
- Linux:
~/.config/anytype-cli/ - macOS:
~/Library/Application Support/anytype-cli/ - Windows:
%APPDATA%\\anytype-cli\\
API keys are stored securely in this directory.
Development
Running Tests
Enable Debug Logging
# For the CLI
# For library development
RUST_LOG=debug
Project Structure
anytype_rs/
├── Cargo.toml # Workspace configuration
├── anytype-core/ # Core library
│ ├── src/
│ │ ├── lib.rs # Public API
│ │ ├── client.rs # HTTP client implementation
│ │ ├── types.rs # API types and models
│ │ └── error.rs # Error types
│ └── Cargo.toml
├── anytype-cli/ # CLI application
│ ├── src/
│ │ ├── main.rs # CLI entry point
│ │ ├── config.rs # Configuration management
│ │ └── commands/ # Command implementations
│ └── Cargo.toml
└── README.md
Dependencies
Core Dependencies
tokio: Async runtimereqwest: HTTP clientserde: Serializationanyhow: Error handlingtracing: Logging
CLI Dependencies
clap: Command-line parsingdirs: Cross-platform directories
Error Handling
The library provides comprehensive error handling with the AnytypeError enum:
Http: Network and HTTP errorsAuth: Authentication failuresApi: API-specific errorsSerialization: JSON parsing errorsInvalidResponse: Unexpected response format
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Anytype for providing the local API interface
- The Rust community for excellent crates and tools
Note: This project connects to your local Anytype application running on http://localhost:31009. Make sure your Anytype desktop app is running before using this tool.