{"id":17787583,"url":"https://github.com/cainmagi/dash-file-cache","last_synced_at":"2025-03-16T07:32:35.335Z","repository":{"id":257825142,"uuid":"870214543","full_name":"cainmagi/dash-file-cache","owner":"cainmagi","description":"Utilities for providing convenient methods to serve cached data in Plotly-Dash or Flask.","archived":false,"fork":false,"pushed_at":"2024-10-31T19:37:17.000Z","size":610,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-27T05:51:21.761Z","etag":null,"topics":["cache","cache-service","dash","downloader","file-download","flask","plotly-dash","python","python-dash","python-library","python3","service"],"latest_commit_sha":null,"homepage":"https://cainmagi.github.io/dash-file-cache/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cainmagi.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-09T16:33:59.000Z","updated_at":"2025-02-08T03:32:28.000Z","dependencies_parsed_at":"2024-10-13T23:45:37.719Z","dependency_job_id":"e9c8d092-2033-48eb-a671-97dc8c6bd549","html_url":"https://github.com/cainmagi/dash-file-cache","commit_stats":null,"previous_names":["cainmagi/dash-file-cache"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cainmagi%2Fdash-file-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cainmagi%2Fdash-file-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cainmagi%2Fdash-file-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cainmagi%2Fdash-file-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cainmagi","download_url":"https://codeload.github.com/cainmagi/dash-file-cache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243806070,"owners_count":20350775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","cache-service","dash","downloader","file-download","flask","plotly-dash","python","python-dash","python-library","python3","service"],"created_at":"2024-10-27T10:11:53.036Z","updated_at":"2025-03-16T07:32:34.926Z","avatar_url":"https://github.com/cainmagi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dash File Cache\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/cainmagi/dash-file-cache/releases/latest\"\u003e\u003cimg alt=\"GitHub release (latest SemVer)\" src=\"https://img.shields.io/github/v/release/cainmagi/dash-file-cache?logo=github\u0026sort=semver\u0026style=flat-square\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/cainmagi/dash-file-cache/releases\"\u003e\u003cimg alt=\"GitHub all releases\" src=\"https://img.shields.io/github/downloads/cainmagi/dash-file-cache/total?logo=github\u0026style=flat-square\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/cainmagi/dash-file-cache/blob/main/LICENSE\"\u003e\u003cimg alt=\"GitHub\" src=\"https://img.shields.io/github/license/cainmagi/dash-file-cache?style=flat-square\u0026logo=opensourceinitiative\u0026logoColor=white\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://pypi.org/project/dash-file-cache\"\u003e\u003cimg alt=\"PyPI - Downloads\" src=\"https://img.shields.io/pypi/dm/dash-file-cache?style=flat-square\u0026logo=pypi\u0026logoColor=white\u0026label=pypi\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/cainmagi/dash-file-cache/actions/workflows/python-package.yml\"\u003e\u003cimg alt=\"GitHub Actions (Build)\" src=\"https://img.shields.io/github/actions/workflow/status/cainmagi/dash-file-cache/python-package.yml?style=flat-square\u0026logo=githubactions\u0026logoColor=white\u0026label=build\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/cainmagi/dash-file-cache/actions/workflows/python-publish.yml\"\u003e\u003cimg alt=\"GitHub Actions (Release)\" src=\"https://img.shields.io/github/actions/workflow/status/cainmagi/dash-file-cache/python-publish.yml?style=flat-square\u0026logo=githubactions\u0026logoColor=white\u0026label=release\"\u003e\u003c/a\u003e\n\u003c/p\u003e\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'\u003csvg height=\"100\" width=\"100\" xmlns=\"http://www.w3.org/2000/svg\"\u003e'\n            R'\u003ccircle r=\"45\" cx=\"50\" cy=\"50\" fill=\"red\" /\u003e\u003c/svg\u003e'\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcainmagi%2Fdash-file-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcainmagi%2Fdash-file-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcainmagi%2Fdash-file-cache/lists"}