Skip to main content

Orshot API SDK for Python.

Project description

Orshot API Python SDK

View on pypi.org: pypi.org/project/orshot

Installation

pip install orshot

Usage

If you don't have your API key, get one from orshot.com.

Initialise

os = orshot.Orshot('YOUR_ORSHOT_API_KEY')

Render from template

response = os.render_from_template({'template_id': 'open-graph-image-1', 'modifications': {'title': 'From python sdk new'}, 'response_type': 'base64', 'response_format': 'png'})
print(response['data'])

Generate signed URL

response = os.generate_signed_url({'template_id': 'open-graph-image-1', 'modifications': {'title': 'From python sdk new'}, 'render_type': 'images', 'response_format': 'png', 'expires_at': 1744276943})
print(response['data'])

Example

Base64 response format

import orshot

os = orshot.Orshot('os-he2jdus1cbz1dpt4mktgjyvx')
modifications = {
    'title': 'From Orshot Python SDK',
    'description': 'Create Visuals and Automate Image Generation'
}
response = os.render_from_template({ 
    'template_id': 'open-graph-image-1',
    'modifications': modifications,
    'response_type': 'base64',
    'response_format': 'png'
})
print(response)

Base64 output

{
    'data': {
        'content': 'data:image/png;base64,iVBORw0KGgoAAA',
        'format': 'png',
        'type': 'base64',
        'responseTime': 3208.03
    }
}

Binary response format

from io import BytesIO

import orshot
from PIL import Image

os = orshot.Orshot('os-he2jdus1cbz1dpt4mktgjyvx')
modifications = {
    'title': 'From Orshot Python SDK',
    'description': 'Create Visuals and Automate Image Generation'
}
response = os.render_from_template({ 
    'template_id': 'open-graph-image-1',
    'modifications': modifications,
    'response_type': 'binary',
    'response_format': 'png'
})

with Image.open(BytesIO(response.content)) as im:
    im.save('og.png')

This example writes the binary image to the file og.png

URL response format

import orshot

os = orshot.Orshot('os-he2jdus1cbz1dpt4mktgjyvx')
modifications = {
    'title': 'From Orshot Python SDK',
    'description': 'Create Visuals and Automate Image Generation'
}
response = os.render_from_template({ 
    'template_id': 'open-graph-image-1',
    'modifications': modifications,
    'response_type': 'url',
    'response_format': 'png'
})
print(response)

URL output

{
    'data': {
        'content': 'https://storage.orshot.com/00632982-fd46-44ff-9a61-f52cdf1b8e62/images/AuBgAsKzLJl.png',
        'type': 'url',
        'format': 'png',
        'responseTime': 3387.08
    }
}

Signed URL

import orshot

os = orshot.Orshot('os-he2jdus1cbz1dpt4mktgjyvx')
modifications = {
    'title': 'From Orshot Python SDK',
    'description': 'Create Visuals and Automate Image Generation'
}

response = os.generate_signed_url({ 
    'template_id': 'open-graph-image-1',
    'modifications': modifications,
    'render_type': 'images',
    'response_format': 'png',
    'expires_at': 1744276943
})
print(response)

Output

{
  "data": {
    "url": "https://api.orshot.com/v1/generate/images?expiresAt=1744276943&id=28&templateId=open-graph-image-1&title=From%20python%20sdk%20new&signature=fa4ea0aa4cf05bd9b836be031dccfc26abf41dcc623561ac262c75b658f725f1"
  }
}

render_from_template

Use this function to generate an image.

argument required description
template_id Yes ID of the template (open-graph-image-1, tweet-image-1, beautify-screenshot-1)
modifications Yes Modifications for the selected template.
response_type No base64, binary, url (Defaults to base64).
response_format No png, webp, pdf, jpg, jpeg (Defaults to png)

For available templates and their modifications refer Orshot Templates Page

generate_signed_url

Use this function to get a signed URL.

argument required description
template_id Yes ID of the template (open-graph-image-1, tweet-image-1, beautify-screenshot-1)
modifications Yes Modifications for the selected template.
expires_at Yes Expires at time in UNIX timestamp (Integer)
render_type No images, pdfs (Defaults to images).
response_format No png, webp, pdf, jpg, jpeg (Defaults to png)

Local development and testing

Install uv - https://docs.astral.sh/uv/getting-started/installation/#installation-methods

uv venv to create the virtual environment.

Uninstall before building and installing again

uv pip uninstall orshot

Build

python -m build

To install the package locally for testing

uv pip install dist/orshot-0.2.1-py3-none-any.whl

You can create a test.py file with a sample code to render an image.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

orshot-0.1.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

orshot-0.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file orshot-0.1.0.tar.gz.

File metadata

  • Download URL: orshot-0.1.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for orshot-0.1.0.tar.gz
Algorithm Hash digest
SHA256 737f945d2757772acbc344b87296c129d45302c14e319cf85d9805b281eba5f3
MD5 69902c9007b4919c22184475d55e48c8
BLAKE2b-256 2baf8b7be1238bf6b2cebb3d1dee19e17beea1fe787e0c8616773c8234e55ebb

See more details on using hashes here.

File details

Details for the file orshot-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: orshot-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for orshot-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b611b1da5ea0e5fb7df3622eb0d332625ff0074cedac5341cccbd2d923df1d4
MD5 7c56f415ffcf93a213492e385ae72887
BLAKE2b-256 6659a66bf049c5fbc434f58824f41f2066266e001e030804e5352c2819ca68ad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page