{"id":13626131,"url":"https://github.com/softprops/envy","last_synced_at":"2025-05-14T13:05:54.335Z","repository":{"id":45253999,"uuid":"62110906","full_name":"softprops/envy","owner":"softprops","description":"deserialize env vars into typesafe structs with rust","archived":false,"fork":false,"pushed_at":"2024-06-07T23:13:52.000Z","size":3398,"stargazers_count":915,"open_issues_count":18,"forks_count":42,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-08T00:06:44.791Z","etag":null,"topics":["12-factor","configuration","env","envy","rust","serde"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/softprops.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-28T04:49:18.000Z","updated_at":"2025-05-07T18:49:11.000Z","dependencies_parsed_at":"2023-02-17T19:00:22.001Z","dependency_job_id":"91d9246e-c79a-4d50-acb9-1b2512cde1dc","html_url":"https://github.com/softprops/envy","commit_stats":{"total_commits":140,"total_committers":14,"mean_commits":10.0,"dds":"0.15000000000000002","last_synced_commit":"e22035c3b91f999c325a44c0c77f0e6e05750da3"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softprops%2Fenvy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softprops%2Fenvy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softprops%2Fenvy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softprops%2Fenvy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/softprops","download_url":"https://codeload.github.com/softprops/envy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254149946,"owners_count":22022851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["12-factor","configuration","env","envy","rust","serde"],"created_at":"2024-08-01T21:02:10.765Z","updated_at":"2025-05-14T13:05:54.292Z","avatar_url":"https://github.com/softprops.png","language":"Rust","funding_links":[],"categories":["Rust","Libraries"],"sub_categories":["Configuration"],"readme":"# envy [![Github Actions](https://github.com/softprops/envy/workflows/Main/badge.svg)](https://github.com/softprops/envy/actions) [![Coverage Status](https://coveralls.io/repos/github/softprops/envy/badge.svg?branch=master)](https://coveralls.io/github/softprops/envy?branch=master) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE) [![crates.io](https://img.shields.io/crates/v/envy)](https://crates.io/crates/envy) [![Latest API docs](https://img.shields.io/badge/docs-latest-green.svg)](https://softprops.github.io/envy)\n\n\u003e deserialize environment variables into typesafe structs\n\n## 📦  install\n\nRun `cargo add envy` or add the following to your `Cargo.toml` file.\n\n```toml\n[dependencies]\nenvy = \"0.4\"\n```\n\n## 🤸 usage\n\nA typical envy usage looks like the following. Assuming your rust program looks something like this...\n\n\u003e 💡 These examples use Serde's [derive feature](https://serde.rs/derive.html)\n\n```rust\nuse serde::Deserialize;\n\n#[derive(Deserialize, Debug)]\nstruct Config {\n  foo: u16,\n  bar: bool,\n  baz: String,\n  boom: Option\u003cu64\u003e\n}\n\nfn main() {\n    match envy::from_env::\u003cConfig\u003e() {\n       Ok(config) =\u003e println!(\"{:#?}\", config),\n       Err(error) =\u003e panic!(\"{:#?}\", error)\n    }\n}\n```\n\n... export some environment variables\n\n```bash\n$ FOO=8080 BAR=true BAZ=hello yourapp\n```\n\nYou should be able to access a completely typesafe config struct deserialized from env vars.\n\nEnvy assumes an env var exists for each struct field with a matching name in all uppercase letters. i.e. A struct field `foo_bar` would map to an env var named `FOO_BAR`.\n\nStructs with `Option` type fields will successfully be deserialized when their associated env var is absent.\n\nEnvy also supports deserializing `Vecs` from comma separated env var values.\n\nBecause envy is built on top of serde, you can use all of serde's [attributes](https://serde.rs/attributes.html) to your advantage.\n\nFor instance let's say your app requires a field but would like a sensible default when one is not provided.\n```rust\n\n/// provides default value for zoom if ZOOM env var is not set\nfn default_zoom() -\u003e u16 {\n  32\n}\n\n#[derive(Deserialize, Debug)]\nstruct Config {\n  foo: u16,\n  bar: bool,\n  baz: String,\n  boom: Option\u003cu64\u003e,\n  #[serde(default=\"default_zoom\")]\n  zoom: u16\n}\n```\n\nThe following will yield an application configured with a zoom of 32\n\n```bash\n$ FOO=8080 BAR=true BAZ=hello yourapp\n```\n\nThe following will yield an application configured with a zoom of 10\n\n```bash\n$ FOO=8080 BAR=true BAZ=hello ZOOM=10 yourapp\n```\n\nThe common pattern for prefixing env var names for a specific app is supported using\nthe `envy::prefixed(prefix)` interface. Asumming your env vars are prefixed with `APP_`\nthe above example may instead look like\n\n```rust\nuse serde::Deserialize;\n\n#[derive(Deserialize, Debug)]\nstruct Config {\n  foo: u16,\n  bar: bool,\n  baz: String,\n  boom: Option\u003cu64\u003e\n}\n\nfn main() {\n    match envy::prefixed(\"APP_\").from_env::\u003cConfig\u003e() {\n       Ok(config) =\u003e println!(\"{:#?}\", config),\n       Err(error) =\u003e panic!(\"{:#?}\", error)\n    }\n}\n```\n\nthe expectation would then be to export the same environment variables prefixed with `APP_`\n\n```bash\n$ APP_FOO=8080 APP_BAR=true APP_BAZ=hello yourapp\n```\n\n\u003e 👭 Consider this crate a cousin of [envy-store](https://github.com/softprops/envy-store), a crate for deserializing AWS parameter store values into typesafe structs and [recap](https://github.com/softprops/recap), a crate for deserializing named regex capture groups into typesafe structs.\n\nDoug Tangren (softprops) 2016-2024\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftprops%2Fenvy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoftprops%2Fenvy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftprops%2Fenvy/lists"}