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 .

Or install in development mode:

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.0.tar.gz (29.2 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.0-py3-none-any.whl (26.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: andf-1.0.0.tar.gz
  • Upload date:
  • Size: 29.2 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.0.tar.gz
Algorithm Hash digest
SHA256 61df00f27b65734a2a7f41ad9708914dcea1455f5af0eaeacf2e6973abc0cf14
MD5 bc4609bfc5e887883e233d1071ec46dc
BLAKE2b-256 90f3a397b68669985e089e49902376be23d96f8087893f0dab0680f13e112cfc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: andf-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 26.1 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9da493dd95d343718b088fa17444e8e04b303e8caab7cd673c2258eef535ac40
MD5 a10e6fcf3396f3e10b449719c20e1e9e
BLAKE2b-256 3f597ce8734d258c56cef59d52312e9235d2d806b3aae9ae32edfb35c404bcb0

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