Skip to main content

AI Native Document Format — self-contained HTML documents with embedded JSON, opening like a PDF in any browser

Project description

ANDF — AI Native Document Format

ANDF (.andf) is a document format built for AI-native workflows. Every .andf file is a self-contained HTML file that:

  • Opens in any browser instantly — looks and feels like a PDF (toolbar, dark background, white pages, page numbers)
  • Is trivially parseable by AI — structured JSON is embedded in a <script type="application/andf+json"> tag
  • Requires no install, no server, no extension

Quick Start

from andf import ANDFDocument

doc = ANDFDocument()
doc.set_metadata(title="My Report", authors=["Alice"])

sec = doc.add_section("intro", "Introduction")
sec.heading("Welcome", level=2)
sec.paragraph("Hello from **ANDF**! This is *important*.")
sec.callout("Remember to save your work!", variant="tip", title="Tip")
sec.table(
    headers=["Name", "Score"],
    rows=[["Alice", "95"], ["Bob", "87"]],
    caption="Table 1: Results",
)
sec.code("print('hello world')", language="python")

doc.save("report.andf")
doc.open_in_browser("report.andf")  # opens in browser

Installation

pip install andf

For development (after cloning the repo):

pip install -e .

CLI

# Create a blank document
andf new output.andf

# Open in browser
andf open output.andf

# Extract embedded JSON
andf parse output.andf --pretty

# Validate format
andf validate output.andf

# Show metadata
andf info output.andf

# AI layer summary
andf ai output.andf

File Format

An .andf file is an HTML file. The complete document data is embedded as JSON:

<script type="application/andf+json">
{
  "andf_version": "1.0",
  "document_id": "...",
  "metadata": { "title": "...", "authors": [...] },
  "sections": [...],
  "blocks": { "blk_xxx": { "type": "paragraph", "text": "..." } },
  ...
}
</script>

AI tools extract it with a single regex:

import re, json

pattern = re.compile(
    r'<script[^>]+type=["\']application/andf\+json["\'][^>]*>(.*?)</script>',
    re.DOTALL
)
data = json.loads(pattern.search(open("file.andf").read()).group(1))

Block Types

Type Description
heading Section heading (levels 1–6)
paragraph Body text with **bold**, *italic*, `code`, [ref] markup
image Embedded image from assets
table Data table with headers and rows
list Ordered or unordered list with nesting
code Syntax-highlighted code block
quote Block quote with optional attribution
callout Highlighted box: info / warning / error / success / tip
separator Horizontal rule
pagebreak Explicit page break

Themes

doc.set_theme("default")    # Inter sans-serif, clean
doc.set_theme("academic")   # Georgia serif, formal
doc.set_theme("corporate")  # Arial, business blue headings
doc.set_theme("minimal")    # System UI, minimal color

AI Layer

from andf import ANDFDocument, ANDFAILayer

doc = ANDFDocument.from_file("report.andf")
layer = ANDFAILayer(doc)

# Plain text
text = layer.full_text()

# Markdown (best for LLM input)
md = layer.to_markdown()

# RAG chunks
chunks = layer.context_chunks(max_chars=4000)

# Document summary
summary = layer.document_summary()
print(summary["key_points"])

# High-importance blocks
important = layer.blocks_by_importance(min_importance=4)

Project Structure

andf/
├── __init__.py     # Public API
├── document.py     # ANDFDocument model + fluent builder
├── renderer.py     # HTML renderer
├── parser.py       # Parser + validator
├── ai_layer.py     # AI extraction layer
└── cli.py          # Command-line interface

spec/
└── ANDF-1.0.md     # Format specification

examples/
├── create_examples.py
├── research_paper.andf
├── business_report.andf
├── legal_contract.andf
└── technical_manual.andf

tests/
└── test_andf.py

Generate Examples

python examples/create_examples.py

Opens each .andf file in your browser to see the viewer.


Run Tests

python -m pytest tests/ -v

Specification

See spec/ANDF-1.0.md for the complete format specification.


License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

andf-1.0.3.tar.gz (29.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

andf-1.0.3-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

Details for the file andf-1.0.3.tar.gz.

File metadata

  • Download URL: andf-1.0.3.tar.gz
  • Upload date:
  • Size: 29.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for andf-1.0.3.tar.gz
Algorithm Hash digest
SHA256 9288198257ee87746a8f5c68116d1d4b342ecf182f6a379748d311477b510c73
MD5 8dc1fe8c29b8f40a7c7f0611543a4a7f
BLAKE2b-256 632c155043b54b02c763bcec4d8fcc04ff190798a45958b889f89c07ea8da003

See more details on using hashes here.

File details

Details for the file andf-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: andf-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 26.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for andf-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9783e77c2a21bc1de967ab997dcdd2b53d874329333df6ddcc0e6d86825ba6d3
MD5 3138407f8eb8a00986482f860c59c967
BLAKE2b-256 b4784f42699340fe05f85758420701f6385192520e3a6a71eaf99f946c442362

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page