A modern C++ library for type-safe, platform-independent environment variable parsing with validation and testing support.
libenvpp is a modern C++ library designed for type-safe parsing and validation of environment variables. It provides a clean, prefix-based API to declare required or optional variables, automatically convert them to specified types (like `int`, `std::filesystem::path`, or custom enums), and validate constraints such as ranges or allowed options. The library solves the problem of manual, error-prone string handling and inconsistent environment variable access across platforms.
C++ developers building applications or libraries that rely on configuration via environment variables, particularly those needing robust validation, testing support, and type safety in systems, CLI tools, or server software.
Developers choose libenvpp for its strong type safety, ease of testing, and extensible design—offering a more reliable and maintainable alternative to ad-hoc `getenv()` usage, with features like automatic typo detection, unused variable warnings, and seamless integration with modern C++ build systems.
A modern C++ library for type-safe environment variable parsing
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Automatically parses environment variables into specified C++ types like unsigned int or std::filesystem::path with compile-time safety, eliminating manual string handling errors as shown in the simple example.
Supports custom validators, range checks, and option constraints with detailed error messages, such as enforcing thread counts within hardware limits in the range variable example.
Includes scoped_test_environment and set_for_testing methods to simplify unit testing without mocking system calls, demonstrated in the testing section for isolated test scenarios.
Groups variables under a configurable prefix to avoid naming collisions, improving clarity in large projects, as illustrated in the simple usage example with MYPROG_ prefix.
Creating custom parsers and validators requires specializing template structs like default_parser, which involves C++ idioms that may be daunting for developers unfamiliar with modern C++ metaprogramming.
Integration relies heavily on CMake via FetchContent or submodules, adding build system complexity for projects using alternative systems like Bazel or those preferring simple header-only libraries.
While built-in types are supported, complex user-defined types (e.g., nested structs) require manual parser implementation, lacking seamless auto-parsing features found in some configuration libraries.