Skip to main content

Minimal library for stackable, renderable Pydantic models

Project description

Pydantic Stack Core

Minimal library for creating stackable, renderable Pydantic models that compose into structured string outputs.

Overview

Pydantic Stack Core provides a simple foundation for building composable models that render to strings. Perfect for generating structured text, documentation, code, or any format where you need systematic composition.

Key Concepts

  • RenderablePiece: Base class for any model that renders to string
  • MetaStack: Universal container for stacking RenderablePiece models
  • generate_output_from_metastack: Function to render stacks to final output

Installation

[Installation instructions pending PyPI publication]

Quick Start

from pydantic_stack_core import RenderablePiece, MetaStack, generate_output_from_metastack

# Define custom pieces
class Title(RenderablePiece):
    text: str
    level: int = 1
    
    def render(self) -> str:
        return f"{'#' * self.level} {self.text}"

class Paragraph(RenderablePiece):
    content: str
    
    def render(self) -> str:
        return self.content

class CodeBlock(RenderablePiece):
    code: str
    language: str = "python"
    
    def render(self) -> str:
        return f"```{self.language}\n{self.code}\n```"

# Create a stack
stack = MetaStack(pieces=[
    Title(text="Getting Started", level=1),
    Paragraph(content="Here's how to use our library:"),
    CodeBlock(code="print('Hello, World!')"),
    Paragraph(content="That's it!")
])

# Generate output
output = generate_output_from_metastack(stack)
print(output)

Output:

# Getting Started
Here's how to use our library:
```python
print('Hello, World!')

That's it!


## Advanced Usage

### Custom Separators

```python
# Control spacing between pieces
stack = MetaStack(
    pieces=[...],
    separator="\n\n"  # Double newline between pieces
)

Nested Stacks

Since MetaStack is also a RenderablePiece, you can nest them:

section1 = MetaStack(pieces=[
    Title(text="Section 1", level=2),
    Paragraph(content="Section content...")
])

section2 = MetaStack(pieces=[
    Title(text="Section 2", level=2), 
    Paragraph(content="More content...")
])

document = MetaStack(pieces=[
    Title(text="Main Document", level=1),
    section1,
    section2
])

Custom Rendering Logic

class NumberedList(RenderablePiece):
    items: List[str]
    
    def render(self) -> str:
        return "\n".join(f"{i+1}. {item}" for i, item in enumerate(self.items))

class BulletList(RenderablePiece):
    items: List[str]
    
    def render(self) -> str:
        return "\n".join(f"• {item}" for item in self.items)

Use Cases

  • Documentation Generation: Create structured docs from data
  • Code Generation: Build source code from templates
  • Report Creation: Compose complex reports from components
  • Template Systems: Build flexible, reusable content templates
  • Agent Outputs: Systematic text generation for AI agents

Integration with HEAVEN Ecosystem

Pydantic Stack Core integrates with:

  • Payload Discovery: For systematic content generation workflows
  • Powerset Agents: For structured agent outputs
  • MetaStack Powerset Agent: For learning and applying stacking patterns

Development

# Clone and install for development
git clone https://github.com/sancovp/pydantic-stack-core
cd pydantic-stack-core
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black .
ruff check .

Why Stack-Based?

The stack metaphor makes composition intuitive:

  1. Sequential: Pieces render in order
  2. Nestable: Stacks can contain other stacks
  3. Separable: Control spacing between pieces
  4. Extensible: Easy to add new piece types

This approach scales from simple text formatting to complex document generation while keeping the API minimal and predictable.

License

MIT License - see LICENSE file for details.

Part of HEAVEN Ecosystem

This library is part of the HEAVEN (Hierarchical Event-based Agent-Versatile Environment Network) ecosystem for AI agent development.

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

pydantic_stack_core-0.1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydantic_stack_core-0.1.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_stack_core-0.1.0.tar.gz.

File metadata

  • Download URL: pydantic_stack_core-0.1.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pydantic_stack_core-0.1.0.tar.gz
Algorithm Hash digest
SHA256 077957ec156105b80871a801a955b3d57d0b20fb48bd4ed2d132ac33c419ecfe
MD5 62631836b82fb9205d2a0aa124c4a651
BLAKE2b-256 f82f460747176a253729c7dfae4e9af29156cd95b1c980059a0566ae47faa3cb

See more details on using hashes here.

File details

Details for the file pydantic_stack_core-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_stack_core-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e5a194839371397244e6767f92aec6967d836a1283f4dda88c4fc0cc1ebbb64d
MD5 8b9277be775ce571b6690ab5a3b25a0a
BLAKE2b-256 b3d07016de2afa6837f019a4e4896e4ebcef69f66c5a916a1f554addebee0ab7

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