An API prototype for simplifying IO in Dash
Project description
dash-io
An API prototype for simplifying IO in Dash. This is an experimental library and not an official Plotly product.
Quickstart
To install the library:
pip install dash-io
Start using it inside Python
import dash_io as dio
# ...
url_df = dio.url_from_pandas(df) # dataframe
url_im = dio.url_from_pillow(im) # PIL image
# ...
df = dio.url_to_pandas(url_df)
im = dio.url_to_pillow(url_im)
Usage
Pillow
from PIL import Image
import numpy as np
import dash_io as dio
# Dummy image in Pillow
im = Image.fromarray(np.random.randint(0, 255, (100,100,3)))
# Encode the image into a data url
data_url = dio.url_from_pillow(im, format="jpg")
# Decode the data url into a PIL image
im = dio.url_to_pillow(data_url, format="jpg")
The following format are currently supported: jpg
, png
.
Pandas
If you use xlsx
, make sure to install a third-party engine such as openpyxl
.
To use it in pandas:
import pandas as pd
import dash_io as dio
# Dummy data
data = {'col_1': [3, 2, 1, 0], 'col_2': ['a', 'b', 'c', 'd']}
df = pd.DataFrame.from_dict(data)
# To encode/decode in binary CSV format
encoded = dio.url_from_pandas(df, format="csv", index=False)
decoded = dio.url_to_pandas(encoded, format="csv")
# To encode/decode in binary parquet format
encoded = dio.url_from_pandas(df, format="parquet")
decoded = dio.url_to_pandas(encoded, format="parquet")
# To encode/decode in string CSV format (i.e. text/csv MIME type)
encoded = dio.url_from_pandas(df, format="csv", mime_type="text", mime_subtype="csv", index=False)
decoded = dio.url_to_pandas(encoded, format="csv")
The following format are currently supported: csv
, parquet
, feather
, xlsx
.
JSON
import dash_io as dio
# Encode/decode dictionary
data = {'col_1': [3, 2, 1, 0], 'col_2': ['a', 'b', 'c', 'd']}
encoded = dio.url_from_json(data)
decoded = dio.url_to_json(encoded)
# It also works with lists and other JSON-serializable objects
encoded = dio.url_from_json([1,2,3,4,5])
Note that if a dict
key is an integer, it will be converted to string by json
. This is a normal behavior.
Numpy
By default, numpy
arrays will not contain the mime header. However, you can enable it with header=True
(e.g. if you want to upload/download a npy
file).
import dash_io as dio
# Encode/decode numpy arrays without MIME header by default
array = np.array([[1, 2, 3], [4, 5, 6]])
encoded = dio.url_from_numpy(array)
decoded = dio.url_to_numpy(encoded)
# You can also use headers
encoded = dio.url_from_numpy(array, header=True)
decoded = dio.url_to_numpy(encoded, header=True)
Note that pickling is disabled for npy
files for security reasons.
Documentation
You can access the documentation by calling:
import dash_io as dio
help(dio)
You can find the up-to-date output from help
inside DOCS.txt
.
Development
First, clone this repo:
git clone https://github.com/plotly/dash-io
Testing
Create a venv:
python -m venv venv
source venv/bin/activate
Install dev dependencies:
cd dash-io
pip install requirements-dev.txt
Run pytest:
python -m pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dash-io-0.0.2.tar.gz
.
File metadata
- Download URL: dash-io-0.0.2.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5126fa6a3e0d706f77c2d938e6febc42fa7f5dd826969d8af4ece5d9a67f687d |
|
MD5 | 02ad93a0e376e9d1f827efbfeeafb83d |
|
BLAKE2b-256 | 2515546fe74d1537476116233d74d7f554a2d2c945caf37d83158b2c30516256 |
File details
Details for the file dash_io-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: dash_io-0.0.2-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96120b748c8d8ceaf0d7460c33c5581619de6838e16e6a2f46d383861ab0ecd8 |
|
MD5 | 781dad9ce735511be9d0f1f50912fbb8 |
|
BLAKE2b-256 | 6f3f69e0b3208f98fd353d26adc499c9de4f9f078d96312bcf82a285d62502a5 |