atproto_codegen
Alpha. Pre-1.0 and evolving alongside at-record; expect breaking changes between 0.x releases.
Generate Gleam types, JSON codecs, and a typed XRPC client from
atproto lexicon files. Parses through the
full-fidelity atproto_lexicon
AST, lowers to a codegen-friendly view, and runs a small plugin pipeline
(types, decode-json, optional xrpc-client) over it. Unsupported defs are
reported and skipped, never emitted wrong.
Usage
gleam run -m atproto_codegen -- <lexicons_dir> <out_dir> <out_module> <nsid_prefix>[,...] [client_module]
# types + codecs only:
gleam run -m atproto_codegen -- ./lexicons ./src/my_app/gen my_app/gen com.example.myapp.,com.atproto.
# additionally generate a typed XRPC client module:
gleam run -m atproto_codegen -- ./lexicons ./src/my_app/gen my_app/gen com.example.myapp.,com.atproto. client
lexicons_diris walked recursively for*.jsonlexicon files. Vendor any external lexicons you reference (e.g.com.atproto.repo.strongRef) into it.out_moduleis the module prefix the generated code imports itself under; it must match whereout_dirsits in yoursrc/.nsid_prefixesare stripped from NSIDs when deriving module paths, socom.example.myapp.shelf.entryemits<out_dir>/shelf/entry.gleam.client_module(optional) enables thexrpc-clientplugin: one module of typed query/procedure functions overatproto_client's primitives, with a params record, generated encoders/decoders, and a per-method error union (one variant per lexicon-declared error plus transport/unknown catch-alls). Omit it and output is exactly the pre-0.2 shape.
Generated blob fields use atproto/blob from atproto_client, so projects
consuming generated code with blobs need that dependency.
Lexicon coverage
record and object defs for codecs; query and procedure defs for the
client plugin (subscriptions are skipped). Refs resolve across lexicons (a
bare NSID ref points at that lexicon's main def). knownValues string sets
map to plain String; unknown round-trips through a Dynamic passthrough.