Skip to main content

HTTP client for the Dinja MDX rendering service

Project description

Dinja Python Client

HTTP client for the Dinja MDX rendering service.

Installation

pip install dinja

Async Support (Optional)

For async support, install with your preferred HTTP library:

pip install dinja[httpx]    # recommended
pip install dinja[aiohttp]  # alternative

Requirements

Start the Dinja service via Docker:

docker pull ghcr.io/hlop3z/dinja:latest
docker run -p 8080:8080 ghcr.io/hlop3z/dinja:latest

Sync Usage

from dinja import Renderer

# Connect to the service
renderer = Renderer("http://localhost:8080")

# Check health
if renderer.health():
    print("Service is running!")

# Render MDX to HTML
result = renderer.html(
    views={"page.mdx": "# Hello World\n\nThis is **bold** text."},
    utils="export default { greeting: 'Hello' }",
)

# Get the output
print(result.get_output("page.mdx"))
# Output: <h1>Hello World</h1><p>This is <strong>bold</strong> text.</p>

Async Usage

import asyncio
from dinja import AsyncRenderer

async def main():
    # Use as async context manager
    async with AsyncRenderer("http://localhost:8080") as renderer:
        # Check health
        if await renderer.health():
            print("Service is running!")

        # Render MDX to HTML
        result = await renderer.html(
            views={"page.mdx": "# Hello World"},
        )
        print(result.get_output("page.mdx"))

asyncio.run(main())

Specifying Backend

# Auto-detect (uses httpx if available, then aiohttp)
renderer = AsyncRenderer("http://localhost:8080")

# Or specify explicitly
renderer = AsyncRenderer("http://localhost:8080", backend="httpx")
renderer = AsyncRenderer("http://localhost:8080", backend="aiohttp")

Render Methods

Both Renderer and AsyncRenderer support the same methods:

# Render to HTML
result = renderer.html(views={...})

# Render to JavaScript
result = renderer.javascript(views={...})

# Extract schema (component names)
result = renderer.schema(views={...})

# Render to JSON tree
result = renderer.json(views={...})

# Generic render with output format
result = renderer.render("html", views={...})

For async, just add await:

result = await renderer.html(views={...})

Components

result = renderer.html(
    views={"app.mdx": "# App\n\n<Button>Click me</Button>"},
    components={
        "Button": "export default function Component(props) { return <button>{props.children}</button>; }"
    },
)

Options

All render methods accept these parameters:

  • views: Dict mapping view names to MDX content (required)
  • components: Dict mapping component names to code (optional)
  • utils: JavaScript utilities code (optional)
  • minify: Enable minification (default: True)
  • directives: List of directive prefixes for schema extraction (optional)

Result Object

result = renderer.html(views={...})

# Check success
result.is_all_success()  # True if all files succeeded

# Get output for a file
result.get_output("page.mdx")

# Get metadata for a file
result.get_metadata("page.mdx")

# Access individual files
result.files["page.mdx"].success
result.files["page.mdx"].output
result.files["page.mdx"].metadata
result.files["page.mdx"].error  # If failed

Types

from dinja import (
    Renderer,       # Sync HTTP client class
    AsyncRenderer,  # Async HTTP client class (requires httpx or aiohttp)
    Input,          # Input dataclass
    Result,         # Batch result dataclass
    FileResult,     # Individual file result
    Component,      # Component definition
    Output,         # Type alias: "html" | "javascript" | "schema" | "json"
)

License

BSD-3-Clause

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

dinja-0.5.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

dinja-0.5.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file dinja-0.5.0.tar.gz.

File metadata

  • Download URL: dinja-0.5.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dinja-0.5.0.tar.gz
Algorithm Hash digest
SHA256 77d0e90651a64e93ad2f81d6829c9b89bbd2f0ad939d63aec296917ddb89856b
MD5 1700766860ef7fb133cf2110377b7c67
BLAKE2b-256 34a6f2e6a4ee57923417661c06d5f022db81b580307d603e0ab3fa9b839fa99d

See more details on using hashes here.

Provenance

The following attestation bundles were made for dinja-0.5.0.tar.gz:

Publisher: publish-python-manual.yml on hlop3z/dinja

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dinja-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: dinja-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dinja-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 197c1c7a99d9316ebb30d269a4b1a4371a1f2a4d023acdc4ed77e55dab41d01f
MD5 167e1e574c89fa76401b59d508b94011
BLAKE2b-256 36f89dc2be6f5bf4af4842aaae6fc376e9368888d4d520f1ceeae21cfba78ae4

See more details on using hashes here.

Provenance

The following attestation bundles were made for dinja-0.5.0-py3-none-any.whl:

Publisher: publish-python-manual.yml on hlop3z/dinja

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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