Skip to main content

A collection and persistance manager for blob stores like aws S3

Project description

https://img.shields.io/pypi/v/ssshelf.svg https://travis-ci.org/voidfiles/ssshelf.svg?branch=master Code Climate Test Coverage

An S3 persistence manager. If you squint closely enough you could even call it a database.

Goals

  • Lots of examples

  • Blob Storage as primary (S3, Ceph, Google Cloud Storage, etc.)

Concerns

  • Eventual Consistency

  • Speed

  • Constraints

Examples Using SSShelf

Example

import asyncio
from datetime import datetime
import simpleflake
import json

from ssshelf.items import IManager
from ssshelf.collections import Collection
from ssshelf.utils import convert_datetime_to_str, json_dump
from ssshelf.managers import CManager
from ssshelf.storages.s3 import S3Storage


class Bookmark(IManager):
    def get_pk(self, item):
        return str(item['pk'])

    def serialize_item(self, item):
        return bytes(json_dump(item), 'utf8')

    def deserialize_item(self, data):
        return json.loads(data)


class AllBookmarks(Collection):
    def get_pk(self, item):
        return str(item['pk'])

    def key(self, item):
        return [
          [convert_datetime_to_str(item['created_at'])]
        ]


class BookmarkManager(CManager):
    item_manager = Bookmark()
    every = AllBookmarks()

async def demo():
    bookmark_manager = BookmarkManager(S3Storage())

    bookmark = {
        'pk': simpleflake.simpleflake(),
        'link': 'http://google.com',
        'created_at': datetime.utcnow()
    }

    await bookmark_manager.add_item(bookmark)

    resp = await bookmark_manager.every.get_items()

    assert resp['items'][0]['link'] == 'http://google.com'

loop = asyncio.get_event_loop()
loop.run_until_complete(demo())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ssshelf-0.1.3.tar.gz (8.8 kB view details)

Uploaded Source

File details

Details for the file ssshelf-0.1.3.tar.gz.

File metadata

  • Download URL: ssshelf-0.1.3.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ssshelf-0.1.3.tar.gz
Algorithm Hash digest
SHA256 0889319c2f1bf13a817e7ccb5a9d5a3c123557592cff37752223dc4dfa306694
MD5 0415aa8035c273d74b515f09e2aa0241
BLAKE2b-256 db274d6be28bddc73974357353d1192abbacae9972e2a099dc6352c488cc5f8b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page