RendShot

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

terminal
pip install rendshot

Requires 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.

setup.py
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:

context_manager.py
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.

render.py
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.

ParameterTypeRequiredDefaultDescription
htmlstrYes*--HTML content to render
template_idstrYes*--Template ID (e.g. tpl_abc123)
variablesdictNo--Template variables as key-value pairs
cssstrNo--Optional CSS styles
widthintNo1080Image width, 1--4096
heightintNo1080Image height, 1--4096
format"png" | "jpg"No"png"Output format
qualityintNo90JPEG quality, 1--100
device_scale1 | 2 | 3No1Device scale factor
fontslist[str]No--Custom Google Fonts to load
timeoutintNo10000Timeout 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.

screenshot.py
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

ParameterTypeRequiredDefaultDescription
urlstrYes--URL to screenshot
widthintNo1280Viewport width, 1--4096
heightintNo800Viewport height, 1--4096
format"png" | "jpg"No"png"Output format
qualityintNo90JPEG quality, 1--100
full_pageboolNoFalseCapture full scrollable page
device_scale1 | 2 | 3No1Device scale factor
timeoutintNo10000Timeout in ms, 1000--30000

Render from Template

Use a published template with variable substitution.

template_render.py
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)

ParameterTypeDescription
platformstrFilter by platform (e.g. 'twitter')
categorystrFilter by category
qstrSearch by name or description
limitintMax results, 1--50 (default 20)
cursorstrPagination 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.

ai_render.py
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 definitions

ai_render() Parameters

ParameterTypeRequiredDescription
promptstrYesNatural language description, 1--2000 chars
platformstrNoPreset (xiaohongshu, twitter_card, og_image, …)
template_idstrNoExisting template ID to use as style reference
widthintNoOverride preset width, 1--4096
heightintNoOverride preset height, 1--4096
format"png" | "jpg"NoOutput format
qualityintNoJPEG quality, 1--100
device_scale1 | 2 | 3NoDevice scale factor
fontslist[str]NoGoogle Fonts to load
locale"zh" | "en"NoLanguage of AI-generated text
timeoutintNoAI + 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

save_as_template.py
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 renders

Create Template

Create a new private draft template. Does not consume render quota. All parameters are keyword-only.

create_template.py
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

ParameterTypeRequiredDescription
namestrYesTemplate name, 1--100 chars
htmlstrYesHTML with {{variable}} placeholders
variableslist[TemplateVariable]YesVariable definitions
descriptionstrNoHuman description
platformstrNoPlatform preset (defaults to custom)
categorystrNoCategory slug
tagslist[str]NoUp to 10 tags
widthintNoOverride preset width
heightintNoOverride preset height
cssstrNoExtra CSS
fontslist[str]NoGoogle Fonts to load
visibility"public" | "private"NoDefaults 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.

async_example.py
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.py
usage = client.get_usage()

print(usage.plan)   # "free" | "pro"
print(usage.month)  # "2026-03"
print(usage.count)  # 42
print(usage.limit)  # 100

Get Image Metadata

Retrieve metadata for a previously rendered image, including its expiration date.

metadata.py
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.

errors.py
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:

ExportKindDescription
RendshotClientclassSynchronous API client
AsyncRendshotClientclassAsync API client
RendshotErrorexceptionStructured API error
RenderImageOptionsdataclassOptions for render_image() (html or template_id)
ScreenshotUrlOptionsdataclassOptions for screenshot_url()
ImageResultdataclassRender/screenshot return value
ImageMetadatadataclassget_image() return value with expires_at
UsageResultdataclassget_usage() return value
TemplateInfodataclassTemplate metadata with variables
TemplateVariabledataclassVariable definition (key, type, default, etc.)
TemplateListResultdataclasslist_templates() return value
AiRenderResultdataclassai_render() return value (image metadata + html + variables)
CreatedTemplatedataclasscreate_template() return value

Next Steps

On this page