The eCFR API (https://www.ecfr.gov/api, no key): the titles list, a title's structure, a section's ancestry, version history, full-text search, and regulation text by title, part or section.

get-section and get-part are the calls to reach for when citing a rule such as 31 CFR 1010.230. They return plain text parsed from the XML; full-xml returns the XML itself.

A whole title can pass the 16 MiB response limit (http.max-response-bytes), so ask for a part, section or chapter. size on structure and ancestry nodes gives the XML size in bytes.

Dated calls take opts.date (YYYY-MM-DD). Without it they first read the title's up_to_date_as_of from the titles list, which costs one more request, so pass date in a loop.

Every function takes an optional trailing opts Map: date, the hierarchy keys subtitle, chapter, subchapter, part, subpart, section and appendix, and base-url.

Context Vars

Optional
  • ecfr.base-url

Values

DEFAULT_COLLECT_PAGE_SIZE

DEFAULT_COLLECT_PAGE_SIZE: Int 100

INLINE_TAGS

INLINE_TAGS: Str "</?(?:I|B|E|FR|AC|FTREF|strong|em)(?:\\s[^>]*)?/?>"

SKIPPED_TAGS

SKIPPED_TAGS: Vec [
  "HEAD",
  "CITA",
  "XREF"
]

Functions

ancestry

fn (title: Any): Vec?
fn (title: Any, opts: Map): Vec?

The nodes above and including a place in a title, from the title down, on opts.date. Pick the place with the hierarchy keys. Returns a Vec of nodes with identifier, label, type and size, or null when there is no such place.

Example

nodes ::ecfr/ancestry(31, {section: "1010.230"})
map(nodes, (n) { n.type })  // ["title", "subtitle", "chapter", "part", "subpart", "section"]

blocks

fn (node: Any): Vec<Str>

The paragraphs of a node's text as a Vec of Str (pure). Headings, source notes and amendment links are left out, and a table is one block with a line per row and | between cells.

Example

::ecfr/blocks(from-xml("<DIV><HEAD>Title</HEAD><P>One.</P><P>Two.</P></DIV>"))  // ["One.", "Two."]

citation-of

fn (node: Any): Str?

The citation in a node's hierarchy_metadata attribute (pure), or null. The attribute is JSON, and part responses escape it twice, so this reads the citation from either form.

Example

node from-xml("<DIV8 hierarchy_metadata=\"{&quot;citation&quot;:&quot;31 CFR 1010.230&quot;}\"/>")
::ecfr/citation-of(node)  // "31 CFR 1010.230"

collect

fn (fetch: Fn, opts: Map, limit: Int): Vec

Follow pages of a search until limit results or the last page. fetch takes opts (with page and per-page set) and returns one page. opts.per-page defaults to 100.

Example

hits ::ecfr/collect((o) { ::ecfr/search("beneficial ownership", o) }, {title: 31, date: "2026-11-02"}, 250)

dated-path

fn (kind: Str, date: Str, title: Any, ext: Str): Str

/{kind}/{date}/title-{title}.{ext} with each part encoded (pure).

Example

::ecfr/dated-path("full", "2026-11-02", 31, "xml")  // "/full/2026-11-02/title-31.xml"

find-title

fn (body: Any, title: Any): Map?

The entry for title in a titles response, or null (pure).

Example

body {titles: [{number: 31, name: "Money and Finance: Treasury"}]}
::ecfr/find-title(body, "31").name  // "Money and Finance: Treasury"
::ecfr/find-title(body, 99)  // null

flatten-inline

fn (xml: Str): Str

Remove inline markup from eCFR XML before parsing (pure), so the spaces around it survive. Superscripts become ^n, so 10<SU>6</SU> doesn't read as 106, and a <br/> becomes a space.

Example

::ecfr/flatten-inline("<P>Up to 10<SU>6</SU> <I>dollars</I></P>")  // "<P>Up to 10^6 dollars</P>"

full

fn (title: Any): Map?
fn (title: Any, opts: Map): Map?

full-xml, parsed by parse-full. Null when full-xml is.

Example

out ::ecfr/full(31, {part: "1010", subpart: "A"})
map(out.sections, (s) { s.citation })

full-xml

fn (title: Any): Str?
fn (title: Any, opts: Map): Str?

The source XML for a place in a title on opts.date, as a Str, or null when the title, place or date has none. Pick the place with the hierarchy keys.

With no hierarchy key this asks for the whole title, which can pass the 16 MiB response limit and fail with an Err. Use size from ancestry or structure to check first.

Example

xml ::ecfr/full-xml(31, {chapter: "X", part: "1010"})

get-part

fn (title: Any, part: Any): Map?
fn (title: Any, part: Any, opts: Map): Map?

One part as parsed text, or null: {type, identifier, citation, heading, authority, source, sections}. See parse-full. A blank part is an Err.

Example

part ::ecfr/get-part(31, "1010")
part.heading           // "PART 1010—GENERAL PROVISIONS"
length(part.sections)  // every section and appendix in the part

get-section

fn (title: Any, section: Any): Map?
fn (title: Any, section: Any, opts: Map): Map?

One section as parsed text, or null: {type, identifier, citation, heading, text, notes, source-note}. See parse-full. A blank section is an Err.

Example

s ::ecfr/get-section(31, "1010.230")
s.citation  // "31 CFR 1010.230"
s.text

get-title

fn (title: Any): Map?
fn (title: Any, opts: Map): Map?

One title's entry from the titles list, or null when there is none.

Example

t ::ecfr/get-title(31)
t.name
t.latest_amended_on

hierarchy-params

fn (opts: Map): Map

The hierarchy query parameters from opts (pure). A key that isn't set is null, and query-string drops it.

Example

::ecfr/hierarchy-params({part: "1010", section: "1010.230"}).section  // "1010.230"

latest-date

fn (title: Any): Str?
fn (title: Any, opts: Map): Str?

The date a title is current to (up_to_date_as_of), or null for an unknown title. Today's date often isn't available yet, so dated calls use this one.

Example

date ::ecfr/latest-date(31)

// Pass it on so later calls skip the lookup
::ecfr/get-section(31, "1010.230", {date: date})

next-page

fn (page: Any): Int?

The page number after a search page from meta (current_page < total_pages), or null on the last page (pure).

Example

::ecfr/next-page({meta: {current_page: 1, total_pages: 3}})  // 2
::ecfr/next-page({meta: {current_page: 3, total_pages: 3}})  // null

node-text

fn (node: Any): Str

All the text under an XML node with whitespace collapsed (pure). ::hot::xml/text reads only a node's direct text.

Example

::ecfr/node-text(from-xml("<P>One <NOTE>two</NOTE></P>"))  // "One two"

parse-full

fn (xml: Str): Map

Parse eCFR XML to text (pure). A section or appendix gives {type, identifier, citation, heading, text, notes, source-note}: text has paragraphs split by a blank line, notes holds eCFR's editorial notes on amendments that are pending or delayed, and source-note the Federal Register history.

Anything larger gives {type, identifier, citation, heading, authority, source, sections}, where sections lists every section and appendix in order, each with part and subpart when it has them. authority and source come from the top node, so a chapter has none.

Images are dropped, so a formula or chart set as a figure is missing from text.

Example

xml "<DIV8 N=\"1010.100\" TYPE=\"SECTION\" hierarchy_metadata=\"{&quot;citation&quot;:&quot;31 CFR 1010.100&quot;}\"><HEAD>General definitions.</HEAD><P>Terms have these meanings.</P></DIV8>"
s ::ecfr/parse-full(xml)
s.citation  // "31 CFR 1010.100"
s.text  // "Terms have these meanings."
fn (query: Str): Map
fn (query: Str, opts: Map): Map

Full-text search. Returns {results, meta}: each result has hierarchy, headings, full_text_excerpt, starts_on and ends_on, and meta has current_page, total_pages and total_count. Excerpts and headings carry <strong> around the terms that matched.

Without opts.date this searches every version, superseded ones included. Pass date for the text in force on that day. Narrow with title and the hierarchy keys; page with per-page and page.

Example

page ::ecfr/search("beneficial ownership", {title: 31, date: "2026-11-02", per-page: 10})
first(page.results).hierarchy.section  // "1010.380"

search-count

fn (query: Str): Int
fn (query: Str, opts: Map): Int

The number of results for a search, taking the same opts as search. Returns the count as an Int.

Example

::ecfr/search-count("beneficial ownership", {title: 31, date: "2026-11-02"})

search-params

fn (query: Str, opts: Map): Map

Query parameters for a search (pure): query, date, hierarchy[...] from opts.title and the hierarchy keys, and paging.

Example

params ::ecfr/search-params("beneficial ownership", {title: 31, part: "1010", per-page: 10})
params.per_page  // 10
get(params, "hierarchy[part]")  // "1010"

structure

fn (title: Any): Map?
fn (title: Any, opts: Map): Map?

A title's table of contents on opts.date: a tree of nodes with identifier, label, type, size and children, without the regulation text. Null when the title or date has none.

Example

tree ::ecfr/structure(31)
tree.label  // "Title 31—Money and Finance: Treasury"

titles

fn (): Map
fn (opts: Map): Map

All 50 titles with their currency dates. Returns {titles, meta}; each title has number, name, latest_amended_on, latest_issue_date, up_to_date_as_of and reserved.

Example

out ::ecfr/titles()
first(out.titles).name  // "General Provisions"

versions

fn (title: Any): Map
fn (title: Any, opts: Map): Map

Version history for a title, narrowed by the hierarchy keys and by opts.issue-date, issue-date-gte and issue-date-lte. Returns {content_versions, meta}. Each version has date, amendment_date, issue_date, identifier, name, substantive and removed.

Example

out ::ecfr/versions(31, {part: "1010", section: "1010.230", issue-date-gte: "2024-01-01"})
out.meta.latest_amendment_date

versions-params

fn (opts: Map): Map

Query parameters for versions (pure): the hierarchy keys and issue_date[on], [gte] and [lte] from opts.issue-date, issue-date-gte and issue-date-lte.

Example

params ::ecfr/versions-params({part: "1010", issue-date-gte: "2024-01-01"})
params.part  // "1010"
get(params, "issue_date[gte]")  // "2024-01-01"