A strict, zero-boilerplate environment variable manager with .env support and validation.
envflag enforces a disciplined approach to configuration: you must explicitly initialize the library (which loads .env files via dotenvy), and then query typed values through a validated builder API or simple convenience functions.
- Strict Initialization: All queries panic if
init()has not been called — no silent misconfiguration. - Dotenv Support: Seamlessly loads
.envfiles upon initialization, or from a custom path. - Prefix Filtering: Keep only environment variables matching configured prefixes (e.g.
APP_,SVC_). - Validated Builder API: Chain
.default(),.validate(), and.get()for type-safe, validated lookups that returnResult. - Built-in Validators:
is_port,is_integer,is_positive_integer,is_positive_number,is_bool,is_non_empty,is_url,is_integer_in_range, and more. - Custom Validators: Pass any
Fn(&str) -> boolclosure as a validator. - Zero Boilerplate: No built-in logging or printing; you control how to display your config.
Check the examples directory for runnable code:
- Basic Usage:
examples/basic.rs- Initialize and query with convenience API. - Validation:
examples/validation.rs- Chain validators on environment variables. - Prefix Filtering:
examples/prefixes.rs- Filter and scope variables by prefix. - Custom Init:
examples/custom_init.rs- Load from a specific.envfile path.
[dependencies]
envflag = { version = "0.1", features = ["full"] }| Feature | Description |
|---|---|
url |
Enables strict URL validation in is_url via the url crate (WHATWG URL Standard). |
regex |
Enables matches_regex validator via fancy-regex. |
tracing |
Enables optional tracing::warn on validation failures and parse fallbacks in convenience API. |
full |
Enables all features above. |
Released under the MIT License © 2026 Canmi