A simple, fast, all-in-one config loader for Zig. Supports reading dotenv, toml, yaml and os env. Fully-functional and tested on Zig 0.15.2.
- Inspired by the wonderful viper (golang). Stripes instead of fangs! 🦓
- Built to adhere to Zen of Zig.
- Reads multiple config files and write into a single, unified hashmap or struct.
- Zero external dependencies, all loaders are native to zebra's code.
- Extensive tests to ensure zebra is as compliant as possible with file format standards.
- Fetch Zebra as a dependency to your Zig project:
zig fetch --save "git+https://github.com/omkar-foss/zebra#main"- In your project's
build.zig, add Zebra as a module dependency by placing below code beforeb.installArtifact(exe);:
const zebra = b.dependency("zebra", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("zebra", zebra.module("zebra"));To try out below example, copy the file env_test.yaml to your project folder, and then update your src/main.zig as follows:
const std = @import("std");
const zebra = @import("zebra");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
var cfg: std.StringHashMap([]u8) = try zebra.core.loadAsMap(allocator, &[_][]const u8{"env_test.yaml"});
defer zebra.cleanup.deinitMap(allocator, &cfg);
std.debug.print("Output: {s}\n", .{cfg.get("person.name.first").?});
}And then run zig build run, you'll get the below output:
$ zig build run
Output: JohnRefer to integration.zig for detailed usage examples.
I'd really appreciate any help from the community towards making Zebra better. Please check out CONTRIBUTING.md to get started!
This project follows a strict no-AI policy and does not accept contributions with AI/LLM use in any form.
