# Create images and PDFs in Python

> Generate an image, a PDF, or a hosted image URL from a template with the Python SDK.

Canonical: https://bannerify.co/docs/sdk/python/apis/create-image

Each method takes a template id and keyword arguments. Every argument except the template id is optional.

## Create an image

`create_image` renders the template and returns the image bytes.

<ParamField body="template_id" type="str" required>
  The template id, for example `tpl_xxx`.
</ParamField>

<ParamField body="modifications" type="list[dict]">
  The values to put into the template's layers. Each entry names a layer with `name`. Layers you leave out keep the values from the template. [Modifications](https://bannerify.co/docs/essentials/modifications) lists the fields each layer accepts.
</ParamField>

<ParamField body="format" type="str" default="png">
  The image format: `png`, `jpeg`, or `webp`.
</ParamField>

```python
result = client.create_image(
    "tpl_xxx",
    modifications=[
        {"name": "headline", "text": "Launch promo"},
        {"name": "price", "text": "$29"},
    ],
    format="webp",
)

if "error" in result:
    raise RuntimeError(result["error"]["message"])

with open("launch-promo.webp", "wb") as file:
    file.write(result["result"])
```

## Create a PDF

`create_pdf` takes the same `template_id` and `modifications`. It has no `format` argument.

```python
result = client.create_pdf(
    "tpl_invoice",
    modifications=[
        {"name": "customer", "text": "Acme Studio"},
        {
            "name": "line-items",
            "columns": ["Item", "Qty", "Total"],
            "rows": [{"Item": "Automate plan", "Qty": 1, "Total": "$29.00"}],
        },
    ],
)

if "error" in result:
    raise RuntimeError(result["error"]["message"])

with open("invoice.pdf", "wb") as file:
    file.write(result["result"])
```

## Create a stored image

`create_stored_image` renders the image, saves it on the Bannerify CDN, and returns a URL instead of the bytes. The URL starts with `https://images.bannerify.co/files/`. Use it when you want to put the link in an email, a database row, or a no-code tool.

It takes the same arguments as `create_image`.

```python
result = client.create_stored_image(
    "tpl_xxx",
    modifications=[{"name": "headline", "text": "Welcome back"}],
)

if "error" in result:
    raise RuntimeError(result["error"]["message"])

print(result["result"])
```

The Python SDK cannot send `s3Config`. To save the file to your own bucket, call [Create stored image](https://bannerify.co/docs/api-reference/endpoint/create-stored-image) over REST.

## Handle the result

All three methods return `{"result": ...}` or `{"error": ...}`. See [Handle errors](https://bannerify.co/docs/sdk/python/overview#handle-errors).

## Related

- [Previous: Python SDK](https://bannerify.co/docs/sdk/python/overview)
- [Next: Render videos in Python](https://bannerify.co/docs/sdk/python/apis/render-video)
- [Documentation index](https://bannerify.co/docs/llms.txt)
