A simple generic key-value store interface library.
- Python 3.4 or newer
- boto3 for AWS DynamoDB (optional)
- pymemcache for Memcached (optional)
- redis for Redis (optional, recommended to also install hiredis)
- pymongo for MongoDB (optional, future)
Note: this may work with Python 2.7 but it will not be tested.
Run pip3 install sandpiper.
First of all, let's set up the adapter.
import boto3
from sandpiper.adapter import DynamoDB
ddb = boto3.resource(
'dynamodb',
endpoint_url='http://127.0.0.1:8000',
region_name='us-east-1',
aws_access_key_id='anything',
aws_secret_access_key='anything',
use_ssl=False,
verify=False
)
driver = DynamoDB(ddb)from sandpiper.adapter import Memcached, create_memcached_client
connection_list = [
('c1.shiroyuki.com', 11211),
('c2.shiroyuki.com', 11211),
# ...
]
client = create_memcached_client(connection_list)
driver = Memcached(client, namespace = 'default', delimiter = ':')from sandpiper.adapter import Redis, create_redis_client
client = create_redis_client(host = 'localhost') # same arguments as redis.ConnectionPool
driver = Redis(client, namespace = 'default', delimiter = ':')from sandpiper import Storage
storage = Storage(driver)
# Set the data.
storage['user.1'] = {'name': 'foo'}
# Alternative: storage.set('user.1', {'name': 'foo'})
# Get the data.
print(storage['user.1']['name']) # -> foo
# Alternative: storage.get('user.1')
# Delete the data
del storage['user.1']
# Alternative: storage.remove('user.1')- In-memory/Python's built-in dictionary type (default)
- AWS DynamoDB
- Memcached
- Redis with hiredis
- MongoDB