PickleDataset¶
PickleDataset loads and saves data using Python's pickle module, with support for Redis as the backend.
kedro_datasets.redis.PickleDataset ¶
PickleDataset(
*,
key,
backend="pickle",
load_args=None,
save_args=None,
credentials=None,
redis_args=None,
metadata=None
)
Bases: AbstractDataset[Any, Any]
PickleDataset loads/saves data from/to a Redis database. The
underlying functionality is supported by the redis library, so it supports
all allowed options for instantiating the redis app from_url and setting
a value.
Examples:
Using the YAML API:
my_python_object: # simple example
type: redis.PickleDataset
key: my_object
from_url_args:
url: redis://127.0.0.1:6379
final_python_object: # example with save args
type: redis.PickleDataset
key: my_final_object
from_url_args:
url: redis://127.0.0.1:6379
db: 1
save_args:
ex: 10
Using the Python API:
>>> import pandas as pd
>>> from kedro_datasets.redis import PickleDataset
>>>
>>> data = pd.DataFrame({"col1": [1, 2], "col2": [4, 5], "col3": [5, 6]})
>>>
>>> my_data = PickleDataset(key="my_data")
>>> my_data.save(data)
>>> reloaded = my_data.load()
>>> assert data.equals(reloaded)
serialise/deserialise objects.
Example backends that are compatible - non-exhaustive
pickledillcompress_picklecloudpickle
Example backends that are incompatible
torch
Parameters:
-
key(str) –The key to use for saving/loading object to Redis.
-
backend(str, default:'pickle') –Backend to use, must be an import path to a module which satisfies the
pickleinterface. That is, contains aloadsanddumpsfunction. Defaults to 'pickle'. -
load_args(dict[str, Any] | None, default:None) –Pickle options for loading pickle files. You can pass in arguments that the backend load function specified accepts, e.g: pickle.loads: https://docs.python.org/3/library/pickle.html#pickle.loads dill.loads: https://dill.readthedocs.io/en/latest/index.html#dill.loads compress_pickle.loads: https://lucianopaz.github.io/compress_pickle/html/api/compress_pickle.html#compress_pickle.compress_pickle.loads cloudpickle.loads: https://github.com/cloudpipe/cloudpickle/blob/master/tests/cloudpickle_test.py All defaults are preserved.
-
save_args(dict[str, Any] | None, default:None) –Pickle options for saving pickle files. You can pass in arguments that the backend dump function specified accepts, e.g: pickle.dumps: https://docs.python.org/3/library/pickle.html#pickle.dump dill.dumps: https://dill.readthedocs.io/en/latest/index.html#dill.dumps compress_pickle.dumps: https://lucianopaz.github.io/compress_pickle/html/api/compress_pickle.html#compress_pickle.compress_pickle.dumps cloudpickle.dumps: https://github.com/cloudpipe/cloudpickle/blob/master/tests/cloudpickle_test.py All defaults are preserved.
-
credentials(dict[str, Any] | None, default:None) –Credentials required to get access to the redis server. E.g.
{"password": None}. -
redis_args(dict[str, Any] | None, default:None) –Extra arguments to pass into the redis client constructor
redis.StrictRedis.from_url. (e.g.{"socket_timeout": 10}), as well as to pass to theredis.StrictRedis.setthrough nested keysfrom_url_argsandset_args. Here you can find all available arguments forfrom_url: https://redis-py.readthedocs.io/en/stable/connections.html?highlight=from_url#redis.Redis.from_url All defaults are preserved, excepturl, which is set toredis://127.0.0.1:6379. You could also specify the url through the env variableREDIS_URL. -
metadata(dict[str, Any] | None, default:None) –Any arbitrary metadata. This is ignored by Kedro, but may be consumed by users or external plugins.
Raises:
-
ValueError–If
backenddoes not satisfy thepickleinterface. -
ImportError–If the
backendmodule could not be imported.
Source code in kedro_datasets/redis/redis_dataset.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
DEFAULT_REDIS_URL
class-attribute
instance-attribute
¶
DEFAULT_REDIS_URL = getenv(
"REDIS_URL", "redis://127.0.0.1:6379"
)
_describe ¶
_describe()
Source code in kedro_datasets/redis/redis_dataset.py
161 162 | |
_exists ¶
_exists()
Source code in kedro_datasets/redis/redis_dataset.py
187 188 189 190 191 192 193 | |
load ¶
load()
Source code in kedro_datasets/redis/redis_dataset.py
166 167 168 169 170 171 172 | |
save ¶
save(data)
Source code in kedro_datasets/redis/redis_dataset.py
174 175 176 177 178 179 180 181 182 183 184 185 | |