Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Sandpiper

A simple generic key-value store interface library.

Requirements

  • 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.

How to Install

Run pip3 install sandpiper.

Example

Set up the driver

First of all, let's set up the adapter.

For DynamoDB

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)

For Memcached

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 = ':')

For Redis

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 = ':')

How to use it

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')

Currently Supported Storage Types

  • In-memory/Python's built-in dictionary type (default)
  • AWS DynamoDB
  • Memcached
  • Redis with hiredis

Soon-to-be Supported Storage Types

  • MongoDB

Releases

No releases published

Packages

No packages published