{"id":25959369,"url":"https://github.com/bitlytwiser/zdotenv","last_synced_at":"2025-03-04T18:36:33.523Z","repository":{"id":279816025,"uuid":"860509955","full_name":"BitlyTwiser/zdotenv","owner":"BitlyTwiser","description":"Zdotenv - A port of Godotenv for Zig","archived":false,"fork":false,"pushed_at":"2025-02-27T15:28:40.000Z","size":145,"stargazers_count":26,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-27T22:03:09.719Z","etag":null,"topics":["dotenv","dotenv-parser","zig","ziglang"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BitlyTwiser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-09-20T15:12:28.000Z","updated_at":"2025-02-27T15:28:43.000Z","dependencies_parsed_at":"2025-02-27T22:03:14.060Z","dependency_job_id":"618e0e70-bfce-47fa-863a-a57faad9ba3b","html_url":"https://github.com/BitlyTwiser/zdotenv","commit_stats":null,"previous_names":["bitlytwiser/zdotenv"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BitlyTwiser%2Fzdotenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BitlyTwiser%2Fzdotenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BitlyTwiser%2Fzdotenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BitlyTwiser%2Fzdotenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BitlyTwiser","download_url":"https://codeload.github.com/BitlyTwiser/zdotenv/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241902168,"owners_count":20039733,"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":["dotenv","dotenv-parser","zig","ziglang"],"created_at":"2025-03-04T18:36:32.935Z","updated_at":"2025-03-04T18:36:33.510Z","avatar_url":"https://github.com/BitlyTwiser.png","language":"Zig","readme":"\u003cdiv align=\"center\"\u003e \n\n\u003cimg src=\"/assets/zdotenv.png\" width=\"450\" height=\"500\"\u003e\n\u003c/div\u003e\n\nZdotenv is a simple .env parser and a port of godotenv and ruby dotenv, but with a smidge more simplicity.\n\n### Usage:\nAdd zdotenv to your zig project:\n```\nzig fetch --save https://github.com/BitlyTwiser/zdotenv/archive/refs/tags/v0.1.1.tar.gz\n```\n\nAdd to build file:\n```\n    const zdotenv = b.dependency(\"zdotenv\", .{});\n    exe.root_module.addImport(\"zdotenv\", zdotenv.module(\"zdotenv\"));\n```\n\nZdotenv has 2 pathways:\n\n1. Absolute path to .env\n- Expects an absolute path to the .env (unix systems expect a preceding / in the path)\n```\nconst z = try Zdotenv.init(std.heap.page_allocator);\n// Must be an absolute path!\ntry z.loadFromFile(\"/home/\u003cusername\u003e/Documents/gitclones/zdotenv/test-env.env\");\n```\n\n2. relaltive path:\n- Expects the .env to be placed alongside the calling binary\n```\nconst z = try Zdotenv.init(std.heap.page_allocator);\ntry z.load();\n```\n\nExample from Main:\n```\nconst std = @import(\"std\");\nconst zdotenv = @import(\"lib.zig\");\nconst assert = std.debug.assert;\n\n///  The binary main is used for testing the package to showcase the API\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 dotenv = try zdotenv.Zdotenv.init(allocator);\n    try dotenv.load();\n\n    const env_map = try std.process.getEnvMap(allocator);\n    const pass = env_map.get(\"PASSWORD\") orelse \"foobar\";\n\n    assert(std.mem.eql(u8, pass, \"I AM ALIVE!!\"));\n}\n\n```\n\nImporting this into your own library, you will use `@import(\"zdotenv\")`. Otherwise, this would be the same :)\n\n## C usage:\nZig (at the time of this writing) does not have a solid way of directly adjusting the env variables. Doing things like:\n```\n        var env_map = std.process.getEnvMap(std.heap.page_allocator);\n        env_map.put(\"t\", \"val\");\n```\n\nwill only adjust the env map for the scope of this execution (i.e. scope of the current calling function). After function exit, the map goes back to its previous state.\n\nTherefore, we do make a C call to store the env variables that are parsed. So linking libC and running tests with ```--library c``` is needed\n\nUsing the package is as simple as the above code examples. import below using zig zon, load the .env, and access the variables as needed using std.process.EnvMap :)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitlytwiser%2Fzdotenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitlytwiser%2Fzdotenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitlytwiser%2Fzdotenv/lists"}