Install
Python (pip)
Linux & macOS (one-liner)
|
Windows (PowerShell)
irm https://raw.githubusercontent.com/sandy-sachin7/shard/main/scripts/install.ps1 | iex
Cargo
Build from source (Rust 1.89+)
Install from local source
Performance (Measured)
All numbers below are measured on Linux x86_64 (AMD Ryzen 5 5600H, 12 logical CPUs) using benchmarks/bench_real.py across 256 MiB artifacts — covering both high-entropy binary payloads (incompressible 1.00×) and structured JSONL datasets (compressible with Zstd):
| Scenario (256 MiB artifact) | Chunker | v1 Store Size (Compression) | v2 Incremental Delta Stored | Dedup Savings | shard verify |
shard checkout |
|---|---|---|---|---|---|---|
| High-entropy payload + 5% append (12.8 MiB) | fixed |
256.01 MiB (1.00×) |
12.81 MiB | 95.0% | 238 MB/s | 206 MB/s |
| High-entropy payload + 5% append (12.8 MiB) | fastcdc |
256.01 MiB (1.00×) |
16.90 MiB | 93.4% | 358 MB/s | 267 MB/s |
| High-entropy payload + 1 MiB prepend (offset shift) | fixed |
256.01 MiB (1.00×) |
257.01 MiB | 0.0% | 479 MB/s | 424 MB/s |
| High-entropy payload + 1 MiB prepend (offset shift) | fastcdc |
256.01 MiB (1.00×) |
3.74 MiB | 98.5% | 982 MB/s | 622 MB/s |
| JSONL dataset + 1 MiB prepend (offset shift) | fixed |
25.00 MiB (10.25×) |
24.96 MiB | 0.1% | 1,249 MB/s | 666 MB/s |
| JSONL dataset + 1 MiB prepend (offset shift) | fastcdc |
25.05 MiB (10.23×) |
0.51 MiB | 98.0% | 1,204 MB/s | 487 MB/s |
Empirical ML Checkpoint Deduplication (64 MiB FP32 Safetensors-Style Weights)
Measured with benchmarks/bench_checkpoints.py (raw output in benchmarks/checkpoint_dedup_results.json):
| Checkpoint Update Pattern (64 MiB FP32) | Chunker | v1 Store (Zstd) | v2 Incremental Delta | Chunk Dedup (vs v1 store) |
|---|---|---|---|---|
Full fine-tune (100% FP32 weights updated by 1e-4 step) |
fixed / fastcdc |
59.31 MiB | 59.31 MiB | 0.0% |
| Frozen 90% backbone + 10% updated head / adapter | fixed |
59.31 MiB | 7.42 MiB | 87.5% |
| Frozen 90% backbone + 10% updated head / adapter | fastcdc |
59.31 MiB | 6.52 MiB | 89.0% |
| 1 MiB adapter prepend + frozen backbone (offset shift) | fixed |
59.31 MiB | 60.24 MiB | 0.0% |
| 1 MiB adapter prepend + frozen backbone (offset shift) | fastcdc |
59.31 MiB | 26.99 MiB | 54.5% |
Honest takeaway: Full fine-tuning perturbs every float weight each epoch, so byte-level chunk deduplication yields 0% savings there — in that workflow, Shard's value is signed Ed25519 provenance, client-side encryption, and direct P2P sync. Content-defined deduplication (
--chunker fastcdc, legacy alias--chunker rabin) delivers strong storage and sync wins when layers stay frozen (LoRA/adapters, frozen backbones), headers shift tensor offsets, or structured JSONL/tabular datasets evolve incrementally.
Reproduce locally with python3 benchmarks/bench_real.py --size-mb 256, uv run --with numpy python3 benchmarks/bench_checkpoints.py, cargo bench, or ./benchmarks/p2p_bench.sh (see benchmarks/METHODOLOGY.md).
# Track a base model checkpoint
# After adding or updating adapters (unchanged chunks are deduplicated)
Python API
Shard ships native Rust-backed Python bindings (shard-py) via PyO3 — no external CLI binary required:
# Initialize repo and track model weights
=
# Later in your training loop:
Quick Start
# Initialize a repository (default: flat store, zstd compression, fixed 4 MiB chunks)
# Add files or directories recursively (respects .shardignore)
# Create a cryptographically signed commit
# Inspect history and working tree
# Verify Blake3 content hashes, Merkle roots, and Ed25519 signature
# Restore files from a commit or branch
# Share over P2P (prints your /ip4/.../tcp/<port>/p2p/<peer_id> multiaddr)
# Pull from a peer using its full multiaddr including /p2p/<peer_id>
# Branching and merging
# Backup, restore, export, and import
# Push sanitized repo artifacts to HuggingFace Datasets (private keys excluded)
Security & Durability
Shard v2.5.2 is engineered for verifiable, defense-in-depth ML artifact workflows:
- Cryptographic Provenance & Trust Anchors: Every commit and manifest is canonicalized and signed with Ed25519.
shard verifyenforces trust-anchor membership (local keychain +authorized_keys), key rotation validity windows, Blake3 content hashes, and manifest Merkle roots (rejecting unsigned commits unless--allow-unsignedis explicitly passed). - Authenticated Encryption at Rest (
SHRDv1): Private repositories (shard init --private) encrypt each chunk inside an 8-byte self-describingSHRDv1 envelope using AES-256-GCM withchunk_idbound as Associated Authenticated Data (AAD), preventing cross-chunk swapping. Secret keys are encrypted with Argon2id + AES-256-GCM, persisted atomically with0o600permissions, and zeroized in memory (zeroize). - Authenticated P2P Protocol & SSRF Defense: P2P writes (and reads when
authorized_keysis configured) require a 2-step domain-separated Ed25519 challenge-response handshake (shard-p2p-auth-v1:) bound to both peer IDs and a 32-byte server nonce with a 30-second TTL.shard synconly auto-pulls from peers present in its verifiedaddress_book(peers.json, mDNS, or established dialed connections) on the repository's own topic — never dialing arbitrary multiaddrs advertised over Gossipsub. - Crash Safety & Cross-Process Concurrency: Mutations record a CRC32-checksummed Write-Ahead Log (
wal.log),shard checkoutpersists a durable fsynced checkout journal (.shard/checkout_journal.json) with backup-before-swap rollback andshard recoverreplay, and every write uses atomic temp-file +fsync+ rename. Every repository operation acquires both an in-process read/write lock and an OS-level advisory lock on.shard.lock(fs2). - Safe Backup, Restore & HuggingFace Export:
shard restorestrictly confines tar archive entries inside.shard/, rejecting path traversal, symlinks, hard links, and special files.shard hf pushcheckpoints SQLite WAL (PRAGMA wal_checkpoint(TRUNCATE)) / flushes Sled under an exclusive write lock and enforces a mandatory secret-exclusion preflight sosecret.key,repo.key,archive/,wal.log, and lock files are never uploaded. - Hardened HTTP API:
shard serveenforces constant-time bearer token authentication (SHARD_API_TOKENor ephemeral CSPRNG token) on all/api/v1/*routes, denies cross-origin requests by default (explicit allowlist viaSHARD_API_CORS_ORIGINS), and confines file paths strictly inside the repository root.
See SECURITY.md for the full threat model, cryptographic primitives, and vulnerability disclosure process.
Commands
| Command | What it does | Key flags |
|---|---|---|
init |
Initialize a repository | --private, --db flat|sled|sqlite, --compression zstd|zlib|none, --chunker fixed|fastcdc, --chunk-size <bytes>, --passphrase, --json |
add <path> |
Stage files or directories for commit | --json (recursive for directories; honors .shardignore) |
commit |
Create an Ed25519-signed commit | -m <msg>, --author <name>, --json |
log |
Show commit history | --json |
checkout <target> |
Restore files from a commit ID or branch | --json |
status |
Show working tree and staging state | --json, --porcelain |
verify <commit> |
Verify hashes, Merkle roots, and signature | --allow-unsigned, --json |
diff <commit1> [commit2] |
Compare two commits (or commit vs HEAD) | --json |
prune |
Remove unreachable objects via DAG GC | --json |
tag |
Manage commit tags | add <name> <commit>, list |
branch |
Manage branches | create <name> [commit], delete <name>, list |
merge <branch> |
Merge branch into current HEAD | -m <msg>, --author <name>, --json |
config |
View/edit repository configuration | get [key], set <key> <value> |
share |
Serve and announce commits over P2P | --listen <multiaddr>, --json |
sync |
Discover peers and auto-pull repo updates | --json |
pull <peer> <commit> |
Pull a commit from a specific peer (/p2p/<peer_id>) |
--json |
push <peer> |
Push objects reachable from HEAD to a peer (does not move receiver refs) | --json |
peer add <multiaddr> |
Add a known peer to peers.json |
--public-key <hex>, --json |
hf push <dataset_id> |
Stage, checkpoint, and upload sanitized .shard to HuggingFace |
--token <tok> (prefer HF_TOKEN), --json |
hf pull <dataset_id> |
Download a .shard repository from HuggingFace Datasets |
--token <tok> (prefer HF_TOKEN), --json |
backup <output> |
Create a .tar.gz repository backup |
--json |
restore <backup> |
Restore .shard/ safely from backup |
--json |
export <commit> <dir> |
Reconstruct a commit's files to a directory | --json |
import <dir> |
Ingest a directory as a signed commit | -m <msg>, --author <name>, --json |
recover |
Replay/recover from an incomplete WAL | --json |
health |
Run repository diagnostics and print metrics | --json |
serve |
Start authenticated HTTP API server | --addr <host:port>, --json |
unlock |
Validate repository passphrase against local keys | --passphrase (prefer SHARD_PASSPHRASE) |
relay |
Start a Circuit Relay v2 node for NAT traversal | --listen <multiaddr>, --json |
transfer |
Inspect or clean resumable P2P partial transfers | list [--json], remove <commit_id> |
key |
Manage signing keys and P2P trust allowlist | rotate, list [--json], verify [--json], add-authorized <hex>, remove-authorized <hex>, list-authorized [--json] |
completions <shell> |
Generate shell completions | bash, zsh, fish, elvish, powershell |
Before a peer can push, add its public key on the receiving repo with shard key add-authorized <public-key-hex>. Repos without authorized_keys allow P2P reads and reject P2P writes.
Global Flags
| Flag | Effect |
|---|---|
--log-format <plain|json> |
Format diagnostic logs written to stderr (plain default, or json) |
-v, --verbose |
Enable debug-level diagnostic logging on stderr |
Individual data/status commands accept
--jsonon the subcommand for machine-readablestdoutoutput (diagnostic logs always go tostderr).
Operations & Configuration
Configuration System
Shard supports layered configuration with SHARD_* environment variable overrides:
# Persist in .shard/config.json
# Environment overrides (take precedence over config.json)
Supported keys: storage_backend (flat/sled/sqlite), compression (none/zstd/zlib), chunker_mode (fixed/fastcdc; legacy alias rabin), chunk_size, rate_limit_max_requests, rate_limit_window_secs, gc_enabled, gc_interval_secs, hidden_files_enabled.
Concurrency Control
All repository operations are serialized per repository with both in-process RwLock and cross-process OS advisory locking on .shard.lock:
- Read operations (
log,status,diff,verify,health,export,push,backup) execute concurrently with other readers. - Write operations (
init,add,commit,checkout,merge,prune,import,restore,hf pushstaging, key updates) execute exclusively.
Garbage Collection
# Manual GC: prune unreachable objects
# Enable automatic periodic GC in long-lived processes (`share`, `sync`, `serve`)
GC traverses reachability from HEAD, all branches, all tags, the staging index, and active inbound P2P transfer pins before removing unreachable objects.
P2P DoS Protection
Configurable sliding-window per-peer rate limiting in share and sync:
SQLite WAL & Connection Pool
When --db sqlite is selected, Shard manages SQLite via an r2d2 connection pool (up to 8 connections) with PRAGMA journal_mode=WAL, PRAGMA synchronous=NORMAL, and PRAGMA busy_timeout=5000. Snapshot exports (hf push) execute PRAGMA wal_checkpoint(TRUNCATE) under an exclusive lock before copying objects.db.
Health & Metrics
(The metrics object includes all 32 atomic operation and error counters from shard_core::metrics::MetricsSnapshot.)
HTTP API
Architecture
See ARCHITECTURE.md and the mdBook documentation for a deep dive.
graph TD
CLI["shard-cli<br/>(clap CLI entrypoint)"]
PY["shard-py<br/>(PyO3 native Python module)"]
subgraph Core["shard-core"]
Ops["OpQueue + .shard.lock<br/>(RW concurrency control)"]
Pipeline["Chunker (Fixed / FastCDC)<br/>+ SHRD v1 Codec (Zstd / Zlib / AES-GCM)"]
DAG["Commit DAG · Manifests · Index<br/>Branch · Merge · WAL · GC"]
Store["Store Abstraction<br/>(FlatStore default · Sled · SQLite)"]
API["Axum HTTP API (/api/v1/*)<br/>+ HuggingFace Export"]
end
subgraph Net["shard-net"]
LibP2P["libp2p Node<br/>TCP + QUIC · Noise · Yamux<br/>mDNS · Kademlia · Gossipsub<br/>CBOR Req/Resp · Relay v2 · DCUtR · AutoNAT"]
end
subgraph Crypto["shard-crypto"]
Keys["Ed25519 KeyPair<br/>Argon2id + AES-256-GCM<br/>Zeroizing Secret Persistence"]
end
subgraph Storage["shard-storage"]
DB["SledBackend (handle cache)<br/>SqliteBackend (WAL + r2d2 pool)"]
end
CLI --> Core
CLI --> Crypto
PY --> Core
Core --> Net
Core --> Crypto
Core --> Storage
Storage Layout
<repo_root>/
├── .shard.lock # OS-level advisory lock (fs2)
└── .shard/
├── objects/<2-prefix>/<hash> # Content-addressed chunks (backend=flat, default)
├── objects.db # Sled directory or SQLite DB (backend=sled|sqlite)
├── HEAD # Active branch ref or detached commit ID
├── config.json # Repository configuration
├── index # Staging index
├── wal.log # CRC32-checksummed write-ahead log
├── partial/ # Resumable in-flight P2P transfers
├── keys/ # Ed25519 keypair, repo key, and rotation chain
│ ├── secret.key # 0o600, optionally Argon2id+AES-256-GCM encrypted
│ ├── public.key
│ ├── repo.key # Private repo AES-256-GCM key (if --private)
│ ├── current # Active key_id
│ ├── records/
│ ├── rotations/
│ └── archive/
├── refs/heads/ # Branch pointers
├── authorized_keys # P2P authentication allowlist
├── peers.json # Known P2P peer multiaddrs
└── tags.json # Named commit tags
Key Design Decisions
| Decision | Choice | Rationale |
|---|---|---|
| Chunking | Fixed 4 MiB (default) or FastCDC (--chunker fastcdc, alias rabin) |
Fixed for predictable I/O; FastCDC (64-bit Gear hash + dual normalized masks) for shift-resilient dedup |
| Compression | Zstd (default), Zlib, or None inside SHRD v1 envelope |
Runtime selectable; self-describing per-chunk header allows safe dedup across compression changes |
| Hashing | Blake3 | SIMD-accelerated cryptographic hashing for content addressing and Merkle roots |
| Signatures | Ed25519 | Fast, compact 64-byte signatures with key rotation chains and trust anchors |
| Storage | FlatStore (default), Sled, or SQLite | FlatStore for simple zero-dependency portability; Sled/SQLite for single-database indexed storage |
| P2P Transport | libp2p TCP + QUIC + Noise + Yamux | Encrypted multiplexed streams with mDNS, Kademlia, Gossipsub, Circuit Relay v2, DCUtR, and AutoNAT |
| Wire Format | CBOR (request-response) + JSON (Gossipsub) | Compact binary transfer for chunks/manifests, human-inspectable pubsub announcements |
| Concurrency | In-process RwLock + .shard.lock OS lock (fs2) |
Concurrent readers, exclusive writers across threads and processes |
| Crash Safety | CRC32 WAL + staged transactional checkout + atomic temp-file fsync + rename |
Prevents torn commits, corrupt objects, and partial multi-file checkouts on verification/persist errors |
Comparison
| Feature | Git LFS | DVC | HuggingFace Hub | Shard |
|---|---|---|---|---|
| Cloud dependency | Required | Optional | Required | None (local-first) |
| Chunking strategy | Full file | Full file | FastCDC (Xet) | Fixed or FastCDC |
| Commit signing | GPG (optional) | No | No | Ed25519 (built-in, enforced) |
| Encryption at rest | No | No | Server-side | Client-side AES-256-GCM (AAD) |
| Native P2P sync | No | No | No | Yes (libp2p TCP/QUIC/Relay) |
| Python API | No | Yes | Yes | Yes (native PyO3) |
| Offline support | Poor | Good | Poor | First-class |
Roadmap
Completed
- v1.x – v2.0: Local VCS core (
init,add,commit,verify,log,checkout,status,diff,branch,merge,tag,prune), FastCDC, Zstd/Zlib, Flat/Sled/SQLite stores, libp2p P2P (share,sync,pull,push,relay), Python bindings (shard-py), HTTP API (serve). - v2.4.0 – v2.5.2 Hardening: Self-describing
SHRDv1 chunk envelopes with AAD-bound AES-256-GCM, 2-step domain-separated Ed25519 P2P challenge-response auth, SSRF-safe Gossipsub auto-pull, CRC32 WAL +.shard.lockcross-process concurrency, durable crash-atomic checkout journal (.shard/checkout_journal.json) with boundary fault-injection tests andshard recoverreplay, FastCDC naming & empirical ML checkpoint benchmarks, strict.shard/tar confinement inrestore, constant-time bearer auth on/api/v1/*, zero non-test panics, and full cross-platform CI.
Upcoming
- v2.6 (Cloud-Hybrid & Packaging): Optional S3/GCS/Azure remote object-store adapters, Homebrew / Nix / Scoop packages, resumable multi-peer striped pulls, and delta packfile compaction.
- v3.0 (Federation & Hardware Keys): Multi-region Circuit Relay v2 federation, OIDC / hardware-backed (HSM/YubiKey) commit signing, fine-grained repository RBAC, and WebRTC browser inspection client.
Contributing
See CONTRIBUTING.md. All contributors must follow the Code of Conduct.
Security
See SECURITY.md for supported versions, threat model, and private vulnerability reporting.
License
MIT. See LICENSE.