{"id":50969514,"url":"https://github.com/minhqdao/zimit","last_synced_at":"2026-06-19T00:32:14.222Z","repository":{"id":351857835,"uuid":"1207401464","full_name":"minhqdao/zimit","owner":"minhqdao","description":"A rate limiter for Zig. Implements the GCRA (Generic Cell Rate Algorithm) with a Token-Bucket-like API.","archived":false,"fork":false,"pushed_at":"2026-04-16T19:20:22.000Z","size":50,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-16T20:33:11.912Z","etag":null,"topics":["api","atomics","backend","concurrency","gcra","library","networking","rate-limit","rate-limiter","rate-limiting","scheduler","server","throttle","throttling","token-bucket","zero-allocation","zig","zig-package","zigistry","ziglang"],"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/minhqdao.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-10T22:44:08.000Z","updated_at":"2026-04-16T19:20:26.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/minhqdao/zimit","commit_stats":null,"previous_names":["minhqdao/zimit"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/minhqdao/zimit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minhqdao%2Fzimit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minhqdao%2Fzimit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minhqdao%2Fzimit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minhqdao%2Fzimit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/minhqdao","download_url":"https://codeload.github.com/minhqdao/zimit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minhqdao%2Fzimit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34513020,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-18T02:00:06.871Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["api","atomics","backend","concurrency","gcra","library","networking","rate-limit","rate-limiter","rate-limiting","scheduler","server","throttle","throttling","token-bucket","zero-allocation","zig","zig-package","zigistry","ziglang"],"created_at":"2026-06-19T00:32:13.450Z","updated_at":"2026-06-19T00:32:14.193Z","avatar_url":"https://github.com/minhqdao.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zimit\n\nA zero-dependency GCRA-based rate limiter with a token-bucket-like API for Zig 0.16.0+.\n\n## Features\n\n- **Global limiting:** Use `GlobalLimiter` when you want a single shared limit across all requests (e.g. protect total server throughput). It's lock-free and thread-safe.\n- **Per-key rate limiting:** Each key is tracked independently (e.g. per user ID or IP address). The `RateLimiter` is **not** thread-safe. If you share it across multiple threads, you should protect it with a `std.Io.Mutex`.\n- **Blocking vs non-blocking:**\n  - `allow()` → Immediate decision\n  - `wait(io, key)` → Blocks until allowed (uses `std.Io.sleep`)\n- **Clocks:**\n  - `SystemClock` → Production (requires `std.process.Init.io`)\n  - `ManualClock` → Deterministic tests\n\n## Usage\n\n```zig\nconst std = @import(\"std\");\nconst zimit = @import(\"zimit\");\n\npub fn main(init: std.process.Init) !void {\n    const gpa = init.gpa;\n    const io = init.io;\n\n    var sys = zimit.SystemClock.init(io);\n\n    var limiter = try zimit.RateLimiter([]const u8).init(.{\n        .allocator = gpa,\n        .rate = 5,\n        .per = .second,\n        .burst = 2,\n        .clock = sys.clock(),\n    });\n    defer limiter.deinit();\n\n    const key = \"127.0.0.1\";\n\n    var i: usize = 0;\n    while (i \u003c 5) : (i += 1) {\n        switch (try limiter.allow(key)) {\n            .allowed =\u003e std.debug.print(\"allowed\\n\", .{}),\n            .denied =\u003e |d| {\n                std.debug.print(\"denied, time until allowed: {d}ms\\n\", .{d.retry_after_ms_ceil()});\n            },\n        }\n    }\n}\n\n```\nSee [examples](examples) for more.\n\n\n## Installation\n\nRun:\n\n```shell\nzig fetch --save git+https://github.com/minhqdao/zimit.git#0.2.1\n```\n\nThen in your `build.zig`:\n\n```zig\nconst zimit_dep = b.dependency(\"zimit\", .{\n    .target = target,\n    .optimize = optimize,\n});\n\nconst exe = b.addExecutable(.{\n    .name = \"yourapp\",\n    .root_module = b.createModule(.{\n        .root_source_file = b.path(\"src/main.zig\"),\n        .target = target,\n        .optimize = optimize,\n        .imports = \u0026.{\n            .{ .name = \"zimit\", .module = zimit_dep.module(\"zimit\") },\n        },\n    }),\n});\n```\n\n## License\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fminhqdao%2Fzimit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fminhqdao%2Fzimit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fminhqdao%2Fzimit/lists"}