streamlit-paste-button


Namestreamlit-paste-button JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/olucaslopes/streamlit-paste-button
SummaryStreamlit component that allows you to paste images from your clipboard into your app with a button click
upload_time2024-01-10 07:14:47
maintainer
docs_urlNone
authorLucas Lopes Amorim
requires_python>=3.7
licenseMIT
keywords streamlit component paste image clipboard
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Streamlit - Paste Button

[![Streamlit App](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://paste-button.streamlit.app/)
<a href="https://www.buymeacoffee.com/olucaslopes" target="_blank"><img align="right" src="https://raw.githubusercontent.com/olucaslopes/streamlit-paste-button/main/docs/img/coffee.jpg" alt="Buy Me A Coffee" height="50" width="180"></a><br>

[![PyPI](https://img.shields.io/pypi/v/streamlit-paste-button)](https://pypi.org/project/streamlit-paste-button/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/streamlit-paste-button)](https://pypi.org/project/streamlit-paste-button/)
![GitHub](https://img.shields.io/github/license/olucaslopes/streamlit-paste-button)

![Browser Support](https://img.shields.io/badge/Browser%20Support-Chrome%20%7C%20Safari%20%7C%20Edge-green)
![Unsupported Browsers](https://img.shields.io/badge/Unsupported%20Browsers-Firefox%20%7C%20Mobile%20Browsers-red)


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

<div align="center">
  <img src="https://raw.githubusercontent.com/olucaslopes/streamlit-paste-button/main/docs/img/demo.gif"><br>
</div>

## Installation instructions 

```sh
pip install streamlit-paste-button
```

## Browser support
- The browser must support the [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/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.

```python
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.

```python
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.

```python
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.

```python
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
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/olucaslopes/streamlit-paste-button",
    "name": "streamlit-paste-button",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "streamlit,component,paste,image,clipboard",
    "author": "Lucas Lopes Amorim",
    "author_email": "lucaslopesamorim@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e6/c8/6a6fd631f33e054a448263a6f07b8ab5c883fa42aa41ce7da39145f5b2dc/streamlit-paste-button-0.1.2.tar.gz",
    "platform": null,
    "description": "# Streamlit - Paste Button\n\n[![Streamlit App](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://paste-button.streamlit.app/)\n<a href=\"https://www.buymeacoffee.com/olucaslopes\" target=\"_blank\"><img align=\"right\" src=\"https://raw.githubusercontent.com/olucaslopes/streamlit-paste-button/main/docs/img/coffee.jpg\" alt=\"Buy Me A Coffee\" height=\"50\" width=\"180\"></a><br>\n\n[![PyPI](https://img.shields.io/pypi/v/streamlit-paste-button)](https://pypi.org/project/streamlit-paste-button/)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/streamlit-paste-button)](https://pypi.org/project/streamlit-paste-button/)\n![GitHub](https://img.shields.io/github/license/olucaslopes/streamlit-paste-button)\n\n![Browser Support](https://img.shields.io/badge/Browser%20Support-Chrome%20%7C%20Safari%20%7C%20Edge-green)\n![Unsupported Browsers](https://img.shields.io/badge/Unsupported%20Browsers-Firefox%20%7C%20Mobile%20Browsers-red)\n\n\nStreamlit component that allows you to paste images from your clipboard into your app with a button click.\n\n<div align=\"center\">\n  <img src=\"https://raw.githubusercontent.com/olucaslopes/streamlit-paste-button/main/docs/img/demo.gif\"><br>\n</div>\n\n## Installation instructions \n\n```sh\npip install streamlit-paste-button\n```\n\n## Browser support\n- The browser must support the [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API).\n- Secure contexts (HTTPS) are required for clipboard access in most browsers. \n\n\n## API Reference\n\n### `paste_image_button`\n\nCreate a button that can be used to paste an image from the clipboard.\n\n```\nstreamlit_paste_button.paste_image_button(\n        label: str,\n        text_color: Optional[str] = \"#ffffff\",\n        background_color: Optional[str] = \"#3498db\",\n        hover_background_color: Optional[str] = \"#2980b9\",\n        key: Optional[str] = 'paste_button',\n        errors: Optional[str] = 'ignore'\n) -> PasteResult\n```\n\n- `label` : str, required\n    - The text to display on the button.\n- `text_color` : str, optional\n    - The color of the text on the button.\n    - Default: `#ffffff`\n- `background_color` : str, optional\n    - The background color of the button.\n    - Default: `#3498db`\n- `hover_background_color` : str, optional\n    - The background color of the button when the mouse is hovering over it.\n    - Default: `#2980b9`\n- `key` : str, optional\n    - An optional string to use as the unique key for the widget.\n    - Default: `paste_button`\n- `errors` : str, optional\n    - Determines how errors are handled.\n    - Default: `ignore`\n    - Possible values:\n        - `ignore` : Ignores errors.\n        - `raise` : Display errors as `st.error` messages.\n\n### `PasteResult`\n\nThe result of a paste operation.\n\n#### Attributes\n- `image_data` : PIL.Image.Image or None\n    - The image data that was pasted.\n    - If no image was pasted, this will be `None`.\n\n\n\n## Usage Examples\n\n### Basic Example\n\nCreate a paste button that displays the pasted image when clicked.\n\n```python\nimport streamlit as st\nfrom streamlit_paste_button import paste_image_button as pbutton\n\npaste_result = pbutton(\"\ud83d\udccb Paste an image\")\n\nif paste_result.image_data is not None:\n    st.write('Pasted image:')\n    st.image(paste_result.image_data)\n```\n\n### Customizing the button\n\nCreate a paste button with a custom label and colors.\n\n```python\nfrom streamlit_paste_button import paste_image_button as pbutton\n\npaste_result = pbutton(\n    label=\"\ud83d\udccb Paste an image\",\n    text_color=\"#ffffff\",\n    background_color=\"#FF0000\",\n    hover_background_color=\"#380909\",\n)\n```\n\n### Handling errors\n\nCreate a paste button that displays errors as `st.error` messages.\n\n```python\nfrom streamlit_paste_button import paste_image_button as pbutton\n\npaste_result = pbutton(\n    label=\"\ud83d\udccb Paste an image\",\n    errors=\"raise\",\n)\n```\n\n### Converting the PasteResult\n\nPasteResult is a PIL.Image.Image object. It can be manipulated as such.\n\n```python\nfrom streamlit_paste_button import paste_image_button as pbutton\nimport io\nimport base64\nimport numpy as np\n\npaste_result = pbutton(\"\ud83d\udccb Paste an image\")\n\nif paste_result.image_data is not None:\n    # Convert to bytes\n    img_bytes = io.BytesIO()\n    paste_result.image_data.save(img_bytes, format='PNG')\n    img_bytes = img_bytes.getvalue() # Image as bytes\n\n    # Convert to base64\n    img_b64 =  base64.b64encode(img_bytes).decode('utf-8') # Image as base64\n\n    # Convert to numpy array\n    img_np = np.array(paste_result.image_data) # Image as numpy array\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Streamlit component that allows you to paste images from your clipboard into your app with a button click",
    "version": "0.1.2",
    "project_urls": {
        "Documentation": "https://github.com/olucaslopes/streamlit-paste-button/blob/main/README.md",
        "Homepage": "https://github.com/olucaslopes/streamlit-paste-button",
        "Issue Tracker": "https://github.com/olucaslopes/streamlit-paste-button/issues"
    },
    "split_keywords": [
        "streamlit",
        "component",
        "paste",
        "image",
        "clipboard"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "17e5a87c0f882089b2b245dd6088e490bfce7aa3b4d0c51aca836487ca0f8518",
                "md5": "e33addaea0732e57181d92e41575897c",
                "sha256": "f65609333ec0169b088cafb5897522354207bf198511552928766b015d65bef2"
            },
            "downloads": -1,
            "filename": "streamlit_paste_button-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e33addaea0732e57181d92e41575897c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7912,
            "upload_time": "2024-01-10T07:14:45",
            "upload_time_iso_8601": "2024-01-10T07:14:45.490931Z",
            "url": "https://files.pythonhosted.org/packages/17/e5/a87c0f882089b2b245dd6088e490bfce7aa3b4d0c51aca836487ca0f8518/streamlit_paste_button-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e6c86a6fd631f33e054a448263a6f07b8ab5c883fa42aa41ce7da39145f5b2dc",
                "md5": "2c178053cdfed62b89677f809cdbf538",
                "sha256": "c06dfd8163bd6eeeba0dc0b8294549395594c04a2854aff899bd261942efb0f0"
            },
            "downloads": -1,
            "filename": "streamlit-paste-button-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "2c178053cdfed62b89677f809cdbf538",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 8074,
            "upload_time": "2024-01-10T07:14:47",
            "upload_time_iso_8601": "2024-01-10T07:14:47.050234Z",
            "url": "https://files.pythonhosted.org/packages/e6/c8/6a6fd631f33e054a448263a6f07b8ab5c883fa42aa41ce7da39145f5b2dc/streamlit-paste-button-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-10 07:14:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "olucaslopes",
    "github_project": "streamlit-paste-button",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "streamlit-paste-button"
}
        
Elapsed time: 0.15978s