Skip to main content

Streamlit - Paste Button

Streamlit App Buy Me A Coffee

PyPI PyPI - Downloads GitHub

Browser Support Unsupported Browsers

Streamlit component that allows you to paste images from your clipboard into your app with a button click.


Installation instructions

pip install streamlit-paste-button

Browser support

  • The browser must support the Clipboard API.
  • Secure contexts (HTTPS) are required for clipboard access in most browsers.

API Reference

paste_image_button

Create a button that can be used to paste an image from the clipboard.

streamlit_paste_button.paste_image_button(
        label: str,
        text_color: Optional[str] = "#ffffff",
        background_color: Optional[str] = "#3498db",
        hover_background_color: Optional[str] = "#2980b9",
        key: Optional[str] = 'paste_button',
        errors: Optional[str] = 'ignore'
) -> PasteResult
  • label : str, required
    • The text to display on the button.
  • text_color : str, optional
    • The color of the text on the button.
    • Default: #ffffff
  • background_color : str, optional
    • The background color of the button.
    • Default: #3498db
  • hover_background_color : str, optional
    • The background color of the button when the mouse is hovering over it.
    • Default: #2980b9
  • key : str, optional
    • An optional string to use as the unique key for the widget.
    • Default: paste_button
  • errors : str, optional
    • Determines how errors are handled.
    • Default: ignore
    • Possible values:
      • ignore : Ignores errors.
      • raise : Display errors as st.error messages.

PasteResult

The result of a paste operation.

Attributes

  • image_data : PIL.Image.Image or None
    • The image data that was pasted.
    • If no image was pasted, this will be None.

Usage Examples

Basic Example

Create a paste button that displays the pasted image when clicked.

import streamlit as st
from streamlit_paste_button import paste_image_button as pbutton

paste_result = pbutton("📋 Paste an image")

if paste_result.image_data is not None:
    st.write('Pasted image:')
    st.image(paste_result.image_data)

Customizing the button

Create a paste button with a custom label and colors.

from streamlit_paste_button import paste_image_button as pbutton

paste_result = pbutton(
    label="📋 Paste an image",
    text_color="#ffffff",
    background_color="#FF0000",
    hover_background_color="#380909",
)

Handling errors

Create a paste button that displays errors as st.error messages.

from streamlit_paste_button import paste_image_button as pbutton

paste_result = pbutton(
    label="📋 Paste an image",
    errors="raise",
)

Converting the PasteResult

PasteResult is a PIL.Image.Image object. It can be manipulated as such.

from streamlit_paste_button import paste_image_button as pbutton
import io
import base64
import numpy as np

paste_result = pbutton("📋 Paste an image")

if paste_result.image_data is not None:
    # Convert to bytes
    img_bytes = io.BytesIO()
    paste_result.image_data.save(img_bytes, format='PNG')
    img_bytes = img_bytes.getvalue() # Image as bytes

    # Convert to base64
    img_b64 =  base64.b64encode(img_bytes).decode('utf-8') # Image as base64

    # Convert to numpy array
    img_np = np.array(paste_result.image_data) # Image as numpy array

Metadata

Release files for streamlit-paste-button 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for streamlit-paste-button 0.1.2
File Size Uploaded
streamlit-paste-button-0.1.2.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for streamlit-paste-button 0.1.2
File Interpreter ABI Platform
streamlit_paste_button-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 16.0 kB

Release files / streamlit-paste-button-0.1.2.tar.gz

Download URL streamlit-paste-button-0.1.2.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c06dfd8163bd6eeeba0dc0b8294549395594c04a2854aff899bd261942efb0f0
BLAKE2b-256 checksum
How to use checksums
e6c86a6fd631f33e054a448263a6f07b8ab5c883fa42aa41ce7da39145f5b2dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.1

Release files / streamlit_paste_button-0.1.2-py3-none-any.whl

Download URL streamlit_paste_button-0.1.2-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f65609333ec0169b088cafb5897522354207bf198511552928766b015d65bef2
BLAKE2b-256 checksum
How to use checksums
17e5a87c0f882089b2b245dd6088e490bfce7aa3b4d0c51aca836487ca0f8518
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.1

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page