{"id":27102999,"url":"https://github.com/xcaeser/zig-dotenv","last_synced_at":"2025-07-13T01:12:31.458Z","repository":{"id":285622553,"uuid":"958774934","full_name":"xcaeser/zig-dotenv","owner":"xcaeser","description":"⚡️A powerful Zig library for loading, parsing, and managing environment variables from .env files","archived":false,"fork":false,"pushed_at":"2025-06-19T18:22:50.000Z","size":50,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-19T19:37:08.617Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Zig","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/xcaeser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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,"zenodo":null}},"created_at":"2025-04-01T18:35:04.000Z","updated_at":"2025-06-19T18:22:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"bb5db46e-e0bb-48ec-a45d-3acaf79e30b6","html_url":"https://github.com/xcaeser/zig-dotenv","commit_stats":null,"previous_names":["xcaeser/zig-dotenv"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/xcaeser/zig-dotenv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xcaeser%2Fzig-dotenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xcaeser%2Fzig-dotenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xcaeser%2Fzig-dotenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xcaeser%2Fzig-dotenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xcaeser","download_url":"https://codeload.github.com/xcaeser/zig-dotenv/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xcaeser%2Fzig-dotenv/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265077532,"owners_count":23707702,"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":[],"created_at":"2025-04-06T16:38:26.567Z","updated_at":"2025-07-13T01:12:31.450Z","avatar_url":"https://github.com/xcaeser.png","language":"Zig","readme":"# zig-dotenv\n\n\u003cdiv\u003e\n\nA powerful Zig library for loading, parsing, and managing environment variables from `.env` files.\n\n[![Version](https://img.shields.io/badge/Zig_Version-0.14.0-orange.svg?logo=zig)](README.md)\n[![MIT](https://img.shields.io/badge/License-MIT-lightgrey.svg?logo=cachet)](LICENSE)\n[![Version](https://img.shields.io/badge/dotenv-v0.6.3-green)](https://github.com/xcaeser/zig-dotenv/releases)\n\n\u003c/div\u003e\n\n## ✅ Features\n\n- Load environment variables from `.env` files\n- Append or write `key=value` pairs to `.env` files\n- Type-safe access using enums\n- Modify the **current process environment** (`setenv`, `SetEnvironmentVariable`)\n- Supports comments, quoted values, and whitespace trimming\n- Graceful fallback and silent error modes\n- Clean, testable API\n\n## 🚀 Usage\n\n```zig\nconst std = @import(\"std\");\nconst dotenv = @import(\"dotenv\");\n\npub const EnvKeys = enum {\n    OPENAI_API_KEY,\n    AWS_ACCESS_KEY_ID,\n    COGNITO_CLIENT_SECRET,\n    S3_BUCKET,\n};\n\nconst Env = dotenv.Env(EnvKeys);\n\npub fn main() !void {\n    var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);\n    defer arena.deinit();\n    const allocator = arena.allocator();\n\n    var env = Env.init(allocator, true);\n    defer env.deinit();\n\n    try env.load(.{ .filename = \".env.local\", .set_envs_inprocess = true, .silent = true });\n\n    const openai = env.key(.OPENAI_API_KEY);\n    std.debug.print(\"OPENAI_API_KEY={s}\\n\", .{openai});\n\n    const aws_key = env.get(\"AWS_ACCESS_KEY_ID\");\n    std.debug.print(\"AWS_ACCESS_KEY_ID={s}\\n\", .{aws_key});\n}\n```\n\n## 📄 Example `.env` File\n\n```dotenv\nOPENAI_API_KEY=sk-your-api-key-here\nAWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE\nS3_BUCKET=\"my-bucket\"\nCOGNITO_CLIENT_SECRET='abcdef123456'\n```\n\n## 📦 Installation\n\n### using `zig fetch`\n\n```bash\nzig fetch --save=dotenv https://github.com/xcaeser/zig-dotenv/archive/v0.6.3.tar.gz\n```\n\n### Add to `build.zig`\n\n```zig\nconst dotenv_dep = b.dependency(\"dotenv\", .{ .target = target, .optimize = optimize });\n\nexe.root_module.addImport(\"dotenv\", dotenv_dep.module(\"dotenv\"));\n\n// Optional: add for unit tests\nexe_unit_tests.root_module.addImport(\"dotenv\", dotenv_dep.module(\"dotenv\"));\n```\n\n## 📚 API Summary\n\n### `Env(EnvKey)` type\n\nA reusable struct for managing environment variables:\n\n| Method                                                  | Description                                   |\n| ------------------------------------------------------- | --------------------------------------------- |\n| `init(allocator, includeCurrentProcessEnvs)`            | Initializes a new Env manager                 |\n| `deinit()`                                              | Frees all allocated memory                    |\n| `load(.{ filename, set_envs_inprocess, silent })`       | Loads variables from a `.env` file            |\n| `parse(content)`                                        | Parses raw `.env`-formatted text              |\n| `get(\"KEY\")`                                            | Get a value by string key (panics if missing) |\n| `key(.ENUM_KEY)`                                        | Get a value by enum key (panics if missing)   |\n| `setProcessEnv(\"KEY\", \"VALUE\")`                         | Set or unset environment variable             |\n| `writeAllEnvPairs(writer, includeSystemVars)`           | Write all variables to a writer               |\n| `writeEnvPairToFile(\"KEY\", \"VALUE\", optional_filename)` | Append a `key=value` line to a file           |\n\n## 🧪 Testing\n\nRun:\n\n```bash\nzig build test\n```\n\nIncludes tests for parsing, file I/O, process environment setting, and edge cases.\n\n## 🤝 Contributing\n\nIssues and PRs welcome! Star the repo if it helped you.\n\n## 📝 License\n\nMIT – see [LICENSE](LICENSE).\n","funding_links":[],"categories":["Fundamentals"],"sub_categories":["Utility"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxcaeser%2Fzig-dotenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxcaeser%2Fzig-dotenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxcaeser%2Fzig-dotenv/lists"}