A simple, powerful standard for structured content that works beautifully with LLMs, humans, and modern editors
Project description
BlockDoc
A simple, powerful standard for structured content that works beautifully with LLMs, humans, and modern editors.
Why BlockDoc?
BlockDoc provides a lightweight, flexible format for structured content that is:
- LLM-friendly: Optimized for AI generation and targeted modifications
- Simple: Flat structure with semantic IDs and minimal nesting
- Extensible: Core block types with room for custom extensions
- Framework-agnostic: Works with any frontend or backend technology
- Database-ready: Easy to store and query in SQL or NoSQL databases
Core Concepts
BlockDoc is based on a block-based architecture where content is organized into discrete, individually addressable blocks. Each block has:
- A semantic ID (like 'intro', 'section-1')
- A block type ('text', 'heading', 'image', 'code')
- Content (in Markdown for text-based blocks)
- Optional metadata
This architecture enables:
- Targeted updates to specific sections
- Better organization of content
- Easy integration with LLMs
- Flexible rendering in different formats
Core Block Types
- Text - Standard paragraphs with Markdown support
- Heading - Section headers with configurable levels
- Image - Pictures with src, alt text, and optional caption
- Code - Code blocks with syntax highlighting
- List - Ordered or unordered lists
- Quote - Blockquote content
- Embed - Embedded content (videos, social media posts)
- Divider - Horizontal rule/separator
Design Principles
- Simplicity: Minimal structure with only necessary properties
- LLM-Friendly: Optimized for AI content generation and modification
- Human-Editable: Clear, readable format for direct editing
- Database-Ready: Easily stored in SQL or NoSQL databases
- Extensible: Core types with support for custom block types
- Semantic: Meaningful IDs for blocks rather than auto-generated IDs
- Portable: Framework-agnostic with multiple render targets
{
"article": {
"title": "Getting Started with BlockDoc",
"blocks": [
{
"id": "intro",
"type": "text",
"content": "BlockDoc makes structured content **simple**."
},
{
"id": "first-steps",
"type": "heading",
"level": 2,
"content": "First Steps"
},
{
"id": "step-one",
"type": "text",
"content": "Install BlockDoc using pip: `pip install blockdoc`"
}
]
}
}
Installation
Install BlockDoc from PyPI:
pip install blockdoc
Usage
from blockdoc import BlockDocDocument, Block
# Create a new document
doc = BlockDocDocument({
"title": "My First BlockDoc Post",
})
# Add blocks using factory methods
doc.add_block(Block.text("intro", "Welcome to my first post!"))
doc.add_block(Block.heading("section-1", 2, "Getting Started"))
doc.add_block(Block.text("content-1", "This is **formatted** content with [links](https://example.com)."))
# Render to HTML
html = doc.render_to_html()
print(html)
# Render to Markdown
markdown = doc.render_to_markdown()
print(markdown)
# Export to JSON
json_str = doc.to_json()
print(json_str)
Working with LLMs
BlockDoc shines when generating or modifying content with LLMs:
from blockdoc import BlockDocDocument
import openai
# Update a specific section using an LLM
async def update_section(document, block_id, prompt):
block = document.get_block(block_id)
response = await openai.chat.completions.create(
model="gpt-4",
messages=[
{
"role": "system",
"content": f"Update the following content to {prompt}. Return only the updated content."
},
{
"role": "user",
"content": block["content"],
},
],
)
document.update_block(block_id, {
"content": response.choices[0].message.content,
})
return document
Documentation
Specification
API Reference
Tutorials
Examples
Development
Installation
# Clone the repository
git clone https://github.com/berrydev-ai/blockdoc-python.git
cd blockdoc-python
# Create a virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install development dependencies
pip install -e ".[dev]"
Testing
BlockDoc uses pytest for testing. To run the tests:
# Run tests
pytest
# Run tests with coverage report
pytest --cov=blockdoc
# Run a specific test file
pytest tests/core/test_block.py
Contributing
We welcome contributions! See CONTRIBUTING.md for details on how to contribute, including our testing guidelines.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file blockdoc-1.0.1.tar.gz.
File metadata
- Download URL: blockdoc-1.0.1.tar.gz
- Upload date:
- Size: 57.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77f67b2dc9179011909f9bf20e5d7d3569393f2b7c61ad6d70494137bfc1a0fb
|
|
| MD5 |
f63c0b91070da24724885288caf2c815
|
|
| BLAKE2b-256 |
d6b0d045cc292ae30811cffa9dd96e4b4b2febd42a28c3964533db590e221eb0
|
File details
Details for the file blockdoc-1.0.1-py3-none-any.whl.
File metadata
- Download URL: blockdoc-1.0.1-py3-none-any.whl
- Upload date:
- Size: 19.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f5367833622a8b6ca840b241ae8bbb1e424cdd04902ad0e5f5c2cca068d11f9
|
|
| MD5 |
3c8a539c2f46758c8fc873d648296ccb
|
|
| BLAKE2b-256 |
819072fef824f2cdd74f9056661fb1ed3223e94234ef93d081a4712edaf97d6c
|