Skip to main content

Additional tinydb storage

Project description

tinydb-storage

Tiny db storage extension, this is an unofficial from tinydb. I'm creating this extension based on my case only.

Installation

pip install tinydbstorage

Storage extension to use Tinydb

  • Memory storage
  • File storage
  • Redis storage
  • S3 storage

Memory storage example

import requests
from tinydb import TinyDB, Query
from tinydbstorage.storage import MemoryStorage

db = TinyDB(storage=MemoryStorage)

def insert_data():
    resp = requests.get("https://jsonplaceholder.typicode.com/users")
    db.table("users").insert_multiple(resp.json())

File storage example

import os

import requests
from tinydb import TinyDB, Query
from tinydbstorage.storage import FileStorage

db_path = os.path.join(os.path.dirname(__file__), "db.json")
db = TinyDB(path=db_path, storage=FileStorage)

def insert_data():
    resp = requests.get("https://jsonplaceholder.typicode.com/users")
    db.table("users").insert_multiple(resp.json())

Redis storage example

import requests
from tinydb import TinyDB, Query

from tinydbstorage.storage import RedisStorage

db = TinyDB(storage=RedisStorage, redis_uri="redis://:secret@localhost:6379/0")

def insert_data():
    resp = requests.get("https://jsonplaceholder.typicode.com/users")
    db.table("users").insert_multiple(resp.json())

S3 storage example

import requests
from tinydb import TinyDB, Query
from tinydbstorage.schema import S3ConfigSchema
from tinydbstorage.storage import S3Storage

config = S3ConfigSchema.parse_obj({
    "bucket_name": "foo",
    "file_path": "foo/bar/baz.json",
    "region_name": "ap-southeast-1",
    "access_key_id": "foobar",
    "secret_access_key": "foobar",
})

db = TinyDB(storage=S3Storage, config=config)

def insert_data():
    resp = requests.get("https://jsonplaceholder.typicode.com/users")
    db.table("users").insert_multiple(resp.json())

Help & Bugs

contributions welcome

If you are still confused or found a bug, please open the issue. All bug reports are appreciated, some features have not been tested yet due to lack of free time.

License

license

tinydb-storage released under MIT. See LICENSE for more details.

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

tinydbstorage-0.1.0.tar.gz (5.2 kB view hashes)

Uploaded Source

Built Distribution

tinydbstorage-0.1.0-py3-none-any.whl (7.9 kB view hashes)

Uploaded Python 3

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