GithubHelp home page GithubHelp logo

ferdinakusumah / tinydb-storage Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 36 KB

Tiny db storage extension

License: MIT License

Python 99.04% Makefile 0.96%
tinydb tinydb-examples tinydb-extension tinydb-storage

tinydb-storage's Introduction

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 S3Schema
from tinydbstorage.storage import S3Storage

config = S3Schema.from_param(
    bucket_name="foo",
    file_path="foo/bar/baz.json",
    region_name="ap-southeast-1",
    access_key_id="bar",
    secret_access_key="secretkey",
)

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.

tinydb-storage's People

Contributors

ferdinakusumah avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.