Metadata-Version: 2.4
Name: tiptap_python_utils
Version: 0.1.0
Summary: Python utilities for parsing, traversing, editing, and serializing TipTap JSON content.
Author: tiptap_python_utils contributors
License: MIT License
        
        Copyright (c) 2026 tiptap_python_utils contributors
        
        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.
        
Project-URL: Homepage, https://github.com/tugkanpilka/tiptap-python-utils
Project-URL: Repository, https://github.com/tugkanpilka/tiptap-python-utils
Project-URL: Issues, https://github.com/tugkanpilka/tiptap-python-utils/issues
Project-URL: Changelog, https://github.com/tugkanpilka/tiptap-python-utils/blob/main/CHANGELOG.md
Keywords: tiptap,prosemirror,json,ast,editor
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: pytest>=8; extra == "dev"
Requires-Dist: twine>=5; extra == "dev"
Dynamic: license-file

# tiptap_python_utils

Python utilities for TipTap JSON content.

`tiptap_python_utils` parses TipTap documents into typed Python nodes, preserves
unknown/custom nodes for lossless round trips, and provides small helpers for
traversal, immutable edits, visible text extraction, task queries, and shared
node synchronization.

The package has no runtime dependencies.

## Install

```bash
pip install tiptap_python_utils
```

## Quick Start

```python
from tiptap_python_utils import Content, Paragraph, Text, kind

raw = {
    "type": "doc",
    "content": [
        {
            "type": "paragraph",
            "attrs": {"id": "p1"},
            "content": [{"type": "text", "text": "Old"}],
        }
    ],
}

updated = Content.require(raw).where_id("p1").text("New").dump()
```

## Typed Nodes

Build typed nodes directly and serialize them back to TipTap-compatible JSON:

```python
node = Paragraph(id="p1", content=(Text(value="Hello"),))
doc = Content.wrap(node.raw())
```

Unknown/custom node types are preserved as `Unknown` nodes and round-trip without
dropping extra fields.

## Selection And Editing

Select nodes by id or TipTap kind:

```python
updated = Content.require(raw).of(kind.PARAGRAPH).attr("color", "blue").dump()
```

Selection methods return updated immutable content:

```python
updated = (
    Content.require(raw)
    .where_id("p1")
    .text("Updated")
    .attr("data-state", "reviewed")
    .dump()
)
```

## Text Extraction

Extract visible text or contextual slices:

```python
from tiptap_python_utils import Content, text_slices, visible_text, word_count

content = Content.require(raw)

plain_text = visible_text(content)
count = word_count(content)
slices = text_slices(content, context=True)
```

## Tasks

```python
from tiptap_python_utils import Content, has_open_tasks, open_tasks

content = Content.require(raw)

pending = has_open_tasks(content)
items = open_tasks(content)
```

## Public API

Common imports are available from the package root:

```python
from tiptap_python_utils import (
    Content,
    Paragraph,
    TaskItem,
    Text,
    append_node,
    has_open_tasks,
    kind,
    replace_node,
    shared_families,
    sync_shared,
    text_slices,
)
```

## Development

```bash
python -m pip install -e ".[dev]"
pytest -q
```

Build and check a release artifact:

```bash
python -m build
python -m twine check dist/*
```
