Skip to content

Python SDK

Use URLPix from Python with the requests library.

TIP

There is no dedicated URLPix Python package yet. Use requests or httpx directly.

Screenshot

python
import requests
import os

def screenshot(url, format="png", width=1280, height=800, **kwargs):
    params = {
        "url": url,
        "format": format,
        "width": width,
        "height": height,
        **kwargs,
    }
    response = requests.get(
        "https://api.urlpix.com/v1/screenshot",
        params=params,
        headers={"X-API-Key": os.environ["URLPIX_API_KEY"]},
    )
    response.raise_for_status()
    return response.content

# Usage
image = screenshot("https://example.com", format="webp", quality=90)
with open("screenshot.webp", "wb") as f:
    f.write(image)

OG Image

python
def og_image(template, format="png", **variables):
    params = {"template": template, "format": format, **variables}
    response = requests.get(
        "https://api.urlpix.com/v1/og",
        params=params,
        headers={"X-API-Key": os.environ["URLPIX_API_KEY"]},
    )
    response.raise_for_status()
    return response.content

# Usage
image = og_image("blog-post", title="My Post", author="Jane Doe")
with open("og.png", "wb") as f:
    f.write(image)

Async (httpx)

python
import httpx
import os

async def screenshot_async(url, **params):
    async with httpx.AsyncClient() as client:
        response = await client.get(
            "https://api.urlpix.com/v1/screenshot",
            params={"url": url, **params},
            headers={"X-API-Key": os.environ["URLPIX_API_KEY"]},
        )
        response.raise_for_status()
        return response.content

Flask Example

python
from flask import Flask, request, Response
import requests
import os

app = Flask(__name__)

@app.route("/og")
def og():
    params = {
        "template": request.args.get("template", "default"),
        "title": request.args.get("title", "My Site"),
    }
    resp = requests.get(
        "https://api.urlpix.com/v1/og",
        params=params,
        headers={"X-API-Key": os.environ["URLPIX_API_KEY"]},
    )
    return Response(resp.content, content_type=resp.headers["content-type"])

URLPix — Screenshot & OG Image API