API Reference
Auto-generated from source. 67 files, 607 public items.
Table of Contents
- ai.zig12
- ai/agent.zig21
- ai/chat.zig17
- ai/client.zig4
- ai/embedding.zig3
- ai/fmt.zig4
- ansi.zig15
- app.zig4
- cli.zig12
- config.zig2
- container.zig17
- context.zig15
- cron.zig13
- crypto.zig1
- csv.zig7
- dom.zig5
- dom/document.zig11
- dom/element.zig12
- dom/local_name.zig5
- dom/node.zig9
- dom/parser.zig5
- dom/text.zig2
- entities.zig5
- event.zig6
- ext.zig3
- ext/github.zig6
- ext/hackernews.zig6
- ext/reddit.zig7
- html2md.zig9
- http.zig5
- http/client.zig14
- injector.zig8
- js.zig5
- main.zig52
- meta.zig25
- middleware/cors.zig1
- middleware/logger.zig1
- middleware/static.zig2
- middleware/swagger.zig2
- mime.zig2
- monitor.zig1
- parse.zig1
- pdf.zig24
- queue.zig17
- regex.zig7
- resource.zig9
- route.zig18
- sax.zig7
- schema.zig5
- selector.zig6
- sendmail.zig4
- server.zig7
- ssr.zig19
- testing.zig10
- time.zig39
- tpl.zig8
- tui.zig10
- util.zig19
- util/bptree.zig1
- util/buf.zig1
- util/shm.zig9
- util/slotmap.zig1
- util/smolstr.zig4
- util/sparse.zig1
- visit.zig2
- vm.zig16
- yaml.zig6
ai.zig
ai/agent.zig
ai/chat.zig
ai/client.zig
ai/embedding.zig
ai/fmt.zig
ansi.zig
app.zig
cli.zig
Controls how command output is formatted (--json, --yaml, or auto-detect).
Runtime context for CLI commands. Most handlers won't need this directly since dependencies and arguments are injected into the handler function.
Parse a string value into the requested type.
Write a result to the output stream in the configured format.
A CLI command definition with name, description, and handler.
Create a command with explicit argument count. Dependencies are injected, remaining parameters are parsed from command-line arguments.
Create a command with no arguments (dependencies only).
Create a command with one argument.
Create a command with two arguments.
Create a command with three arguments.
Print usage information and available commands.
CLI entry point. Use with tk.app.run(tk.cli.run, &.{YourModule}).
config.zig
container.zig
Creates a new container from the given modules.
At comptime, this builds the dependency graph, resolves initialization order, and generates a specialized struct. At runtime, it allocates the container and initializes all dependencies in the computed order.
Destroy the container and all its dependencies (in reverse order).
Specifies how a dependency should be initialized.
Used with Bundle.provide(), Bundle.override(), and Bundle.mock() to
control dependency initialization.
This dependency should be initialized using the provided comptime value.
NOTE: If the dep type is a mutable ptr, then you can still pass a ref to a global var this way. Not recommended, but good to know.
Initialize the dependency using ptr.* = try inj.call(fun).
The function will be called at the proper time, but if you cause a cycle
you may still get a compile error.
Cycles should be avoided, but you can always define an empty initializer
for one of them, or use .value(undefined). The former is better
because you can still control the order by declaring the deps.
Initialize the dependency using try inj.callArgs(fun, .{ ptr, ...deps }).
Like with factory, if you get into a cycle, you can either adapt the
other end, or in the worst case, force undefined.
Compile-time dependency graph builder.
Registers all fields of module M as dependencies.
For each field:
- Fields with default values use
.value(default) - Fields without defaults use
.auto - Fields with an
interfacesub-field auto-register&T.interface
If there's a pub fn M.configure(*Bundle) defined, it will be called
(and it may recur). This is where you can define extra refs, register
init/deinit/compile hooks or even add more dependencies conditionally
and/or be more explicit about how it will be initialized.
Adds a single dependency with the specified initialization strategy.
Use this to add dependencies that are not module fields. The dependency
can still be overridden via override() or mocked via mock(), but any
other re-definition will result in a compile error.
Only allowed during a test run. Use this in your test module to override how some dependency should be initialized. This should not be part of your regular modules, and calling it outside of the test runner will result in a compile error.
Overrides how an existing dependency should be initialized. Works across
module boundaries (last one wins). Use this sparingly, as it can make
initialization order harder to follow. For post-initialization logic,
prefer addInitHook() instead.
Adds a reference to a struct field as a separate dependency. Use this if you need to inject ptr to some sub-part of your struct.
Registers a function to be called during comptime, when all the modules
are added and configured but before any dependency resolution. Can be
used for validation and post-processing, i.e., for walking the
[]const Route tree and checking if we have all the deps available.
Registers a function to be called during container initialization, as soon as all its deps are ready.
Registers a function to be called right before any of its deps are cleaned up. Executes in reverse order of init hooks.
Finds an existing dependency by type. Matches by base type (T.*).
context.zig
Function signature for route handlers.
Function signature for custom error handlers.
Request context for middleware and advanced handlers. Note that most route
handlers should inject dependencies directly (e.g., *tk.Request,
*tk.Response) instead.
Parse a string value into the requested type.
Reads the query parameters into a struct.
Reads the request body as JSON.
Returns the value of the given cookie or null if it doesn't exist.
Sets a cookie.
Send a response. Accepts strings, JSON-serializable values, errors, or
types with a custom sendResponse method (like EventStream).
Redirects the client to a different URL with an optional status code.
Continue to the next matching route. Used by middleware to pass control.
Continue with additional dependencies available for injection.
Wrapper type over already-initialized iterator, which will be cloned with meta.dupe() and then run in a newly created thread. Every next() result will be JSON stringified and sent as SSE event.
Options for Context.setCookie().
Map well-known errors to HTTP status codes. Returns 500 for unknown errors.
cron.zig
crypto.zig
csv.zig
dom.zig
dom/document.zig
dom/element.zig
dom/local_name.zig
dom/node.zig
dom/parser.zig
dom/text.zig
entities.zig
event.zig
ext.zig
ext/github.zig
ext/hackernews.zig
ext/reddit.zig
html2md.zig
http.zig
http/client.zig
injector.zig
Type-erased reference to a dependency.
Creates a Ref from any pointer.
Injector serves as a custom runtime scope for retrieving dependencies. It can be passed around, enabling any code to request a value or reference to a given type. Additionally, it can invoke arbitrary functions and supply the necessary dependencies automatically.
Injectors can be nested. If a dependency is not found, the parent context is searched. If the dependency is still not found, an error is returned.
Looks up a dependency by type, returning null if not found.
Get a dependency from the context.
Call a function with all the args filled-in from this scope.
Call a function with dependencies. The extra_args tuple is used to
pass additional arguments to the function. Function with anytype can
be called as long as the concrete value is provided in the extra_args.
js.zig
main.zig
meta.zig
Ptr to a comptime value, wrapped together with its type. We use this to pass around values (including a concrete fun types!) during the Bundle compilation.
middleware/cors.zig
Adds CORS headers and handles preflight requests. Note that headers cannot be removed so this should always wrapped in a group.
middleware/logger.zig
Returns a wrapper for logging all requests going through it.
middleware/static.zig
Serve static files from a directory. In debug mode, files are read from disk.
In release builds, files can be embedded if enabled via tk.setup() in build.zig.
Serve a single static file.
middleware/swagger.zig
Serve Swagger UI. Loads the UI from CDN and points it to the schema URL.
Generate OpenAPI 3.0 JSON schema from routes. Extracts path parameters, request bodies, and response types automatically.
mime.zig
Get the MIME type for a given file extension.
monitor.zig
Runs the given processes in parallel, restarting them if they exit.
The processes are tuples of the form: .{ "name", &fn, .{ ...args } }
Example: pub fn main() !void { // do some init checks and setup if needed
return monitor(.{
.{ "server", &serverFn, .{ 8080 } },
.{ "worker 1", &workerFn, .{ 1 } },
.{ "worker 2", &workerFn, .{ 2 } },
});
}
parse.zig
Parse a string value into the requested type. Supports: optional, bool, int, enum, string, and slices (comma-separated).
pdf.zig
queue.zig
A lightweight, crash-safe, at-most-once*, bounded job queue. Jobs can be scheduled in the future and if they have a key, it will be used for avoiding duplicates. There is no persistence guarantee but the queue will remain consistent even if any process dies (or is killed) at any point. It is implemented using POSIX shared memory for storage (macos/linux only) and file locking for synchronization. No broker, no database, no worker thread.
*: At-most-once applies at the API boundary. If a process is killed before
claim() returns, the item will be retrieved again by another caller,
because it was never handed over for processing.
NOTE: Atomic operations are INTENTIONAL for crash-resilience, not for lock-free access. The mutex serializes live processes, but if a process crashes mid-operation, atomics with release/acquire semantics ensure other processes see either a fully-written slot or FREE but NEVER partial state.
Initialize the queue in place. The caller must ensure self is at a
stable memory location that won't be moved after this call.
regex.zig
resource.zig
route.zig
Defines an HTTP route with method, path, handler, and optional children.
Use helper methods like get(), post(), group() to build routes.
Provides a dependency to the children routes by calling the given
factory. If there is a deinit method, it will be called at the end of
the scope.
Returns a route that sends the given, comptime response.
Returns a route that will redirect user somewhere else.
Groups the given routes under a common prefix. The prefix is removed from the request path before the children are called.
Creates a GET route with the given path and handler.
Creates a POST route with the given path and handler. The handler will receive the request body in the last argument.
Creates a POST route with the given path and handler but without a body.
Creates a PUT route with the given path and handler. The handler will receive the request body in the last argument.
Creates a PUT route with the given path and handler but without a body.
Creates a PATCH route with the given path and handler. The handler will receive the request body in the last argument.
Creates a PATCH route with the given path and handler but without a body.
Creates a DELETE route with the given path and handler.
Creates a group of routes from a struct type. Each pub fn will be equivalent to calling the corresponding route function with the method and path.
Path parameters extracted from a route match (e.g., :id segments).
Match a pattern against a path, extracting parameters. Returns null if no match.
sax.zig
A SAX event.
A simple SAX-style XML parser that can be used for both complete input and streaming. In the case of streaming, the returned strings are only valid until the next event.
The parser is forgiving and will attempt to parse as much as possible. It will ignore the XML header and the DOCTYPE, and it will not fail on invalid characters.
Notably, it does not perform entity decoding or unquoting of attributes. This is because many events are typically ignored, making such operations wasteful.
Create a parser for streaming input.
Create a parser for a complete input.
Returns next event or null if we reached the end of the input.
schema.zig
Returns a formatter which will print a JSON-schema for the given type.
selector.zig
sendmail.zig
server.zig
Configuration for Server.init(). Most options are passed through to httpz.
Address and port to listen on.
A simple HTTP server with dependency injection.
Initialize a new server.
Deinitialize the server.
Start listening for incoming connections.
Stop the server.
ssr.zig
testing.zig
Like std.testing.expectError() but with flipped args.
Like std.testing.expectEqual() but with flipped args and support for strings and optionals.
Attempts to print arg into a buf and then compare those strings.
Shorthand for MockClient.init() + &mock.interface
time.zig
Units for Time operations (includes time-of-day components).
Units for Date operations (calendar components only).
Returns true if the given year is a leap year in the Gregorian calendar.
Calendar date (year, month, day) without time-of-day or timezone. Uses Rata Die algorithm internally for efficient date arithmetic.
Create a date from year, month (1-12), and day (1-31).
Returns day of week (0 = Sunday, 1 = Monday, ..., 6 = Saturday).
UTC timestamp with second precision, stored as Unix epoch.
Provides fluent API for time manipulation: Time.now().setHour(10).add(.days, 1).
Create a Time from a Unix timestamp (seconds since 1970-01-01 00:00:00 UTC).
Get the current time.
tpl.zig
tui.zig
util.zig
util/bptree.zig
util/buf.zig
util/shm.zig
Cross-process mutex which works reliably on Linux/macOS even after crash. Also thread-safe within a single process via std.Thread.Mutex.
Opens or creates a shared memory segment. The size must be page-aligned.
Returns with created = true if this call created the segment (caller
should initialize it), or created = false if it already existed.
Unmaps and closes the shared memory segment.
NOTE: This does NOT unlink the segment - it persists in the system until
explicitly unlinked via Shm.unlink() or until system reboot. This is
intentional: it allows other processes to continue using the segment and
preserves data across process restarts.