Python SDK — HTML to Image in Python
Install and use the official Python SDK to convert HTML to images. Render HTML to PNG, JPEG, or WebP with a few lines of Python.
The official Python SDK for RendShot. Render HTML to images and capture URL screenshots with both synchronous and async clients.
Installation
pip install rendshotRequires Python 3.9+. The SDK uses httpx as its HTTP transport.
Setup
Create a client with your API key. The base_url defaults to https://api.rendshot.ai.
from rendshot import RendshotClient
client = RendshotClient(
api_key="rs_live_YOUR_KEY",
base_url="https://api.rendshot.ai", # optional
)Both RendshotClient and AsyncRendshotClient support context managers:
with RendshotClient(api_key="rs_live_YOUR_KEY") as client:
result = client.render_image(...)Render Image
Convert HTML/CSS to a PNG or JPEG image.
from rendshot import RendshotClient, RenderImageOptions
client = RendshotClient(api_key="rs_live_YOUR_KEY")
result = client.render_image(RenderImageOptions(
html='<div style="padding:40px;background:#1a1a2e;color:#fff"><h1>Hello</h1></div>',
css="h1 { font-size: 48px; }",
width=1200,
height=630,
format="png",
quality=90,
device_scale=2,
fonts=["Inter"],
timeout=10000,
))
print(result.image_id) # image id (snake_case; equivalent to `id` in the JS SDK)
print(result.url) # https://assets.rendshot.ai/...Options
Provide either html or template_id, not both.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
html | str | Yes* | -- | HTML content to render |
template_id | str | Yes* | -- | Template ID (e.g. tpl_abc123) |
variables | dict | No | -- | Template variables as key-value pairs |
css | str | No | -- | Optional CSS styles |
width | int | No | 1080 | Image width, 1--4096 |
height | int | No | 1080 | Image height, 1--4096 |
format | "png" | "jpg" | No | "png" | Output format |
quality | int | No | 90 | JPEG quality, 1--100 |
device_scale | 1 | 2 | 3 | No | 1 | Device scale factor |
fonts | list[str] | No | -- | Custom Google Fonts to load |
timeout | int | No | 10000 | Timeout in ms, 1000--30000 |
* Provide html for raw HTML rendering, or template_id for template-based rendering.
Screenshot URL
Capture a screenshot of any public URL.
from rendshot import ScreenshotUrlOptions
result = client.screenshot_url(ScreenshotUrlOptions(
url="https://example.com",
width=1280,
height=800,
format="png",
quality=90,
full_page=False,
device_scale=2,
timeout=15000,
))
print(result.url)Options
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
url | str | Yes | -- | URL to screenshot |
width | int | No | 1280 | Viewport width, 1--4096 |
height | int | No | 800 | Viewport height, 1--4096 |
format | "png" | "jpg" | No | "png" | Output format |
quality | int | No | 90 | JPEG quality, 1--100 |
full_page | bool | No | False | Capture full scrollable page |
device_scale | 1 | 2 | 3 | No | 1 | Device scale factor |
timeout | int | No | 10000 | Timeout in ms, 1000--30000 |
Render from Template
Use a published template with variable substitution.
from rendshot import RendshotClient, RenderImageOptions
client = RendshotClient(api_key="rs_live_YOUR_KEY")
# 1. Browse available templates
result = client.list_templates(limit=10)
for t in result.templates:
print(f"{t.id}: {t.name} ({len(t.variables)} vars)")
# 2. Inspect a template's variables
template = client.get_template("tpl_abc123")
for v in template.variables:
print(f" {v.key} ({v.type}) = {v.default}")
# 3. Render with variables
image = client.render_image(RenderImageOptions(
template_id="tpl_abc123",
variables={"title": "Hello World", "bgColor": "#6B8F5E"},
))
print(image.url)Template Methods
list_templates(**kwargs)
| Parameter | Type | Description |
|---|---|---|
platform | str | Filter by platform (e.g. 'twitter') |
category | str | Filter by category |
q | str | Search by name or description |
limit | int | Max results, 1--50 (default 20) |
cursor | str | Pagination cursor |
Returns TemplateListResult with .templates and .next_cursor.
get_template(template_id)
Returns TemplateInfo with .id, .name, .variables, .width, .height, etc.
AI Render
Turn a natural-language prompt into a rendered image. See the AI Render guide for the full story.
ai_render takes prompt as a positional argument; all other parameters are keyword-only.
result = client.ai_render(
"Social card announcing a product launch, minimal layout",
platform="twitter_card", # optional preset
template_id="tpl_abc123", # optional: use existing template as style reference
width=1200,
height=630,
format="png",
locale="en", # 'zh' | 'en'
)
print(result.url) # rendered image URL
print(result.html) # AI-generated template HTML with {{placeholders}}
print(result.variables) # AI-generated variable definitionsai_render() Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
prompt | str | Yes | Natural language description, 1--2000 chars |
platform | str | No | Preset (xiaohongshu, twitter_card, og_image, …) |
template_id | str | No | Existing template ID to use as style reference |
width | int | No | Override preset width, 1--4096 |
height | int | No | Override preset height, 1--4096 |
format | "png" | "jpg" | No | Output format |
quality | int | No | JPEG quality, 1--100 |
device_scale | 1 | 2 | 3 | No | Device scale factor |
fonts | list[str] | No | Google Fonts to load |
locale | "zh" | "en" | No | Language of AI-generated text |
timeout | int | No | AI + render timeout, 1000--55000 ms |
Each ai_render call counts as one request against your monthly quota — same as render_image.
Saving the Result as a Template
result = client.ai_render("Minimal weekly digest cover", platform="xiaohongshu")
tpl = client.create_template(
name="Weekly Digest",
html=result.html,
variables=result.variables,
platform="xiaohongshu",
width=result.width,
height=result.height,
)
print(tpl.id) # "tpl_xyz789" — reuse for fast, deterministic rendersCreate Template
Create a new private draft template. Does not consume render quota. All parameters are keyword-only.
from rendshot import TemplateVariable
tpl = client.create_template(
name="Launch Card",
html='<div class="card"><h1>{{title}}</h1></div>',
variables=[
TemplateVariable(key="title", type="text", label="Title", default="Hello"),
],
platform="twitter_card",
description="Marketing launch card",
tags=["marketing", "launch"],
# visibility="private" by default — publish from the web dashboard
)
print(tpl.id) # "tpl_abc123"
print(tpl.status) # "draft"
print(tpl.visibility) # "private"create_template() Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
name | str | Yes | Template name, 1--100 chars |
html | str | Yes | HTML with {{variable}} placeholders |
variables | list[TemplateVariable] | Yes | Variable definitions |
description | str | No | Human description |
platform | str | No | Platform preset (defaults to custom) |
category | str | No | Category slug |
tags | list[str] | No | Up to 10 tags |
width | int | No | Override preset width |
height | int | No | Override preset height |
css | str | No | Extra CSS |
fonts | list[str] | No | Google Fonts to load |
visibility | "public" | "private" | No | Defaults to "private" |
Templates are always created with status="draft". Publishing is a manual action in the web dashboard.
Async Usage
Use AsyncRendshotClient for async/await workflows. The API is identical to the sync client, but all methods are async.
from rendshot import AsyncRendshotClient, RenderImageOptions, ScreenshotUrlOptions
async with AsyncRendshotClient(api_key="rs_live_YOUR_KEY") as client:
# Render HTML to image
result = await client.render_image(RenderImageOptions(
html="<h1>Hello World</h1>",
width=800,
height=400,
))
print(result.url)
# Screenshot a URL
screenshot = await client.screenshot_url(ScreenshotUrlOptions(
url="https://example.com",
full_page=True,
))
print(screenshot.url)
# AI Render
ai_result = await client.ai_render(
"Minimal product card for a premium coffee",
platform="xiaohongshu",
locale="en",
)
print(ai_result.url)
# Save the AI-generated design as a reusable template
tpl = await client.create_template(
name="Coffee Card",
html=ai_result.html,
variables=ai_result.variables,
platform="xiaohongshu",
)
print(tpl.id)Get Usage
Check your current billing period usage and plan limits.
usage = client.get_usage()
print(usage.plan) # "free" | "pro"
print(usage.month) # "2026-03"
print(usage.count) # 42
print(usage.limit) # 100Get Image Metadata
Retrieve metadata for a previously rendered image, including its expiration date.
image = client.get_image("img_abc123")
print(image.image_id) # "img_abc123"
print(image.url) # "https://assets.rendshot.ai/..."
print(image.expires_at) # "2026-04-22T00:00:00Z"Error Handling
All API errors are raised as RendshotError exceptions with structured code, status, and message properties.
from rendshot import RendshotClient, RendshotError, RenderImageOptions
client = RendshotClient(api_key="rs_live_YOUR_KEY")
try:
client.render_image(RenderImageOptions(html="<h1>Hello</h1>"))
except RendshotError as e:
print(e.code) # e.g. "RATE_LIMIT_EXCEEDED"
print(e.status) # e.g. 429
print(str(e)) # e.g. "Rate limited"Python Exports
The SDK exports the following classes and types:
| Export | Kind | Description |
|---|---|---|
RendshotClient | class | Synchronous API client |
AsyncRendshotClient | class | Async API client |
RendshotError | exception | Structured API error |
RenderImageOptions | dataclass | Options for render_image() (html or template_id) |
ScreenshotUrlOptions | dataclass | Options for screenshot_url() |
ImageResult | dataclass | Render/screenshot return value |
ImageMetadata | dataclass | get_image() return value with expires_at |
UsageResult | dataclass | get_usage() return value |
TemplateInfo | dataclass | Template metadata with variables |
TemplateVariable | dataclass | Variable definition (key, type, default, etc.) |
TemplateListResult | dataclass | list_templates() return value |
AiRenderResult | dataclass | ai_render() return value (image metadata + html + variables) |
CreatedTemplate | dataclass | create_template() return value |
Next Steps
- JavaScript SDK -- Node.js / browser client
- CLI -- Use RendShot from the command line
- MCP Server -- Integrate with Claude and AI assistants
- API Reference -- Full endpoint documentation