Sprig

Over 100 template functions for Go's text/template and html/template, covering strings, lists, dicts, dates, math, crypto, and semver comparisons.

Library
Go
vv3.3.0
4,752 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
48 /100 Fair
Development Activity 0
Maintenance 20
Community 72
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
71 /100 Good
Architecture 70
Code Quality 78
Innovation 55
Learning Curve 80

Sprig is a Go library that extends the standard library’s text/template and html/template packages with more than 100 utility functions. Go’s built-in templating language is deliberately minimal, so Sprig fills the gap with string manipulation, list and dict helpers, date formatting, type conversion, math, cryptographic hashing, regular expressions, URL parsing, and semantic version comparison, all callable directly from template pipelines.

The project is widely used as a dependency inside other tools rather than a standalone application: Helm (the Kubernetes package manager) bundles Sprig to power chart templating, and it shows up throughout the Go templating ecosystem wherever text/template needs more expressive power. It is distributed as a single importable package with no external services or configuration required.

Sprig follows a deliberate design philosophy: template functions should never return hard errors when a sensible default can be produced instead, arguments are frequently ordered to support piping ({{ "foo" | repeat 5 }}), and functions are kept purely presentational rather than allowed to fetch or mutate external data. The library ships two major, source-compatible-but-behaviorally-different version lines (v2 and v3), with v3 as the actively maintained release on the module path github.com/Masterminds/sprig/v3.

What You Get

  • A single sprig.FuncMap() call that registers 100+ functions on any text/template or html/template instance
  • String helpers (trim, truncate, case conversion, base64/base32, quoting, wrapping) inspired by Twig and underscore.js
  • List and dict helpers (push, prepend, uniq, without, merge, pluck, dict manipulation) using reflection so they work across slice and map types
  • Date formatting and manipulation functions, plus math, type-conversion, and default-value helpers for safe fallbacks
  • Cryptographic helpers (SHA, bcrypt, derivePassword, genPrivateKey) and URL/regex utilities for common templating chores
  • Semver comparison functions built on Masterminds/semver for version-gated template logic
  • A HermeticTxtFuncMap/HermeticHtmlFuncMap variant that strips non-deterministic functions (like now or randAlphaNum) for reproducible rendering

Common Use Cases

  • Kubernetes/Helm chart templating, where Sprig is the built-in function set for chart authors
  • Generating configuration files, boilerplate code, or infrastructure manifests from Go templates
  • Building internal CLI or codegen tools that render text/HTML from user-supplied or static templates
  • Adding safe default values and type coercion to templates fed by loosely-typed data (YAML/JSON configs)
  • Comparing semantic versions inside templates to gate feature output by version constraints

Under The Hood

Architecture

Sprig is organized as a flat, single-package library with functions grouped by domain into separate files (strings.go, list.go, dict.go, date.go, crypto.go, numeric.go, regex.go, url.go, semver.go, reflect.go, network.go, defaults.go). A central functions.go assembles every domain’s exports into one genericMap, exposed through FuncMap()/TxtFuncMap()/HtmlFuncMap() and hermetic variants that filter out non-deterministic entries like now and random generators via a nonhermeticFunctions list. There is no layering beyond this registry pattern — each function is a small, self-contained transform with no shared internal state, which keeps the blast radius of any single function change limited to its own file.

Tech Stack

The module targets modern Go (go.mod requires go 1.23 with a 1.24 toolchain) and pulls in a small set of focused dependencies: dario.cat/mergo for map merging, Masterminds/goutils and huandu/xstrings for string helpers, Masterminds/semver/v3 for version comparison, google/uuid for identifiers, mitchellh/copystructure for deep copies, shopspring/decimal for precise arithmetic, spf13/cast for type coercion, and golang.org/x/crypto for hashing/bcrypt. There is no build tooling beyond go build/go test; a Makefile wraps common commands and GitHub Actions runs the test suite on push.

Code Quality

Every domain file has a matching _test.go file (crypto, date, dict, list, network, numeric, regex, semver, strings, url, reflect, defaults, flow_control), and tests exercise functions through actual template execution via a runt() helper rather than only unit-testing raw Go calls, which validates the piping behavior end to end. testify/assert is used for assertions. Error handling favors returning zero-value/default output over propagating errors, consistent with the project’s stated design principle that template functions shouldn’t break rendering. No linter config or static-analysis tooling is checked in beyond go vet implied by CI.

What Makes It Unique

Sprig’s contribution isn’t a novel algorithm but a deliberate, well-documented set of conventions for template-function ergonomics: reversed argument order to support piping, refusal to hit external error paths where a default will do, and a hard rule against functions that fetch external data or override core template behavior. Its main technical distinction is being the de facto function set behind Helm’s chart templating, which has made its API surface and defaults an implicit standard across the Go templating ecosystem rather than one library among many.

Used by 15 apps in this directory

Go
98%
Apache 2.0

Space Cloud

Authentication · Devops

4,003

Kubernetes-native serverless platform that generates instant GraphQL and REST APIs for any database with built-in auth and real-time subscriptions

View details
50
Repo Health
74
Technical
63
Dependency
Built with
Go 98%
Updated 2 years ago
Go
75%
AGPL 3.0

Teleport

Authentication · Security

21,016

Zero-trust infrastructure access platform that replaces credentials and VPNs with short-lived certificates, SSO, and identity-aware proxies for SSH, Kubernetes, databases, RDP, and AI agents.

View details
94
Repo Health
81
Technical
68
Dependency
Built with
Go 75%
TypeScript 16%
Updated 1 weeks ago
Go
99%
MIT

temporal

Automation · Devops

23,948

Open-source durable execution platform that keeps mission-critical workflows running through any failure, automatically.

View details
92
Repo Health
85
Technical
67
Dependency
Built with
Go 99%
Updated 1 weeks ago
Go
94%
MIT

Traefik

Automation · Devops · Security

65,344

A cloud-native reverse proxy and load balancer that auto-configures itself from Docker, Kubernetes, and other orchestrators — zero manual routing required.

View details
93
Repo Health
85
Technical
64
Dependency
Built with
Go 94%
Updated 1 weeks ago
Go
98%
Other

Tyk API Gateway

Developer Tools · Devops

10,869

Cloud-native, high-performance open-source API gateway for REST, GraphQL, gRPC, and TCP — built in Go since 2014 with no feature lockout.

View details
97
Repo Health
78
Technical
67
Dependency
Built with
Go 98%
Updated 1 weeks ago
Go
54%
AGPL 3.0

Uptrace

Devops · Monitoring

4,305

Unified open-source APM that collects OpenTelemetry traces, metrics, and logs into a single self-hosted platform backed by ClickHouse.

View details
71
Repo Health
70
Technical
65
Dependency
Built with
Go 54%
Vue 34%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers