colonylib
A Rust library implementing the Colony metadata framework for the Autonomi decentralized network. This library provides the core infrastructure for creating, managing, and searching metadata about files stored on Autonomi using a semantic RDF-based approach.
Note: This is a library for developers. If you're looking for an end-user application to easily upload/download/search files from Autonomi, look at the following applications based on your needs:
- Colony(IN PROGRESS) - Cross platform GUI applications
- Colony Daemon and CLI - Command line interface and background daemon for headless servers
- Mutant - Rust GUI application
Overview
Core Concepts
Pods are the fundamental building blocks of colonylib. A pod consists of:
- An Autonomi pointer that serves as the pod's address
- A scratchpad containing RDF metadata about files and other pods
- Semantic metadata written in RDF in the TriG format using schema.org schema
This architecture enables:
- Rich metadata storage: File types, sizes, names, descriptions, and custom properties
- Knowledge graphs: Pods can reference other pods, creating interconnected networks of metadata
- Semantic search: Query data using SPARQL via the integrated oxigraph database
- Decentralized discovery: Traverse pod references to discover related content across the network
Key Features
- Deterministic key derivation: Uses 12-word mnemonic seed phrases to reproducibly generate all pod addresses
- Offline-first operation: Build and search your metadata locally without network access or cryptocurrency
- Cross-device synchronization: Access your pods from any device using the same seed phrase
- Network integration: Upload/download pods to/from the Autonomi network when ready
- Semantic interoperability: Standardized RDF schemas enable data sharing between applications
Scope
Colonylib focuses on metadata management and semantic search. It does not handle actual file uploads/downloads - those operations use the standard Autonomi API. Think of colonylib as a sophisticated indexing and discovery layer on top of Autonomi's storage primitives.
Status
Current Capabilities ✅
- Local pod management: Create, modify, and cache pods in platform-appropriate data directories (Windows, Mac, Linux)
- Secure key management: Password-protected keystore with deterministic key derivation from mnemonic phrases
- Network synchronization: Upload modified pods and download updates from the Autonomi network
- Cache management: Populate, repair, and maintain local pod caches with automatic conflict resolution
- RDF graph database: Store and query semantic metadata using oxigraph with SPARQL support
- Pod references: Create interconnected networks of pods with configurable traversal depth
- Semantic search: Query pods by content, type, properties, and relationships
- Advanced search features: Relevance ranking by number of matches and pod depth, fuzzy matching
- Automatic scratchpad overflow: Automatically splits up pod data into multiple scratchpads for large metadata collections (>4MB)
Roadmap 🚧
- Improve Autonomi error handling (auto retry on certain failures, library specific errors)
- Performance optimizations for large-scale pod networks (threading Autonomi fetch operations)
Library Architecture
Colonylib is organized into four core modules that work together to provide a complete metadata management system:
1. KeyStore (key.rs)
Purpose: Cryptographic key management and derivation
- Mnemonic-based: Generate deterministic keys from 12-word seed phrases
- Secure storage: Password-encrypted keystore files using the Cocoon library
- Key derivation: Separate key spaces for pointers, scratchpads, and wallet operations
- Cross-device sync: Same mnemonic produces identical keys across devices
2. DataStore (data.rs)
Purpose: Local file system operations and pod caching
- Platform-aware: Uses OS-appropriate data directories (
~/.local/share/colonyon Linux) - Organized storage: Separate directories for pointers, scratchpads, and pod references
- Cache management: Track upload queues, handle file operations, manage local state
- Atomic operations: Safe concurrent access to pod files
3. Graph (graph.rs)
Purpose: RDF semantic database and SPARQL query engine
- Oxigraph integration: High-performance RDF store with SPARQL 1.1 support
- Ontology independent: Library supports any ontology or schema (Using schema.org is preferred for portability)
- Named graphs: Isolate pod data while enabling cross-pod queries
- JSON-LD metadata entry: Write JSON-LD metadata for subjects within pods
- Query interface: Execute SPARQL queries across all local and referenced pods and return results in JSON format
4. PodManager (pod.rs)
Purpose: High-level pod operations and network coordination
- Unified interface: Coordinates between KeyStore, DataStore, Graph, and Autonomi network
- Pod lifecycle: Create, modify, upload, download, and synchronize pods
- Reference traversal: Discover and cache interconnected pod networks
- Search operations: Execute semantic queries across local and referenced pods
Public API
The main entry point for colonylib is the PodManager struct, which provides a high-level interface for all pod operations. Here are the key methods:
Wallet Key Management
// Add a new wallet key with a name
async async
Core Pod Operations
// Create a new pod with a given name
async async async async async
Network Synchronization
// Upload all local changes to the Autonomi network
async async async async
Pod Discovery and Listing
// List all pods owned by the user
Search and Query
// Search pods using various criteria (text, type, properties)
async
Initialization
// Create a new PodManager instance
async
Installation
Add colonylib to your Rust project:
[]
= "0.3.0"
= "0.4.6"
= "1.44"
= "1.0"
Or use cargo:
Examples
The repository includes three comprehensive examples that demonstrate colonylib's capabilities. These examples are designed to be run in sequence and work on a local Autonomi testnet. Running on main or the Alpha network is possible, but requires code changes.
Prerequisites
Before running the examples, you need:
-
Rust toolchain (1.70 or later)
-
Autonomi network access:
- Local testnet: Run a local Autonomi node for development. See the Autonomi documentation for setup instructions.
- Alpha network: Connect to the Autonomi alpha testnet (change the
init_clientfunction in each example) - Main network: Connect to the live Autonomi network (change the
init_clientfunction in each example)
-
Wallet with tokens (for Alpha/Main network operations, creating the local testnet will handle this for you):
- ETH for gas fees
- ANT tokens for storage payments
Example 1: Setup (examples/setup.rs)
Purpose: Initialize the colonylib environment and verify network connectivity.
This example:
- Creates the local data directory structure
- Initializes or loads an encrypted keystore
- Sets up the RDF graph database
- Connects to the Autonomi network
- Displays wallet balances
Run it:
# For local testnet
# The example uses these default settings:
# - Network: local testnet
# - Mnemonic: "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
# - Password: "password"
What it does:
- Creates
~/.local/share/colony/(Linux) or equivalent on other platforms - Generates deterministic keys from the mnemonic phrase
- Verifies network connectivity and wallet balance
- Prepares the environment for pod operations
Example 2: Adding Pods (examples/add_pods.rs)
Purpose: Create pods with sample metadata and upload them to the network.
This example demonstrates:
- Creating multiple pods with descriptive names
- Adding rich JSON-LD metadata for different file types
- Uploading pods to the Autonomi network
- Handling network costs and replication delays
Run it:
What it creates:
- Pod 1: Metadata for an image file (
ant_girl.png) - Pod 2: Metadata for an audio file (
BegBlag.mp3)
Each pod contains structured metadata using Schema.org vocabularies:
Example 3: Search (examples/search.rs)
Purpose: Demonstrate various search capabilities across the pod network.
This example shows:
- Simple text search across all metadata
- Type-based queries (find all MediaObjects)
- Property-based queries (find items with specific attributes)
- Advanced multi-criteria searches
- Subject data retrieval
Run it:
Search types demonstrated:
- Text search: Find pods containing specific words
- Type search: Query by RDF type (e.g., MediaObject, Document)
- Predicate search: Find resources with specific properties
- Browse: List all subjects with their name, type, and description, ordered by pod depth
- Advanced search: Combine multiple criteria
- Subject retrieval: Get complete metadata for specific resources
- Pod listing: Enumerate all user pods and their contents
Running the Examples
Complete workflow:
# 1. Initialize the environment
# 2. Create sample pods with metadata
# 3. Search and query the pods
Network Configuration:
To use different networks, modify the environment variable in each example:
// Local testnet (default)
let environment = "local".to_string;
// Alpha testnet (needs test tokens)
let environment = "alpha".to_string;
// Main network (needs real tokens)
let environment = "autonomi".to_string;
Wallet Configuration:
The examples use a hardcoded private key for local testing. For production use:
- Generate a secure private key
- Fund the wallet with ETH and ANT tokens
- Update the
LOCAL_PRIVATE_KEYconstant
Data Persistence:
- All examples use the same data directory
- Keystores and graph databases persist between runs
- You can safely re-run examples to see updated results
- Delete the data directory and run
setup.rsto reset the environment if needed
NOTE! This is a destructive operation. It will overwrite the local data directory and recreate it. If you have things you want to keep, make sure you have uploaded everything to Autonomi before running this.
Usage Patterns
Basic Workflow
use ;
use ;
use json;
async
Advanced Pod Operations
Uploading Individual Pods
For more granular control over network operations, you can upload specific pods instead of all pending changes:
// Create and populate a pod
let = pod_manager.add_pod.await?;
let metadata = json!;
pod_manager.put_subject_data.await?;
// Upload only this specific pod
pod_manager.upload_pod.await?;
Discovering and Managing Pods
List all your pods and explore their contents:
// Get all user pods
let pods_result = pod_manager.list_my_pods?;
if let Some = pods_result.as_array
Working with Pod References
Create interconnected pod networks:
// Create related pods
let = pod_manager.add_pod.await?;
let = pod_manager.add_pod.await?;
let = pod_manager.add_pod.await?;
// Create references between pods
pod_manager.add_pod_ref.await?;
pod_manager.add_pod_ref.await?;
// Upload all pods
pod_manager.upload_all.await?;
// Later, refresh with references to discover connected pods
pod_manager.refresh_ref.await?; // Depth 2 to include referenced pods
Pod Management Operations
Rename and remove pods as needed:
// Create a pod with an initial name
let = pod_manager.add_pod.await?;
// Add some metadata
let metadata = json!
Important Notes:
- Renaming: Only changes the display name; the pod address remains the same
- Removal: Completely removes the pod and all associated scratchpads
- Configuration pod: The configuration pod cannot be removed (it's protected)
- Irreversible: Once uploaded to the network, removals cannot be undone
Offline-First User Support
Colonylib supports offline usage - you can create, reference, and search pods without performing any Autonomi network write operations:
// Create pods locally
let = pod_manager.add_pod.await?;
pod_manager.put_subject_data.await?;
// Search works immediately
let results = pod_manager.search.await?;
// Upload when ready (requires network + tokens)
pod_manager.upload_all.await?;
The caveat here is that the data is only stored on your computer. There is no way to recover it if you lose your computer. Uploading to the network is necessary to ensure data persistence, cross-device synchronization, and the ability to share your data with others.
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
Development Setup
Running Tests
# Run all tests
# Run specific module tests
License
This project is licensed under the GPL-3.0-only License - see the LICENSE file for details.
Links
- Documentation: docs.rs/colonylib
- Repository: github.com/zettawatt/colonylib
- Issues: github.com/zettawatt/colonylib/issues
- Autonomi Network: autonomi.com
- Colony App: github.com/zettawatt/colony
- Colony Daemon and CLI: github.com/zettawatt/colony-utils