Name | adf-lib JSON |
Version |
0.2.1
JSON |
| download |
home_page | None |
Summary | A Python library for creating and manipulating ADF (Atlassian Document Format) documents |
upload_time | 2025-01-28 05:02:37 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | MIT License
Copyright (c) 2024 ADF Library
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. |
keywords |
adf
atlassian
document
format
markup
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# ADF Library
## Overview
ADF Library is a Python package for creating and manipulating ADF (Atlassian Document Format) documents. It provides a clean, type-safe API for building structured documents with support for headings, paragraphs, tables, and rich text formatting.
## Installation
```bash
pip install adf_lib
```
## Quick Start
```python
from adf_lib import ADF, Text, Table, Link
from adf_lib.constants.enums import HeadingLevel
# Create a new document
doc = ADF()
# Add a heading
doc.add(Text("My Document").heading(HeadingLevel.H1))
# Add a paragraph with formatting
doc.add(Text("This is a formatted paragraph", "strong", "em").paragraph())
# Export as dictionary
adf_dict = doc.to_dict()
```
## Core Components
### Document Structure
The ADF document is composed of various content types organized in a hierarchical structure:
```python
{
"version": 1,
"type": "doc",
"content": [
# Content elements go here
]
}
```
### Content Types
The library supports the following content types:
```python
class ContentType(Enum):
TEXT = "text"
TABLE = "table"
```
### Text Types
Text content can be formatted as:
```python
class TextType(Enum):
HEADING = "heading"
PARAGRAPH = "paragraph"
```
## Detailed API Reference
### ADF Class
The main document class that serves as a container for all content.
```python
class ADF:
def __init__(self, version: int = 1, type: str = "doc")
def add(self, content: dict) -> None
def to_dict(self) -> dict
```
#### Parameters:
- `version`: Document version (default: 1)
- `type`: Document type (default: "doc")
#### Methods:
- `add(content)`: Adds a content element to the document
- `to_dict()`: Converts the document to a dictionary format
### Text Class
Handles text content with formatting.
```python
class Text:
def __init__(self, text: str, *marks: Union[str, dict])
def heading(self, level: Union[int, HeadingLevel] = HeadingLevel.H1,
local_id: Optional[str] = None) -> dict
def paragraph(self, local_id: Optional[str] = None) -> dict
```
#### Parameters:
- `text`: The text content
- `marks`: Optional formatting marks
#### Methods:
- `heading()`: Creates a heading element
- `paragraph()`: Creates a paragraph element
### Table Class
Handles table creation and manipulation.
```python
class Table:
def __init__(
self,
width: int,
is_number_column_enabled: bool = False,
layout: Union[str, TableLayout] = TableLayout.CENTER,
display_mode: Union[str, TableDisplayMode] = TableDisplayMode.DEFAULT
)
def header(self, content: List[dict], col_span: int = 1,
row_span: int = 1) -> dict
def cell(self, content: List[dict], col_span: int = 1,
row_span: int = 1) -> dict
def add_row(self, cells: List[dict]) -> None
def to_dict(self) -> dict
```
#### Parameters:
- `width`: Table width (percentage)
- `is_number_column_enabled`: Enable numbered columns
- `layout`: Table layout style
- `display_mode`: Display mode
#### Methods:
- `header()`: Creates a header cell
- `cell()`: Creates a regular cell
- `add_row()`: Adds a row to the table
- `to_dict()`: Converts table to dictionary format
### Link Class
Handles hyperlinks in the document.
```python
@dataclass
class Link:
href: str
title: Optional[str] = None
collection: Optional[str] = None
id: Optional[str] = None
occurrence_key: Optional[str] = None
```
#### Methods:
- `to_mark()`: Converts link to mark format
## Text Formatting
The library supports various text formatting options through the `MarkType` enum:
```python
class MarkType(Enum):
CODE = "code" # Code formatting
EM = "em" # Emphasis (italic)
LINK = "link" # Hyperlink
STRIKE = "strike" # Strikethrough
STRONG = "strong" # Bold
SUBSUP = "subsup" # Subscript/Superscript
UNDERLINE = "underline" # Underline
TEXT_COLOR = "textColor" # Text color
```
## Tables
Tables can be configured with different layouts and display modes:
```python
class TableLayout(Enum):
CENTER = "center"
ALIGN_START = "align-start"
class TableDisplayMode(Enum):
DEFAULT = "default"
FIXED = "fixed"
```
## Examples
### Creating a Document with Multiple Elements
```python
from adf_lib import ADF, Text, Table, Link
from adf_lib.constants.enums import HeadingLevel, TableLayout
# Create document
doc = ADF()
# Add heading
doc.add(Text("Project Report").heading(HeadingLevel.H1))
# Add paragraph with formatting
doc.add(Text("Executive Summary", "strong").paragraph())
# Add link
link = Link(href="https://example.com", title="More Info")
doc.add(Text("See details here", link.to_mark()).paragraph())
# Create table
table = Table(
width=100,
is_number_column_enabled=True,
layout=TableLayout.CENTER
)
# Add table header
table.add_row([
table.header([Text("Category").paragraph()]),
table.header([Text("Value").paragraph()])
])
# Add table data
table.add_row([
table.cell([Text("Revenue").paragraph()]),
table.cell([Text("$100,000").paragraph()])
])
# Add table to document
doc.add(table.to_dict())
# Convert to dictionary
result = doc.to_dict()
```
### Advanced Text Formatting
```python
# Multiple formatting marks
doc.add(Text("Important Notice", "strong", "underline").paragraph())
# Colored text
doc.add(Text("Warning", {"type": "textColor", "attrs": {"color": "#FF0000"}}).paragraph())
# Combined formatting
doc.add(Text("Critical Update", "strong", "em", {"type": "textColor", "attrs": {"color": "#FF0000"}}).paragraph())
```
## Error Handling
The library includes custom exceptions for validation:
```python
from adf_lib.exceptions.validation import ValidationError, RequiredFieldError, InvalidMarkError
try:
Text("").paragraph() # Empty text
except RequiredFieldError:
print("Text content is required")
try:
Text("Hello", "invalid_mark").paragraph() # Invalid mark
except InvalidMarkError:
print("Invalid mark type")
```
## Best Practices
1. **Document Structure**
- Start documents with a heading
- Use appropriate heading levels (H1 -> H6)
- Group related content in sections
2. **Text Formatting**
- Use semantic formatting (e.g., `strong` for importance)
- Avoid overusing text colors
- Combine marks judiciously
3. **Tables**
- Use headers for better structure
- Keep tables simple and readable
- Use appropriate widths for content
4. **Error Handling**
- Always handle potential exceptions
- Validate user input before creating elements
- Check required fields
Raw data
{
"_id": null,
"home_page": null,
"name": "adf-lib",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "adf, atlassian, document, format, markup",
"author": null,
"author_email": "Dimuthu Lakmal <info@lakmal.dev>",
"download_url": "https://files.pythonhosted.org/packages/1f/94/14c06fc09138a87781622219485a880b93652772c146c3204d7d87f24535/adf_lib-0.2.1.tar.gz",
"platform": null,
"description": "# ADF Library\n\n## Overview\nADF Library is a Python package for creating and manipulating ADF (Atlassian Document Format) documents. It provides a clean, type-safe API for building structured documents with support for headings, paragraphs, tables, and rich text formatting.\n\n## Installation\n```bash\npip install adf_lib\n```\n\n## Quick Start\n\n```python\nfrom adf_lib import ADF, Text, Table, Link\nfrom adf_lib.constants.enums import HeadingLevel\n\n# Create a new document\ndoc = ADF()\n\n# Add a heading\ndoc.add(Text(\"My Document\").heading(HeadingLevel.H1))\n\n# Add a paragraph with formatting\ndoc.add(Text(\"This is a formatted paragraph\", \"strong\", \"em\").paragraph())\n\n# Export as dictionary\nadf_dict = doc.to_dict()\n```\n\n## Core Components\n\n### Document Structure\nThe ADF document is composed of various content types organized in a hierarchical structure:\n\n```python\n{\n \"version\": 1,\n \"type\": \"doc\",\n \"content\": [\n # Content elements go here\n ]\n}\n```\n\n### Content Types\nThe library supports the following content types:\n\n```python\nclass ContentType(Enum):\n TEXT = \"text\"\n TABLE = \"table\"\n```\n\n### Text Types\nText content can be formatted as:\n\n```python\nclass TextType(Enum):\n HEADING = \"heading\"\n PARAGRAPH = \"paragraph\"\n```\n\n## Detailed API Reference\n\n### ADF Class\nThe main document class that serves as a container for all content.\n\n```python\nclass ADF:\n def __init__(self, version: int = 1, type: str = \"doc\")\n def add(self, content: dict) -> None\n def to_dict(self) -> dict\n```\n\n#### Parameters:\n- `version`: Document version (default: 1)\n- `type`: Document type (default: \"doc\")\n\n#### Methods:\n- `add(content)`: Adds a content element to the document\n- `to_dict()`: Converts the document to a dictionary format\n\n### Text Class\nHandles text content with formatting.\n\n```python\nclass Text:\n def __init__(self, text: str, *marks: Union[str, dict])\n def heading(self, level: Union[int, HeadingLevel] = HeadingLevel.H1,\n local_id: Optional[str] = None) -> dict\n def paragraph(self, local_id: Optional[str] = None) -> dict\n```\n\n#### Parameters:\n- `text`: The text content\n- `marks`: Optional formatting marks\n\n#### Methods:\n- `heading()`: Creates a heading element\n- `paragraph()`: Creates a paragraph element\n\n### Table Class\nHandles table creation and manipulation.\n\n```python\nclass Table:\n def __init__(\n self,\n width: int,\n is_number_column_enabled: bool = False,\n layout: Union[str, TableLayout] = TableLayout.CENTER,\n display_mode: Union[str, TableDisplayMode] = TableDisplayMode.DEFAULT\n )\n def header(self, content: List[dict], col_span: int = 1,\n row_span: int = 1) -> dict\n def cell(self, content: List[dict], col_span: int = 1,\n row_span: int = 1) -> dict\n def add_row(self, cells: List[dict]) -> None\n def to_dict(self) -> dict\n```\n\n#### Parameters:\n- `width`: Table width (percentage)\n- `is_number_column_enabled`: Enable numbered columns\n- `layout`: Table layout style\n- `display_mode`: Display mode\n\n#### Methods:\n- `header()`: Creates a header cell\n- `cell()`: Creates a regular cell\n- `add_row()`: Adds a row to the table\n- `to_dict()`: Converts table to dictionary format\n\n### Link Class\nHandles hyperlinks in the document.\n\n```python\n@dataclass\nclass Link:\n href: str\n title: Optional[str] = None\n collection: Optional[str] = None\n id: Optional[str] = None\n occurrence_key: Optional[str] = None\n```\n\n#### Methods:\n- `to_mark()`: Converts link to mark format\n\n## Text Formatting\nThe library supports various text formatting options through the `MarkType` enum:\n\n```python\nclass MarkType(Enum):\n CODE = \"code\" # Code formatting\n EM = \"em\" # Emphasis (italic)\n LINK = \"link\" # Hyperlink\n STRIKE = \"strike\" # Strikethrough\n STRONG = \"strong\" # Bold\n SUBSUP = \"subsup\" # Subscript/Superscript\n UNDERLINE = \"underline\" # Underline\n TEXT_COLOR = \"textColor\" # Text color\n```\n\n## Tables\nTables can be configured with different layouts and display modes:\n\n```python\nclass TableLayout(Enum):\n CENTER = \"center\"\n ALIGN_START = \"align-start\"\n\nclass TableDisplayMode(Enum):\n DEFAULT = \"default\"\n FIXED = \"fixed\"\n```\n\n## Examples\n\n### Creating a Document with Multiple Elements\n\n```python\nfrom adf_lib import ADF, Text, Table, Link\nfrom adf_lib.constants.enums import HeadingLevel, TableLayout\n\n# Create document\ndoc = ADF()\n\n# Add heading\ndoc.add(Text(\"Project Report\").heading(HeadingLevel.H1))\n\n# Add paragraph with formatting\ndoc.add(Text(\"Executive Summary\", \"strong\").paragraph())\n\n# Add link\nlink = Link(href=\"https://example.com\", title=\"More Info\")\ndoc.add(Text(\"See details here\", link.to_mark()).paragraph())\n\n# Create table\ntable = Table(\n width=100,\n is_number_column_enabled=True,\n layout=TableLayout.CENTER\n)\n\n# Add table header\ntable.add_row([\n table.header([Text(\"Category\").paragraph()]),\n table.header([Text(\"Value\").paragraph()])\n])\n\n# Add table data\ntable.add_row([\n table.cell([Text(\"Revenue\").paragraph()]),\n table.cell([Text(\"$100,000\").paragraph()])\n])\n\n# Add table to document\ndoc.add(table.to_dict())\n\n# Convert to dictionary\nresult = doc.to_dict()\n```\n\n### Advanced Text Formatting\n\n```python\n# Multiple formatting marks\ndoc.add(Text(\"Important Notice\", \"strong\", \"underline\").paragraph())\n\n# Colored text\ndoc.add(Text(\"Warning\", {\"type\": \"textColor\", \"attrs\": {\"color\": \"#FF0000\"}}).paragraph())\n\n# Combined formatting\ndoc.add(Text(\"Critical Update\", \"strong\", \"em\", {\"type\": \"textColor\", \"attrs\": {\"color\": \"#FF0000\"}}).paragraph())\n```\n\n## Error Handling\nThe library includes custom exceptions for validation:\n\n```python\nfrom adf_lib.exceptions.validation import ValidationError, RequiredFieldError, InvalidMarkError\n\ntry:\n Text(\"\").paragraph() # Empty text\nexcept RequiredFieldError:\n print(\"Text content is required\")\n\ntry:\n Text(\"Hello\", \"invalid_mark\").paragraph() # Invalid mark\nexcept InvalidMarkError:\n print(\"Invalid mark type\")\n```\n\n## Best Practices\n\n1. **Document Structure**\n - Start documents with a heading\n - Use appropriate heading levels (H1 -> H6)\n - Group related content in sections\n\n2. **Text Formatting**\n - Use semantic formatting (e.g., `strong` for importance)\n - Avoid overusing text colors\n - Combine marks judiciously\n\n3. **Tables**\n - Use headers for better structure\n - Keep tables simple and readable\n - Use appropriate widths for content\n\n4. **Error Handling**\n - Always handle potential exceptions\n - Validate user input before creating elements\n - Check required fields\n",
"bugtrack_url": null,
"license": "MIT License\n \n Copyright (c) 2024 ADF Library\n \n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n \n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n \n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.",
"summary": "A Python library for creating and manipulating ADF (Atlassian Document Format) documents",
"version": "0.2.1",
"project_urls": {
"Bug Tracker": "https://github.com/lakmal98/adf-lib/issues",
"Documentation": "https://github.com/lakmal98/adf-lib",
"Homepage": "https://github.com/lakmal98/adf-lib"
},
"split_keywords": [
"adf",
" atlassian",
" document",
" format",
" markup"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "23d2dfad036dd86b4d40c6a10bd002dc970ae85a9570357d4268aadf78b3980f",
"md5": "5fea2e15601471c510d5e6712a4ccb16",
"sha256": "cf22c4392a56740fa5f1fbc213692fb24d79f47d87cb6399fe408e374f58e0d6"
},
"downloads": -1,
"filename": "adf_lib-0.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5fea2e15601471c510d5e6712a4ccb16",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 10295,
"upload_time": "2025-01-28T05:02:36",
"upload_time_iso_8601": "2025-01-28T05:02:36.022826Z",
"url": "https://files.pythonhosted.org/packages/23/d2/dfad036dd86b4d40c6a10bd002dc970ae85a9570357d4268aadf78b3980f/adf_lib-0.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "1f9414c06fc09138a87781622219485a880b93652772c146c3204d7d87f24535",
"md5": "377d4bb679e3e4ced415eb86e9d0286b",
"sha256": "a719772dfc0fb66d842dad223d36201d436190d413ad39f2d9aa8b2e3a49b73c"
},
"downloads": -1,
"filename": "adf_lib-0.2.1.tar.gz",
"has_sig": false,
"md5_digest": "377d4bb679e3e4ced415eb86e9d0286b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 12023,
"upload_time": "2025-01-28T05:02:37",
"upload_time_iso_8601": "2025-01-28T05:02:37.278109Z",
"url": "https://files.pythonhosted.org/packages/1f/94/14c06fc09138a87781622219485a880b93652772c146c3204d7d87f24535/adf_lib-0.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-28 05:02:37",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "lakmal98",
"github_project": "adf-lib",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "adf-lib"
}