A command-line tool and Go library for querying and modifying JSON, YAML, TOML, XML, CSV and other structured data with one selector syntax.
caarlos0/env
A zero-dependency Go library that parses environment variables into typed structs using struct tags.
- Stars
- 6,356
- Forks
- 299
- Open issues
- 44
- Last commit
- 2 days ago
What is it?
env is a Go library for loading configuration from environment variables. You define a struct, annotate its fields with `env` tags naming the variables to read, and call Parse or ParseAs to fill the struct with typed values. It has no external dependencies.
Beyond basic string and number fields, env supports durations, URLs, time zones, slices and maps with configurable separators, nested structs with prefixes, default values, and custom parsers for your own types. Tag options cover required and non-empty checks, reading values from files, variable expansion, and unsetting variables after use.
The library is the 'feature-complete' v11 release line, with generics-based helpers and options for changing tag names, providing a custom environment source, and hooking into value assignment.
Key features
- 01Parses environment variables into structs using `env` struct tags.
- 02Supports built-in numeric, string, bool, duration, URL and time zone types.
- 03Handles slices, maps, pointers and nested structs with prefixes.
- 04Offers required, notEmpty, file-reading and variable expansion options.
- 05Allows custom parsers for user-defined types.
Use cases
- Loading application configuration from environment variables in a Go service.
- Validating that required settings are present at startup.
- Reading container or 12-factor style configuration into typed Go structs.
Quick start
- 1
Install the library with go get
go get github.com/caarlos0/env/v11 - 2
Define a struct with env tags and call env.Parse to load environment variables into it
Things to know
- Unexported struct fields are ignored by design.
Topics
FAQ
- What is env?
- A zero-dependency Go library that parses environment variables into typed structs using struct tags. env is a Go library for loading configuration from environment variables. You define a struct, annotate its fields with `env` tags naming the variables to read, and call Parse or ParseAs to fill the struct with typed values. It has no external dependencies.
- Is env free to use? What license does it have?
- env is open source under the MIT license. Check the license terms before using it in commercial products.
- Is env still maintained?
- Actively maintained. The last commit to env was on Nov 5, 2026.
- What can I use env for?
- Loading application configuration from environment variables in a Go service. Validating that required settings are present at startup. Reading container or 12-factor style configuration into typed Go structs.
- How do I install env?
- Install the library with go get: go get github.com/caarlos0/env/v11 Define a struct with env tags and call env.Parse to load environment variables into it
- Where can I get env?
- The source code and installation instructions are on GitHub: https://github.com/caarlos0/env
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A web-based visual configuration generator for the Ghostty terminal that exports a minimal config file.
A zero-dependency Node.js module that loads environment variables from a .env file into process.env.
A Python library that loads key-value pairs from a .env file into environment variables, following 12-factor app practices.
A tmux plugin that adds a hackable, powerline-style status bar built from segments, written in pure bash.
A config-overrides helper that lets you customize Create React App's webpack, Jest and dev server settings without ejecting.