No project description provided
Project description
Data Snack
About
Install
Plugin can be easily installed using pypi repository.
pip install data_snack
Usage
Example 1
1. Define entities
from dataclasses import dataclass
from typing import Text
from data_snack.entities import Entity
@dataclass
class CarEntity(Entity):
index: Text
price: int
brand: Text
2. Connect to redis
import redis
redis_connection = redis.Redis(
host='127.0.0.1',
port=6379,
password=''
)
3. Create snack instance
from data_snack import Snack
snack = Snack(connection=redis_connection) # create instance
snack.register_entity(CarEntity, keys=['index']) # register your entity
4. Create test dataset
import pandas as pd
df = pd.DataFrame([
{"index": "1", "brand": "Audi", "price": 17000},
{"index": "2", "brand": "Opel", "price": 4000},
{"index": "3", "brand": "Audi", "price": 7000},
{"index": "4", "brand": "Toyota", "price": 14000},
])
data = [CarEntity(**v) for v in df.to_dict(orient="records")]
5. Save and load data
snack.set(data[1])
# 'CarEntity-2'
snack.get(CarEntity, ["1"])
# CarEntity(index='1', price=17000, brand='Audi')
entities = snack.mget(CarEntity, [["1"], ["2"], ["3"]])
# [CarEntity(index='1', price=17000, brand='Audi'), CarEntity(index='2', price=4000, brand='Opel'), CarEntity(index='3', price=7000, brand='Audi')]
snack.mset(data)
# ['CarEntity-1', 'CarEntity-2', 'CarEntity-3', 'CarEntity-4']
Contact
Plugin was created by the Data Science team from Webinterpret.
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
data_snack-0.0.1.tar.gz
(5.3 kB
view hashes)
Built Distribution
Close
Hashes for data_snack-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b05b6668fdea15c3504f685fc1ebaa3aa18e76f4901f8a7e12817adbb2280add |
|
MD5 | 1216e0d5eb4475d91d8f1d234e694f00 |
|
BLAKE2b-256 | 67461371378c0e93f4fd65a51120d5b3ff19750697f3dca90c63b3bf506114e9 |