dash-file-cache


Namedash-file-cache JSON
Version 0.1.2 PyPI version JSON
download
home_pageNone
SummaryUtilities for providing convenient methods to serve cached data in Plotly-Dash or Flask.
upload_time2024-10-13 23:38:04
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License
keywords python python3 python-library dash plotly-dash python-dash flask service cache cache-service downloader file-downloads
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Dash File Cache

<p align="center">
  <a href="https://github.com/cainmagi/dash-file-cache/releases/latest"><img alt="GitHub release (latest SemVer)" src="https://img.shields.io/github/v/release/cainmagi/dash-file-cache?logo=github&sort=semver&style=flat-square"></a>
  <a href="https://github.com/cainmagi/dash-file-cache/releases"><img alt="GitHub all releases" src="https://img.shields.io/github/downloads/cainmagi/dash-file-cache/total?logo=github&style=flat-square"></a>
  <a href="https://github.com/cainmagi/dash-file-cache/blob/main/LICENSE"><img alt="GitHub" src="https://img.shields.io/github/license/cainmagi/dash-file-cache?style=flat-square&logo=opensourceinitiative&logoColor=white"></a>
  <a href="https://pypi.org/project/dash-file-cache"><img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dm/dash-file-cache?style=flat-square&logo=pypi&logoColor=white&label=pypi"/></a>
</p>
<p align="center">
  <a href="https://github.com/cainmagi/dash-file-cache/actions/workflows/python-package.yml"><img alt="GitHub Actions (Build)" src="https://img.shields.io/github/actions/workflow/status/cainmagi/dash-file-cache/python-package.yml?style=flat-square&logo=githubactions&logoColor=white&label=build"></a>
  <a href="https://github.com/cainmagi/dash-file-cache/actions/workflows/python-publish.yml"><img alt="GitHub Actions (Release)" src="https://img.shields.io/github/actions/workflow/status/cainmagi/dash-file-cache/python-publish.yml?style=flat-square&logo=githubactions&logoColor=white&label=release"></a>
</p>

Dash File Cache is a Dash extension library.

Utilities for providing convenient methods to serve cached data in Plotly-Dash or Flask.

The data cache enables the following features:

1. Load a server-side file dynamically and send the file to users (the frontend).
2. Support in-memory files (like `io.BytesIO()`) or on-disk files (specified by a path).
3. Support different kinds of cache (single-thread, multi-processing, or file-based).
4. A customized component helping the dashboard trigger a download event from the server side.

## 1. Install

Intall the **latest released version** of this package by using the PyPI source:

``` sh
python -m pip install dash-file-cache
```

Or use the following commands to install **the developing version** from the GitHub Source when you have already installed [Git :hammer:][tool-git]:

```bash
git clone https://github.com/cainmagi/dash-file-cache
cd dash-file-cache
python -m pip install -r requirements.txt -r requirements-dev.txt
python -m pip install .
```

## 2. Usage

The following codes show a minimal example of this package

```python
from typing import Optional

import io

import dash
from dash import html
from dash import Input, Output

from dash_file_cache import ServiceData, CachePlain

app = dash.Dash("demo")
service = ServiceData(CachePlain(1))
service.serve(app)

app.layout = html.Div(
    (
        html.Div(
            html.P(
                (
                    html.Span("Get Image:", style={"paddingRight": "0.5rem"}),
                    html.Button(id="btn", children="Image"),
                )
            )
        ),
        html.Div((html.P("Cache address:"), html.P(id="addr"))),
        html.Div((html.P("Cached Image:"), html.Img(id="cache"))),
    ),
)


@app.callback(
    Output("addr", "children"),
    Input("btn", "n_clicks"),
    prevent_initial_call=True,
)
def click_get_image(
    n_clicks: Optional[int],
):
    if not n_clicks:
        return dash.no_update

    addr = service.register(
        io.StringIO(
            R'<svg height="100" width="100" xmlns="http://www.w3.org/2000/svg">'
            R'<circle r="45" cx="50" cy="50" fill="red" /></svg>'
        ),
        content_type="image/svg+xml",
        mime_type="image/svg+xml",
        one_time_service=True,
    )
    return addr


@app.callback(
    Output("cache", "src"),
    Input("addr", "children"),
    prevent_initial_call=True,
)
def update_cache(addr):
    if not addr:
        return dash.no_update
    return addr


if __name__ == "__main__":
    app.run(host="127.0.0.1", port="8080", debug=True)
```

Check http://127.0.0.1:8080 to see the following results:

|           The minimal demo            |
| :-----------------------------------: |
| ![pic-demo-minimal][pic-demo-minimal] |

## 3. Documentation

Check the documentation to find more details about the examples and APIs.

https://cainmagi.github.io/dash-file-cache/

## 4. Contributing

See [CONTRIBUTING.md :book:][link-contributing]

## 5. Changelog

See [Changelog.md :book:][link-changelog]

[tool-git]:https://git-scm.com/downloads
[tool-nodejs]:https://nodejs.org/en/download/package-manager
[tool-yarn]:https://yarnpkg.com/getting-started/install

[pic-demo-minimal]:https://raw.githubusercontent.com/cainmagi/dash-file-cache/main/display/demo-minimal.png

[link-contributing]:https://github.com/cainmagi/dash-file-cache/blob/main/CONTRIBUTING.md
[link-changelog]:https://github.com/cainmagi/dash-file-cache/blob/main/Changelog.md

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "dash-file-cache",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Yuchen Jin <cainmagi@gmail.com>",
    "keywords": "python, python3, python-library, dash, plotly-dash, python-dash, flask, service, cache, cache-service, downloader, file-downloads",
    "author": null,
    "author_email": "Yuchen Jin <cainmagi@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/22/f6/b7f83642986f9f62b88e36774495b9ccdd457b35f86d0b9a5ee04b610035/dash_file_cache-0.1.2.tar.gz",
    "platform": null,
    "description": "# Dash File Cache\n\n<p align=\"center\">\n  <a href=\"https://github.com/cainmagi/dash-file-cache/releases/latest\"><img alt=\"GitHub release (latest SemVer)\" src=\"https://img.shields.io/github/v/release/cainmagi/dash-file-cache?logo=github&sort=semver&style=flat-square\"></a>\n  <a href=\"https://github.com/cainmagi/dash-file-cache/releases\"><img alt=\"GitHub all releases\" src=\"https://img.shields.io/github/downloads/cainmagi/dash-file-cache/total?logo=github&style=flat-square\"></a>\n  <a href=\"https://github.com/cainmagi/dash-file-cache/blob/main/LICENSE\"><img alt=\"GitHub\" src=\"https://img.shields.io/github/license/cainmagi/dash-file-cache?style=flat-square&logo=opensourceinitiative&logoColor=white\"></a>\n  <a href=\"https://pypi.org/project/dash-file-cache\"><img alt=\"PyPI - Downloads\" src=\"https://img.shields.io/pypi/dm/dash-file-cache?style=flat-square&logo=pypi&logoColor=white&label=pypi\"/></a>\n</p>\n<p align=\"center\">\n  <a href=\"https://github.com/cainmagi/dash-file-cache/actions/workflows/python-package.yml\"><img alt=\"GitHub Actions (Build)\" src=\"https://img.shields.io/github/actions/workflow/status/cainmagi/dash-file-cache/python-package.yml?style=flat-square&logo=githubactions&logoColor=white&label=build\"></a>\n  <a href=\"https://github.com/cainmagi/dash-file-cache/actions/workflows/python-publish.yml\"><img alt=\"GitHub Actions (Release)\" src=\"https://img.shields.io/github/actions/workflow/status/cainmagi/dash-file-cache/python-publish.yml?style=flat-square&logo=githubactions&logoColor=white&label=release\"></a>\n</p>\n\nDash File Cache is a Dash extension library.\n\nUtilities for providing convenient methods to serve cached data in Plotly-Dash or Flask.\n\nThe data cache enables the following features:\n\n1. Load a server-side file dynamically and send the file to users (the frontend).\n2. Support in-memory files (like `io.BytesIO()`) or on-disk files (specified by a path).\n3. Support different kinds of cache (single-thread, multi-processing, or file-based).\n4. A customized component helping the dashboard trigger a download event from the server side.\n\n## 1. Install\n\nIntall the **latest released version** of this package by using the PyPI source:\n\n``` sh\npython -m pip install dash-file-cache\n```\n\nOr use the following commands to install **the developing version** from the GitHub Source when you have already installed [Git :hammer:][tool-git]:\n\n```bash\ngit clone https://github.com/cainmagi/dash-file-cache\ncd dash-file-cache\npython -m pip install -r requirements.txt -r requirements-dev.txt\npython -m pip install .\n```\n\n## 2. Usage\n\nThe following codes show a minimal example of this package\n\n```python\nfrom typing import Optional\n\nimport io\n\nimport dash\nfrom dash import html\nfrom dash import Input, Output\n\nfrom dash_file_cache import ServiceData, CachePlain\n\napp = dash.Dash(\"demo\")\nservice = ServiceData(CachePlain(1))\nservice.serve(app)\n\napp.layout = html.Div(\n    (\n        html.Div(\n            html.P(\n                (\n                    html.Span(\"Get Image:\", style={\"paddingRight\": \"0.5rem\"}),\n                    html.Button(id=\"btn\", children=\"Image\"),\n                )\n            )\n        ),\n        html.Div((html.P(\"Cache address:\"), html.P(id=\"addr\"))),\n        html.Div((html.P(\"Cached Image:\"), html.Img(id=\"cache\"))),\n    ),\n)\n\n\n@app.callback(\n    Output(\"addr\", \"children\"),\n    Input(\"btn\", \"n_clicks\"),\n    prevent_initial_call=True,\n)\ndef click_get_image(\n    n_clicks: Optional[int],\n):\n    if not n_clicks:\n        return dash.no_update\n\n    addr = service.register(\n        io.StringIO(\n            R'<svg height=\"100\" width=\"100\" xmlns=\"http://www.w3.org/2000/svg\">'\n            R'<circle r=\"45\" cx=\"50\" cy=\"50\" fill=\"red\" /></svg>'\n        ),\n        content_type=\"image/svg+xml\",\n        mime_type=\"image/svg+xml\",\n        one_time_service=True,\n    )\n    return addr\n\n\n@app.callback(\n    Output(\"cache\", \"src\"),\n    Input(\"addr\", \"children\"),\n    prevent_initial_call=True,\n)\ndef update_cache(addr):\n    if not addr:\n        return dash.no_update\n    return addr\n\n\nif __name__ == \"__main__\":\n    app.run(host=\"127.0.0.1\", port=\"8080\", debug=True)\n```\n\nCheck http://127.0.0.1:8080 to see the following results:\n\n|           The minimal demo            |\n| :-----------------------------------: |\n| ![pic-demo-minimal][pic-demo-minimal] |\n\n## 3. Documentation\n\nCheck the documentation to find more details about the examples and APIs.\n\nhttps://cainmagi.github.io/dash-file-cache/\n\n## 4. Contributing\n\nSee [CONTRIBUTING.md :book:][link-contributing]\n\n## 5. Changelog\n\nSee [Changelog.md :book:][link-changelog]\n\n[tool-git]:https://git-scm.com/downloads\n[tool-nodejs]:https://nodejs.org/en/download/package-manager\n[tool-yarn]:https://yarnpkg.com/getting-started/install\n\n[pic-demo-minimal]:https://raw.githubusercontent.com/cainmagi/dash-file-cache/main/display/demo-minimal.png\n\n[link-contributing]:https://github.com/cainmagi/dash-file-cache/blob/main/CONTRIBUTING.md\n[link-changelog]:https://github.com/cainmagi/dash-file-cache/blob/main/Changelog.md\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Utilities for providing convenient methods to serve cached data in Plotly-Dash or Flask.",
    "version": "0.1.2",
    "project_urls": {
        "Changelog": "https://github.com/cainmagi/dash-file-cache/blob/main/Changelog.md",
        "Documentation": "https://cainmagi.github.io/dash-file-cache/",
        "Homepage": "https://github.com/cainmagi/dash-file-cache",
        "Issues": "https://github.com/cainmagi/dash-file-cache/issues",
        "Repository": "https://github.com/cainmagi/dash-file-cache.git"
    },
    "split_keywords": [
        "python",
        " python3",
        " python-library",
        " dash",
        " plotly-dash",
        " python-dash",
        " flask",
        " service",
        " cache",
        " cache-service",
        " downloader",
        " file-downloads"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c9349341e38019a4f41f0337bca67f04122d982db0e0af47e7e42df0dda74789",
                "md5": "ee5d576aca9b81f7652d3115faf7787f",
                "sha256": "2e658a01ec0e8fe94aabdbaf455b7955b64018e5a6b23e30c64bafa34822b96f"
            },
            "downloads": -1,
            "filename": "dash_file_cache-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ee5d576aca9b81f7652d3115faf7787f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 28797,
            "upload_time": "2024-10-13T23:38:03",
            "upload_time_iso_8601": "2024-10-13T23:38:03.009015Z",
            "url": "https://files.pythonhosted.org/packages/c9/34/9341e38019a4f41f0337bca67f04122d982db0e0af47e7e42df0dda74789/dash_file_cache-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "22f6b7f83642986f9f62b88e36774495b9ccdd457b35f86d0b9a5ee04b610035",
                "md5": "9e8dff269e33bf1f652ca177ecd66aef",
                "sha256": "c4e2afd65412f07fa513f7adbe64913eab3e76617c0fd255e60283f46b4adb0f"
            },
            "downloads": -1,
            "filename": "dash_file_cache-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "9e8dff269e33bf1f652ca177ecd66aef",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 158439,
            "upload_time": "2024-10-13T23:38:04",
            "upload_time_iso_8601": "2024-10-13T23:38:04.607873Z",
            "url": "https://files.pythonhosted.org/packages/22/f6/b7f83642986f9f62b88e36774495b9ccdd457b35f86d0b9a5ee04b610035/dash_file_cache-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-13 23:38:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cainmagi",
    "github_project": "dash-file-cache",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "dash-file-cache"
}
        
Elapsed time: 0.36323s