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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77d0e90651a64e93ad2f81d6829c9b89bbd2f0ad939d63aec296917ddb89856b
|
|
| MD5 |
1700766860ef7fb133cf2110377b7c67
|
|
| BLAKE2b-256 |
34a6f2e6a4ee57923417661c06d5f022db81b580307d603e0ab3fa9b839fa99d
|
Provenance
The following attestation bundles were made for dinja-0.5.0.tar.gz:
Publisher:
publish-python-manual.yml on hlop3z/dinja
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dinja-0.5.0.tar.gz -
Subject digest:
77d0e90651a64e93ad2f81d6829c9b89bbd2f0ad939d63aec296917ddb89856b - Sigstore transparency entry: 730572198
- Sigstore integration time:
-
Permalink:
hlop3z/dinja@d9e5a866e260a08168fc04f2e2cedab301a9f02e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/hlop3z
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python-manual.yml@d9e5a866e260a08168fc04f2e2cedab301a9f02e -
Trigger Event:
workflow_dispatch
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
197c1c7a99d9316ebb30d269a4b1a4371a1f2a4d023acdc4ed77e55dab41d01f
|
|
| MD5 |
167e1e574c89fa76401b59d508b94011
|
|
| BLAKE2b-256 |
36f89dc2be6f5bf4af4842aaae6fc376e9368888d4d520f1ceeae21cfba78ae4
|
Provenance
The following attestation bundles were made for dinja-0.5.0-py3-none-any.whl:
Publisher:
publish-python-manual.yml on hlop3z/dinja
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dinja-0.5.0-py3-none-any.whl -
Subject digest:
197c1c7a99d9316ebb30d269a4b1a4371a1f2a4d023acdc4ed77e55dab41d01f - Sigstore transparency entry: 730572240
- Sigstore integration time:
-
Permalink:
hlop3z/dinja@d9e5a866e260a08168fc04f2e2cedab301a9f02e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/hlop3z
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python-manual.yml@d9e5a866e260a08168fc04f2e2cedab301a9f02e -
Trigger Event:
workflow_dispatch
-
Statement type: