https://github.com/deatil/zig-dotenv
A dotenv library for zig.
https://github.com/deatil/zig-dotenv
dotenv dotenv-parser zig zig-env
Last synced: 7 months ago
JSON representation
A dotenv library for zig.
- Host: GitHub
- URL: https://github.com/deatil/zig-dotenv
- Owner: deatil
- License: apache-2.0
- Created: 2025-06-19T16:34:36.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-06-19T16:48:02.000Z (7 months ago)
- Last Synced: 2025-06-19T17:41:48.199Z (7 months ago)
- Topics: dotenv, dotenv-parser, zig, zig-env
- Language: Zig
- Homepage: https://github.com/deatil/zig-dotenv
- Size: 9.77 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-zig - zig-dotenv🗒️A parse and set env library for zig
- awesome-zig - deatil/zig-dotenv - A parse and set env library for Zig. (Tools / Utility)
README
## Zig-dotenv
A dotenv library for zig.
### Env
- Zig >= 0.15.0-dev.337+4e700fdf8
### Adding zig-dotenv as a dependency
Add the dependency to your project:
```sh
zig fetch --save=zig-dotenv git+https://github.com/deatil/zig-dotenv#main
```
or use local path to add dependency at `build.zig.zon` file
```zig
.{
.dependencies = .{
.@"zig-dotenv" = .{
.path = "./lib/zig-dotenv",
},
...
}
}
```
And the following to your `build.zig` file:
```zig
const zig_totp_dep = b.dependency("zig-dotenv", .{});
exe.root_module.addImport("zig-dotenv", zig_totp_dep.module("zig-dotenv"));
```
The `zig-dotenv` structure can be imported in your application with:
```zig
const dotenv = @import("zig-dotenv");
```
### Get Starting
~~~zig
const std = @import("std");
const dotenv = @import("zig-dotenv");
pub fn main() !void {
const alloc = std.heap.page_allocator;
const env_data =
\\FOO=abc
\\BAR="def ghi"
\\# Test
\\BAZ=xyz
;
var env = dotenv.Dotenv.init(alloc, .{});
defer env.deinit();
try env.parse(env_data);
const got_foo = env.get("FOO").?;
// output:
// dotenv got: abc
std.debug.print("dotenv got: {s} \n", .{got_foo});
}
~~~
### LICENSE
* The library LICENSE is `Apache2`, using the library need keep the LICENSE.
### Copyright
* Copyright deatil(https://github.com/deatil).