piecemeal

module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: MIT

README

piecemeal

A self-hosted BitTorrent client: one Go binary built on anacrolix/torrent, with its own REST API, a qBittorrent-compatible WebAPI for Radarr, Sonarr, Prowlarr and other qBittorrent tools, and an embedded web UI.

Status: early. The engine, the native API and its auth work; the qBittorrent API and the web UI are next. See docs/plan.md for the design and roadmap.

Running

docker run -d --name piecemeal \
  -p 8080:8080 -p 6881:6881 -p 6881:6881/udp \
  -v piecemeal-data:/data -v /path/to/downloads:/downloads \
  -e PIECEMEAL_ADMIN_PASSWORD_HASH='$argon2id$...' \
  ghcr.io/sebdanielsson/piecemeal:latest

Make the password hash with docker run --rm -i ghcr.io/sebdanielsson/piecemeal hash-password and type the password. Without a hash, piecemeal logs a temporary admin password at every start.

The native API is at /api/piecemeal/v1, with interactive docs at /api/piecemeal/v1/docs and the OpenAPI document in api/openapi.json. Sign in with POST /api/piecemeal/v1/auth/login, or create an API key (POST /api/piecemeal/v1/api-keys) and send it as Authorization: Bearer pm_....

Configuration

Startup configuration comes from environment variables:

Variable Default Meaning
PIECEMEAL_ADDR :8080 HTTP address for the APIs and web UI.
PIECEMEAL_DATA_DIR /data in the image Database and piece completion state. Keep it on fast storage.
PIECEMEAL_DOWNLOAD_DIR /downloads in the image Default save path.
PIECEMEAL_ALLOWED_ROOTS the download dir Comma-separated directories every save path must be inside.
PIECEMEAL_WATCH_DIR off Directory polled for .torrent and .magnet files.
PIECEMEAL_QBITTORRENT_WEBUI_DIR off A qBittorrent web UI such as VueTorrent, served at /qbittorrent/. See qBittorrent compatibility.
PIECEMEAL_NATPMP_GATEWAY off NAT-PMP gateway (such as a VPN's) to forward the peer port through. piecemeal listens on whatever port it gets and follows changes.
PIECEMEAL_LISTEN_HOST all Address to bind peer listeners to.
PIECEMEAL_DISABLE_IPV6 false No IPv6 peers, for IPv4-only tunnels.
PIECEMEAL_MMAP false Memory-mapped file I/O. Off by default: on ZFS it amplifies writes.
PIECEMEAL_ADMIN_USERNAME admin The local admin.
PIECEMEAL_ADMIN_PASSWORD_HASH none argon2id hash from piecemeal hash-password.
PIECEMEAL_LOCAL_LOGIN true Allow password sign-in.
PIECEMEAL_SECURE_COOKIES true Mark cookies Secure. Turn off only for plain HTTP on a host other than localhost.
PIECEMEAL_TRUSTED_PROXIES none CIDRs whose X-Forwarded-For is trusted for client addresses.
PIECEMEAL_FETCH_ALLOWED_NETWORKS none Private CIDRs that adding by URL may fetch from. Private, loopback and link-local addresses are refused otherwise.
PIECEMEAL_METRICS auth /metrics access: public, auth (session or API key) or off.
PIECEMEAL_PUBLIC_URL none Where people reach piecemeal, such as https://piecemeal.example.com. Needed for OIDC.
PIECEMEAL_OIDC_ISSUER off OpenID Connect issuer URL, such as Pocket ID's. Turns on SSO sign-in.
PIECEMEAL_OIDC_CLIENT_ID, PIECEMEAL_OIDC_CLIENT_SECRET none The client registered at the provider, with the callback <public URL>/api/piecemeal/v1/auth/oidc/callback.
PIECEMEAL_OIDC_NAME SSO Name on the sign-in button.
PIECEMEAL_OIDC_ALLOWED_GROUPS anyone Comma-separated groups allowed to sign in.
PIECEMEAL_OIDC_ADMIN_GROUPS none Comma-separated groups whose members are admins.
PIECEMEAL_OIDC_GROUPS_CLAIM groups ID token claim holding the groups.
PIECEMEAL_LOG_LEVEL info debug, info, warn or error.
PIECEMEAL_LOG_FORMAT json json or text.

Runtime settings (speed limits, connections, DHT, encryption, seeding goals and more) are changed through PATCH /api/piecemeal/v1/settings. Any of them can be pinned with an environment variable named after it, such as PIECEMEAL_DOWNLOAD_LIMIT for downloadLimit; pinned settings are read-only in the API.

Development

Tool versions are pinned in mise.toml.

mise install        # Go, Node, pnpm, golangci-lint, govulncheck, sqlc
mise run build      # web UI, then bin/piecemeal with it embedded
mise run generate   # store queries, OpenAPI document, web API client
mise run check      # everything CI checks
pnpm -C web dev     # UI dev server, proxying /api to a piecemeal on :8080

Go-only builds need the embed directory to exist: mkdir -p internal/webui/dist && touch internal/webui/dist/.keep.

Releases

Releases are cut by release-please from conventional commits. Each release publishes a signed multi-arch image to ghcr.io/sebdanielsson/piecemeal, with SBOM and provenance attestations, plus binaries for linux/amd64, linux/arm64 and darwin/arm64.

License

MIT

Directories

Path Synopsis
cmd
piecemeal command
Command piecemeal is a BitTorrent client with a native REST API, a qBittorrent-compatible WebAPI and an embedded web UI.
Command piecemeal is a BitTorrent client with a native REST API, a qBittorrent-compatible WebAPI and an embedded web UI.
internal
api
Package api is piecemeal's native REST API under /api/piecemeal/v1, built with Huma.
Package api is piecemeal's native REST API under /api/piecemeal/v1, built with Huma.
auth
Package auth authenticates people and tools: the local admin's password, session cookies for the web UI and for qBittorrent clients (SID), and named API keys sent as Bearer tokens to either API.
Package auth authenticates people and tools: the local admin's password, session cookies for the web UI and for qBittorrent clients (SID), and named API keys sent as Bearer tokens to either API.
auth/authtest
Package authtest has a fake OpenID Connect provider for tests.
Package authtest has a fake OpenID Connect provider for tests.
config
Package config reads piecemeal's startup configuration from environment variables.
Package config reads piecemeal's startup configuration from environment variables.
engine
Package engine owns the anacrolix/torrent client and everything torrent-shaped: adding, removing, starting and stopping torrents, limits, seed goals, categories and tags, and the state the rest of piecemeal reads.
Package engine owns the anacrolix/torrent client and everything torrent-shaped: adding, removing, starting and stopping torrents, limits, seed goals, categories and tags, and the state the rest of piecemeal reads.
engine/enginetest
Package enginetest has helpers for tests that need a BitTorrent swarm: a seeder serving generated content on loopback, and client settings that keep anacrolix off the network.
Package enginetest has helpers for tests that need a BitTorrent swarm: a seeder serving generated content on loopback, and client settings that keep anacrolix off the network.
fetch
Package fetch downloads .torrent files from URLs given to the add endpoints.
Package fetch downloads .torrent files from URLs given to the add endpoints.
logbuf
Package logbuf keeps the most recent log records in memory, for the log endpoints of both APIs.
Package logbuf keeps the most recent log records in memory, for the log endpoints of both APIs.
metrics
Package metrics exports engine state to Prometheus.
Package metrics exports engine state to Prometheus.
natpmp
Package natpmp keeps a TCP and a UDP port mapping open on a NAT-PMP gateway, such as a VPN provider's, and reports the forwarded port.
Package natpmp keeps a TCP and a UDP port mapping open on a NAT-PMP gateway, such as a VPN provider's, and reports the forwarded port.
qbit
Package qbit serves the qBittorrent WebAPI v2 under /api/v2 on top of the engine, so Radarr, Sonarr, Prowlarr and other qBittorrent clients can use piecemeal unchanged.
Package qbit serves the qBittorrent WebAPI v2 under /api/v2 on top of the engine, so Radarr, Sonarr, Prowlarr and other qBittorrent clients can use piecemeal unchanged.
settings
Package settings holds piecemeal's runtime settings: the ones that can be changed through the API while it runs.
Package settings holds piecemeal's runtime settings: the ones that can be changed through the API while it runs.
store
Package store keeps piecemeal's own state in SQLite: settings, users, sessions, API keys, categories, tags and everything about torrents that anacrolix does not persist.
Package store keeps piecemeal's own state in SQLite: settings, users, sessions, API keys, categories, tags and everything about torrents that anacrolix does not persist.
watch
Package watch adds the .torrent and .magnet files dropped into a directory.
Package watch adds the .torrent and .magnet files dropped into a directory.
webui
Package webui serves the web UI that `pnpm -C web build` writes to internal/webui/dist, embedded into the binary.
Package webui serves the web UI that `pnpm -C web build` writes to internal/webui/dist, embedded into the binary.
test
e2e/seeder command
Command seeder seeds generated content for the end-to-end tests.
Command seeder seeds generated content for the end-to-end tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL