Skip to main content

Rust-first, Python-friendly SDK for SeaweedFS

Project description

weedforge

A lightweight Rust SDK with Python bindings for SeaweedFS.

Crates.io PyPI License: MIT

Features

  • Clean Architecture: Domain, Application, Infrastructure, Python layers
  • HA-aware: Multiple master support with automatic failover
  • Async + Sync: Both async and blocking Rust APIs
  • Type-safe: FileId as a first-class entity, not an opaque string
  • Python bindings: Native Python SDK via PyO3
  • Production-ready: Retry logic, error handling, tracing

Installation

Rust

[dependencies]
weedforge = "0.1"

Python

pip install weedforge

Quick Start

Rust (Async)

use weedforge::WeedClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create client with HA support
    let client = WeedClient::builder()
        .master_urls(["http://master1:9333", "http://master2:9333"])
        .build()?;

    // Upload a file
    let file_id = client.write(b"Hello, SeaweedFS!".to_vec(), Some("hello.txt")).await?;
    println!("Uploaded: {}", file_id);

    // Download the file
    let data = client.read(&file_id).await?;
    println!("Downloaded: {} bytes", data.len());

    // Get public URL
    let url = client.public_url(&file_id).await?;
    println!("Public URL: {}", url);

    // Delete the file
    client.delete(&file_id).await?;

    Ok(())
}

Rust (Blocking)

use weedforge::BlockingWeedClient;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = BlockingWeedClient::builder()
        .master_url("http://localhost:9333")
        .build()?;

    let file_id = client.write(b"Hello!".to_vec(), Some("hello.txt"))?;
    let data = client.read(&file_id)?;

    Ok(())
}

Python

from weedforge import WeedClient, FileId

# Create client
client = WeedClient(
    master_urls=["http://localhost:9333"],
    strategy="round_robin",  # or "failover", "random"
    max_retries=3
)

# Upload bytes
file_id = client.write(b"Hello, SeaweedFS!", filename="hello.txt")
print(f"Uploaded: {file_id}")

# Download
data = client.read(file_id)
print(f"Downloaded: {len(data)} bytes")

# Get public URL
url = client.public_url(file_id)
print(f"Public URL: {url}")

# With image resize
url = client.public_url_resized(file_id, width=200, height=200)

# Delete
client.delete(file_id)

# Parse file ID from string
fid = FileId.parse("3,01637037d6")
print(f"Volume: {fid.volume_id}, Key: {fid.file_key}")

Architecture

weedforge follows Clean Architecture principles:

┌─────────────────────────────────────────┐
│             Python Bindings             │  ← Thin wrappers (PyO3)
├─────────────────────────────────────────┤
│            Application Layer            │  ← Use cases (WriteFile, ReadFile)
├─────────────────────────────────────────┤
│              Domain Layer               │  ← Entities (FileId), Ports (traits)
├─────────────────────────────────────────┤
│           Infrastructure Layer          │  ← HTTP clients, HA logic
└─────────────────────────────────────────┘

Dependencies flow downward only:

  • Python → Application → Domain → Infrastructure
  • Domain layer has no external dependencies
  • Application layer is fully testable with mocks

Configuration

Master Selection Strategies

Strategy Description
round_robin Cycle through masters (default)
failover Try masters in order, failover on error
random Random selection

Rust Builder Options

let client = WeedClient::builder()
    .master_urls(["http://master1:9333", "http://master2:9333"])
    .strategy(MasterSelectionStrategy::RoundRobin)
    .max_retries(3)
    .http_config(HttpClientConfig::default()
        .with_connect_timeout(Duration::from_secs(5))
        .with_request_timeout(Duration::from_secs(30)))
    .build()?;

SeaweedFS Protocol

weedforge implements the official SeaweedFS protocol:

Write Flow

  1. GET /dir/assign → Get file ID and volume URL
  2. POST {volume_url}/{fid} → Upload file (multipart)
  3. Return fid for storage

Read Flow

  1. GET /dir/lookup?volumeId=X → Get volume locations
  2. Select replica (random or deterministic)
  3. GET {volume_url}/{fid} → Download file

Development

Prerequisites

  • Rust 1.75+
  • Python 3.9+ (for Python bindings)
  • maturin (for building Python wheels)

Build

# Rust
cargo build --release

# Python (development)
cd crates/weedforge-python
maturin develop

# Python (release wheel)
maturin build --release

Test

# Rust tests
cargo test

# Clippy
cargo clippy --all-targets --all-features

# Format check
cargo fmt --check

# Security audit
cargo deny check

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

weedforge-0.1.0.tar.gz (35.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

weedforge-0.1.0-cp311-cp311-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.11Windows x86-64

weedforge-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

weedforge-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

weedforge-0.1.0-cp39-abi3-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.9+Windows x86-64

weedforge-0.1.0-cp39-abi3-manylinux_2_24_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.24+ x86-64

weedforge-0.1.0-cp39-abi3-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

weedforge-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

weedforge-0.1.0-cp38-cp38-manylinux_2_24_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.24+ x86-64

File details

Details for the file weedforge-0.1.0.tar.gz.

File metadata

  • Download URL: weedforge-0.1.0.tar.gz
  • Upload date:
  • Size: 35.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.2

File hashes

Hashes for weedforge-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b7b0e93f61c4c05cac50a48d03843798ce80b7471cfb8ba017a16989fc142413
MD5 7d412f2ad347b9e02ca5f89ca0ba8058
BLAKE2b-256 7737ca5683013a4c937f9b5c7277202530d6afded82dde0b57732b39fbfa3462

See more details on using hashes here.

File details

Details for the file weedforge-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: weedforge-0.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for weedforge-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 99b62a351693cd10d168167caf15811c7e4f4af3b95602cc05c49fdf3004b341
MD5 f9197a510a666cdf6a0996c7ac1fa598
BLAKE2b-256 72d7014172a5dbeba382801fc995bbd17aae3326f189d48096075df1d2015796

See more details on using hashes here.

File details

Details for the file weedforge-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for weedforge-0.1.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e3eac806dfb7e90e85c36d4300be1895967a7daea5261753e434f64a459ceda9
MD5 e015bb3c88cfcae90641ccdde2e18a19
BLAKE2b-256 c1a15de37b9eaa4204aefd02d4a1767e64c49f92e9420e11d4ff2cdecd8deff7

See more details on using hashes here.

File details

Details for the file weedforge-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for weedforge-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3fedcd66632df7082ccf221f2d5ad01766f92a8ecb412c4a8e29d74d8bbbcc99
MD5 c3e2bfbfd3a2f3d322b874e724093e15
BLAKE2b-256 ec6f77df9dbe9989e18a1c4320a973ac6f2d8ca7ad5b2fb085ffcf7327463839

See more details on using hashes here.

File details

Details for the file weedforge-0.1.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: weedforge-0.1.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.2

File hashes

Hashes for weedforge-0.1.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2dbec587fb59b7ffb8bc552de13766a160336bfc31ace2e6695cca80c26b1dcd
MD5 9f42dc50c14482e33ea7b23f96912618
BLAKE2b-256 db9a68a52a19830263473336ca06c748b6c450afe6e4ad477f3077478fdae953

See more details on using hashes here.

File details

Details for the file weedforge-0.1.0-cp39-abi3-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for weedforge-0.1.0-cp39-abi3-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 ab3d01052607ad54e919a5225819ec266ab57328593ae43feb08da7c4e15fadf
MD5 f0b3a9118f902856aa15101722da5138
BLAKE2b-256 fe4ebce3d899116070d21e7ea0aae09b270671dccecf5f7c644f0bab2241173d

See more details on using hashes here.

File details

Details for the file weedforge-0.1.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for weedforge-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a1933b33a5004e2ce3388e456a4fb0d3da1b497581ce9305a2b07757234e0c97
MD5 4af4d13a6d37241ca2d97d543471e18f
BLAKE2b-256 dfd6c4e46df7de7a382bfc5dc40a42178a6222f4962547999de8f91b37e9f194

See more details on using hashes here.

File details

Details for the file weedforge-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for weedforge-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1f82c24eca3e12d7ab14f99bb0cd34cd1ee02c6b441e57f495ea41f612f0b54b
MD5 0a5622cea370e3c9060300fdfa5c1305
BLAKE2b-256 acfe6bb0fec3150ff3b1b308b1f1663a96687f643979b65c87914b49510f754d

See more details on using hashes here.

File details

Details for the file weedforge-0.1.0-cp38-cp38-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for weedforge-0.1.0-cp38-cp38-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 a717508ff11188fc9471ba7f3341818ba4f9fc6820cfbe8ce1daa75bb8156042
MD5 61a4de687202c8bd2f99c69d3d006361
BLAKE2b-256 62a2733224c5db010fd2012fb12c44ad304c789f0a515e1e0ebee1a521a557a1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page