andf 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
andf-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,238 @@
1
+ Metadata-Version: 2.4
2
+ Name: andf
3
+ Version: 1.0.0
4
+ Summary: AI Native Document Format — self-contained HTML documents with embedded JSON, opening like a PDF in any browser
5
+ Author: ANDF Authors
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/andf-format/andf
8
+ Project-URL: Documentation, https://github.com/andf-format/andf#readme
9
+ Project-URL: Issues, https://github.com/andf-format/andf/issues
10
+ Keywords: document,format,ai,pdf,viewer,html
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Topic :: Text Processing :: Markup :: HTML
15
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
16
+ Classifier: Intended Audience :: Developers
17
+ Requires-Python: >=3.8
18
+ Description-Content-Type: text/markdown
19
+ Provides-Extra: dev
20
+ Requires-Dist: pytest>=7.0; extra == "dev"
21
+ Requires-Dist: build; extra == "dev"
22
+ Requires-Dist: twine; extra == "dev"
23
+ Dynamic: author
24
+ Dynamic: requires-python
25
+
26
+ # ANDF — AI Native Document Format
27
+
28
+ **ANDF** (`.andf`) is a document format built for AI-native workflows. Every `.andf` file is a self-contained HTML file that:
29
+
30
+ - **Opens in any browser instantly** — looks and feels like a PDF (toolbar, dark background, white pages, page numbers)
31
+ - **Is trivially parseable by AI** — structured JSON is embedded in a `<script type="application/andf+json">` tag
32
+ - **Requires no install, no server, no extension**
33
+
34
+ ---
35
+
36
+ ## Quick Start
37
+
38
+ ```python
39
+ from andf import ANDFDocument
40
+
41
+ doc = ANDFDocument()
42
+ doc.set_metadata(title="My Report", authors=["Alice"])
43
+
44
+ sec = doc.add_section("intro", "Introduction")
45
+ sec.heading("Welcome", level=2)
46
+ sec.paragraph("Hello from **ANDF**! This is *important*.")
47
+ sec.callout("Remember to save your work!", variant="tip", title="Tip")
48
+ sec.table(
49
+ headers=["Name", "Score"],
50
+ rows=[["Alice", "95"], ["Bob", "87"]],
51
+ caption="Table 1: Results",
52
+ )
53
+ sec.code("print('hello world')", language="python")
54
+
55
+ doc.save("report.andf")
56
+ doc.open_in_browser("report.andf") # opens in browser
57
+ ```
58
+
59
+ ---
60
+
61
+ ## Installation
62
+
63
+ ```bash
64
+ pip install .
65
+ ```
66
+
67
+ Or install in development mode:
68
+
69
+ ```bash
70
+ pip install -e .
71
+ ```
72
+
73
+ ---
74
+
75
+ ## CLI
76
+
77
+ ```bash
78
+ # Create a blank document
79
+ andf new output.andf
80
+
81
+ # Open in browser
82
+ andf open output.andf
83
+
84
+ # Extract embedded JSON
85
+ andf parse output.andf --pretty
86
+
87
+ # Validate format
88
+ andf validate output.andf
89
+
90
+ # Show metadata
91
+ andf info output.andf
92
+
93
+ # AI layer summary
94
+ andf ai output.andf
95
+ ```
96
+
97
+ ---
98
+
99
+ ## File Format
100
+
101
+ An `.andf` file is an HTML file. The complete document data is embedded as JSON:
102
+
103
+ ```html
104
+ <script type="application/andf+json">
105
+ {
106
+ "andf_version": "1.0",
107
+ "document_id": "...",
108
+ "metadata": { "title": "...", "authors": [...] },
109
+ "sections": [...],
110
+ "blocks": { "blk_xxx": { "type": "paragraph", "text": "..." } },
111
+ ...
112
+ }
113
+ </script>
114
+ ```
115
+
116
+ AI tools extract it with a single regex:
117
+
118
+ ```python
119
+ import re, json
120
+
121
+ pattern = re.compile(
122
+ r'<script[^>]+type=["\']application/andf\+json["\'][^>]*>(.*?)</script>',
123
+ re.DOTALL
124
+ )
125
+ data = json.loads(pattern.search(open("file.andf").read()).group(1))
126
+ ```
127
+
128
+ ---
129
+
130
+ ## Block Types
131
+
132
+ | Type | Description |
133
+ |------|-------------|
134
+ | `heading` | Section heading (levels 1–6) |
135
+ | `paragraph` | Body text with `**bold**`, `*italic*`, `` `code` ``, `[ref]` markup |
136
+ | `image` | Embedded image from assets |
137
+ | `table` | Data table with headers and rows |
138
+ | `list` | Ordered or unordered list with nesting |
139
+ | `code` | Syntax-highlighted code block |
140
+ | `quote` | Block quote with optional attribution |
141
+ | `callout` | Highlighted box: info / warning / error / success / tip |
142
+ | `separator` | Horizontal rule |
143
+ | `pagebreak` | Explicit page break |
144
+
145
+ ---
146
+
147
+ ## Themes
148
+
149
+ ```python
150
+ doc.set_theme("default") # Inter sans-serif, clean
151
+ doc.set_theme("academic") # Georgia serif, formal
152
+ doc.set_theme("corporate") # Arial, business blue headings
153
+ doc.set_theme("minimal") # System UI, minimal color
154
+ ```
155
+
156
+ ---
157
+
158
+ ## AI Layer
159
+
160
+ ```python
161
+ from andf import ANDFDocument, ANDFAILayer
162
+
163
+ doc = ANDFDocument.from_file("report.andf")
164
+ layer = ANDFAILayer(doc)
165
+
166
+ # Plain text
167
+ text = layer.full_text()
168
+
169
+ # Markdown (best for LLM input)
170
+ md = layer.to_markdown()
171
+
172
+ # RAG chunks
173
+ chunks = layer.context_chunks(max_chars=4000)
174
+
175
+ # Document summary
176
+ summary = layer.document_summary()
177
+ print(summary["key_points"])
178
+
179
+ # High-importance blocks
180
+ important = layer.blocks_by_importance(min_importance=4)
181
+ ```
182
+
183
+ ---
184
+
185
+ ## Project Structure
186
+
187
+ ```
188
+ andf/
189
+ ├── __init__.py # Public API
190
+ ├── document.py # ANDFDocument model + fluent builder
191
+ ├── renderer.py # HTML renderer
192
+ ├── parser.py # Parser + validator
193
+ ├── ai_layer.py # AI extraction layer
194
+ └── cli.py # Command-line interface
195
+
196
+ spec/
197
+ └── ANDF-1.0.md # Format specification
198
+
199
+ examples/
200
+ ├── create_examples.py
201
+ ├── research_paper.andf
202
+ ├── business_report.andf
203
+ ├── legal_contract.andf
204
+ └── technical_manual.andf
205
+
206
+ tests/
207
+ └── test_andf.py
208
+ ```
209
+
210
+ ---
211
+
212
+ ## Generate Examples
213
+
214
+ ```bash
215
+ python examples/create_examples.py
216
+ ```
217
+
218
+ Opens each `.andf` file in your browser to see the viewer.
219
+
220
+ ---
221
+
222
+ ## Run Tests
223
+
224
+ ```bash
225
+ python -m pytest tests/ -v
226
+ ```
227
+
228
+ ---
229
+
230
+ ## Specification
231
+
232
+ See [`spec/ANDF-1.0.md`](spec/ANDF-1.0.md) for the complete format specification.
233
+
234
+ ---
235
+
236
+ ## License
237
+
238
+ Apache 2.0
andf-1.0.0/README.md ADDED
@@ -0,0 +1,213 @@
1
+ # ANDF — AI Native Document Format
2
+
3
+ **ANDF** (`.andf`) is a document format built for AI-native workflows. Every `.andf` file is a self-contained HTML file that:
4
+
5
+ - **Opens in any browser instantly** — looks and feels like a PDF (toolbar, dark background, white pages, page numbers)
6
+ - **Is trivially parseable by AI** — structured JSON is embedded in a `<script type="application/andf+json">` tag
7
+ - **Requires no install, no server, no extension**
8
+
9
+ ---
10
+
11
+ ## Quick Start
12
+
13
+ ```python
14
+ from andf import ANDFDocument
15
+
16
+ doc = ANDFDocument()
17
+ doc.set_metadata(title="My Report", authors=["Alice"])
18
+
19
+ sec = doc.add_section("intro", "Introduction")
20
+ sec.heading("Welcome", level=2)
21
+ sec.paragraph("Hello from **ANDF**! This is *important*.")
22
+ sec.callout("Remember to save your work!", variant="tip", title="Tip")
23
+ sec.table(
24
+ headers=["Name", "Score"],
25
+ rows=[["Alice", "95"], ["Bob", "87"]],
26
+ caption="Table 1: Results",
27
+ )
28
+ sec.code("print('hello world')", language="python")
29
+
30
+ doc.save("report.andf")
31
+ doc.open_in_browser("report.andf") # opens in browser
32
+ ```
33
+
34
+ ---
35
+
36
+ ## Installation
37
+
38
+ ```bash
39
+ pip install .
40
+ ```
41
+
42
+ Or install in development mode:
43
+
44
+ ```bash
45
+ pip install -e .
46
+ ```
47
+
48
+ ---
49
+
50
+ ## CLI
51
+
52
+ ```bash
53
+ # Create a blank document
54
+ andf new output.andf
55
+
56
+ # Open in browser
57
+ andf open output.andf
58
+
59
+ # Extract embedded JSON
60
+ andf parse output.andf --pretty
61
+
62
+ # Validate format
63
+ andf validate output.andf
64
+
65
+ # Show metadata
66
+ andf info output.andf
67
+
68
+ # AI layer summary
69
+ andf ai output.andf
70
+ ```
71
+
72
+ ---
73
+
74
+ ## File Format
75
+
76
+ An `.andf` file is an HTML file. The complete document data is embedded as JSON:
77
+
78
+ ```html
79
+ <script type="application/andf+json">
80
+ {
81
+ "andf_version": "1.0",
82
+ "document_id": "...",
83
+ "metadata": { "title": "...", "authors": [...] },
84
+ "sections": [...],
85
+ "blocks": { "blk_xxx": { "type": "paragraph", "text": "..." } },
86
+ ...
87
+ }
88
+ </script>
89
+ ```
90
+
91
+ AI tools extract it with a single regex:
92
+
93
+ ```python
94
+ import re, json
95
+
96
+ pattern = re.compile(
97
+ r'<script[^>]+type=["\']application/andf\+json["\'][^>]*>(.*?)</script>',
98
+ re.DOTALL
99
+ )
100
+ data = json.loads(pattern.search(open("file.andf").read()).group(1))
101
+ ```
102
+
103
+ ---
104
+
105
+ ## Block Types
106
+
107
+ | Type | Description |
108
+ |------|-------------|
109
+ | `heading` | Section heading (levels 1–6) |
110
+ | `paragraph` | Body text with `**bold**`, `*italic*`, `` `code` ``, `[ref]` markup |
111
+ | `image` | Embedded image from assets |
112
+ | `table` | Data table with headers and rows |
113
+ | `list` | Ordered or unordered list with nesting |
114
+ | `code` | Syntax-highlighted code block |
115
+ | `quote` | Block quote with optional attribution |
116
+ | `callout` | Highlighted box: info / warning / error / success / tip |
117
+ | `separator` | Horizontal rule |
118
+ | `pagebreak` | Explicit page break |
119
+
120
+ ---
121
+
122
+ ## Themes
123
+
124
+ ```python
125
+ doc.set_theme("default") # Inter sans-serif, clean
126
+ doc.set_theme("academic") # Georgia serif, formal
127
+ doc.set_theme("corporate") # Arial, business blue headings
128
+ doc.set_theme("minimal") # System UI, minimal color
129
+ ```
130
+
131
+ ---
132
+
133
+ ## AI Layer
134
+
135
+ ```python
136
+ from andf import ANDFDocument, ANDFAILayer
137
+
138
+ doc = ANDFDocument.from_file("report.andf")
139
+ layer = ANDFAILayer(doc)
140
+
141
+ # Plain text
142
+ text = layer.full_text()
143
+
144
+ # Markdown (best for LLM input)
145
+ md = layer.to_markdown()
146
+
147
+ # RAG chunks
148
+ chunks = layer.context_chunks(max_chars=4000)
149
+
150
+ # Document summary
151
+ summary = layer.document_summary()
152
+ print(summary["key_points"])
153
+
154
+ # High-importance blocks
155
+ important = layer.blocks_by_importance(min_importance=4)
156
+ ```
157
+
158
+ ---
159
+
160
+ ## Project Structure
161
+
162
+ ```
163
+ andf/
164
+ ├── __init__.py # Public API
165
+ ├── document.py # ANDFDocument model + fluent builder
166
+ ├── renderer.py # HTML renderer
167
+ ├── parser.py # Parser + validator
168
+ ├── ai_layer.py # AI extraction layer
169
+ └── cli.py # Command-line interface
170
+
171
+ spec/
172
+ └── ANDF-1.0.md # Format specification
173
+
174
+ examples/
175
+ ├── create_examples.py
176
+ ├── research_paper.andf
177
+ ├── business_report.andf
178
+ ├── legal_contract.andf
179
+ └── technical_manual.andf
180
+
181
+ tests/
182
+ └── test_andf.py
183
+ ```
184
+
185
+ ---
186
+
187
+ ## Generate Examples
188
+
189
+ ```bash
190
+ python examples/create_examples.py
191
+ ```
192
+
193
+ Opens each `.andf` file in your browser to see the viewer.
194
+
195
+ ---
196
+
197
+ ## Run Tests
198
+
199
+ ```bash
200
+ python -m pytest tests/ -v
201
+ ```
202
+
203
+ ---
204
+
205
+ ## Specification
206
+
207
+ See [`spec/ANDF-1.0.md`](spec/ANDF-1.0.md) for the complete format specification.
208
+
209
+ ---
210
+
211
+ ## License
212
+
213
+ Apache 2.0
@@ -0,0 +1,52 @@
1
+ """
2
+ ANDF — AI Native Document Format
3
+ =================================
4
+ A self-contained HTML file format that looks like a PDF in the browser
5
+ and is trivially parseable by AI tools.
6
+
7
+ Quick start::
8
+
9
+ from andf import ANDFDocument
10
+
11
+ doc = ANDFDocument()
12
+ doc.set_metadata(title="My Document", authors=["Alice"])
13
+ sec = doc.add_section("intro", "Introduction")
14
+ sec.heading("Welcome", level=2)
15
+ sec.paragraph("Hello from **ANDF**!")
16
+ doc.save("output.andf")
17
+
18
+ # Open in browser
19
+ doc.open_in_browser("output.andf")
20
+
21
+ # Parse an existing file
22
+ doc2 = ANDFDocument.from_file("output.andf")
23
+
24
+ # AI extraction
25
+ from andf import ANDFAILayer
26
+ layer = ANDFAILayer(doc2)
27
+ print(layer.to_markdown())
28
+ """
29
+
30
+ from .document import ANDFDocument
31
+ from .parser import ANDFParser
32
+ from .ai_layer import ANDFAILayer
33
+
34
+
35
+ def load(path: str) -> ANDFDocument:
36
+ """Load an ANDF document from a file path."""
37
+ return ANDFDocument.from_file(path)
38
+
39
+
40
+ def save(doc: ANDFDocument, path: str) -> None:
41
+ """Save an ANDF document to a file path."""
42
+ doc.save(path)
43
+
44
+
45
+ def open_in_browser(path: str) -> None:
46
+ """Open an existing .andf file in the default browser."""
47
+ from .cli import _open_in_browser
48
+ _open_in_browser(path)
49
+
50
+
51
+ __version__ = "1.0.0"
52
+ __all__ = ["ANDFDocument", "ANDFParser", "ANDFAILayer", "load", "save", "open_in_browser"]