Every publication on The Stacks is also available in machine-readable formats. Use these to feed a publication to an AI agent, build your own tools, or render it somewhere else. The API reference covers everything this page doesn’t, including drafts.
Get Markdown or JSON¶
Simply add .md or .json to a publication’s URL. For example:
URL | What you get |
|---|---|
The web page. | |
The publication as Markdown. The title, authors, DOI, license, and version are in YAML frontmatter at the top. | |
The publication’s full record and metadata. Currently, the content source is markdown. |
These URLs will return the latest published version.
To get an older version, put its number before the suffix, like thestacks
Here’s an example in Python that gets a publication as Markdown and as JSON:
import requests
slug = "result-chlamy-spgf"
markdown = requests.get(f"https://thestacks.org/publications/{slug}.md").text
print(markdown.split("\n---\n")[0]) # the YAML frontmatter
pub = requests.get(f"https://thestacks.org/publications/{slug}.json").json()["publication"]
print(pub["title"], pub["doi"])You can also ask for a format with the Accept header instead of a suffix:
curl -H "Accept: text/markdown" https://thestacks.org/publications/result-chlamy-spgfThe same request in Python:
import requests
response = requests.get(
"https://thestacks.org/publications/result-chlamy-spgf",
headers={"Accept": "text/markdown"},
)
print(response.headers["Content-Type"])Get the MyST AST¶
Publications written in MyST are also available as a MyST AST, the parsed document tree that thestacks.org renders.[1]
To get the AST, ask the API for a version of the publication, with the AST type in the Accept header.
The latest version number is version_number in the JSON.
Here’s an example that gets the AST of a MyST publication and prints its first few section headings:
import requests
def headings(node):
if node["type"] == "heading":
yield "".join(child.get("value", "") for child in node["children"])
for child in node.get("children", []):
yield from headings(child)
slug = "perspective-computational-fibers-white-paper"
pub = requests.get(f"https://thestacks.org/publications/{slug}.json").json()["publication"]
if pub["content"]["format"] == "myst":
url = f"https://api.thestacks.org/api/v1/publications/p/{slug}/versions/v{pub['version_number']}"
response = requests.get(url, headers={"Accept": "application/vnd.thestacks.mdast+json"})
abstract, body = response.json()["tree"]["children"]
print("\n".join(list(headings(body))[:5]))The response has these fields:
tree: the MyST AST. Its root has two blocks, the abstract and the body.citations.order: reference URLs in the order they’re cited. Acitenode’senumeratoris its position in this list, counting from 1.frontmatter.math: LaTeX macros the document’s math uses. It’s missing when there are none.
Find publications¶
Every publication is listed in
thestacks.org/sitemaps/sitemap-publications.xml.Each organization has an RSS feed of its publications at
api.thestacks.org/api/publications/rss/<org-slug>.
Here’s an example that reads the sitemap and downloads the first three publications as Markdown.
import requests
import xml.etree.ElementTree as ET
sitemap = requests.get("https://thestacks.org/sitemaps/sitemap-publications.xml")
ns = {"sm": "http://www.sitemaps.org/schemas/sitemap/0.9"}
urls = [loc.text for loc in ET.fromstring(sitemap.content).iterfind(".//sm:loc", ns)]
for url in urls[:3]:
markdown = requests.get(f"{url}.md").text
print(url, len(markdown), "characters")Publications in the Google Docs format don’t have one, so the API will return a
406error in this case. To check which type of content you have, look atcontent.formatin the JSON. For MyST publications it will be calledmyst.