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
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
tinydb-storage released under MIT. See LICENSE
for more details.
Project details
Release history Release notifications | RSS feed
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)
Built Distribution
Close
Hashes for tinydbstorage-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2648310d3e3f6ea5ac0914039a2b5d5d443cacc4b45f099fd8e6e08a51fe6c3 |
|
MD5 | 1bbc62429a7f616dbde74d8335d823a4 |
|
BLAKE2b-256 | d93b09cd52f5e1c40eaec00f1d9625c0dded7234974a9f9af97b4bb8af02b47c |