https://github.com/shiroyuki/sandpiper
A simple generic key-value store interface library
https://github.com/shiroyuki/sandpiper
aws-dynamodb dynamodb hiredis library memcached python python-library python3 redis sandpiper
Last synced: 2 months ago
JSON representation
A simple generic key-value store interface library
- Host: GitHub
- URL: https://github.com/shiroyuki/sandpiper
- Owner: shiroyuki
- License: mit
- Created: 2016-02-12T01:38:27.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-06-27T20:27:35.000Z (almost 9 years ago)
- Last Synced: 2024-12-24T13:32:09.106Z (over 1 year ago)
- Topics: aws-dynamodb, dynamodb, hiredis, library, memcached, python, python-library, python3, redis, sandpiper
- Language: Python
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```python
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
```python
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
```python
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
```python
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