Giter Club home page Giter Club logo

jsonbox-python's Introduction

jsonbox-python

Python wrapper for https://jsonbox.io

PyPI version License: MIT Downloads

Installation

pip install jsonbox

Usage

import uuid
from jsonbox import JsonBox

# generate unique box id
MY_BOX_ID = str(uuid.uuid4()).replace("-", "_")

# create instance
jb = JsonBox()

data = [{"name": "first", "age": 25}, {"name": "second", "age": 19}]

# write data
result = jb.write(data, MY_BOX_ID)

# get record id of written data
record_ids = jb.get_record_id(result)

# read record
print(jb.read(MY_BOX_ID, record_ids[0]))

# read all records in box
print(jb.read(MY_BOX_ID))

# read all records in box with sort
print(jb.read(MY_BOX_ID, sort_by="age"))

# read records in box with sort matching query (see documentation for syntax)
print(jb.read(MY_BOX_ID, query="name:firs*"))
print(jb.read(MY_BOX_ID, query="age:=19"))

# read records with limit
print(jb.read(MY_BOX_ID, limit=1))

# read records with skip
print(jb.read(MY_BOX_ID, skip=1))

# update data
data = {"name": "Bob", "age": "25"}
jb.update(data, MY_BOX_ID, record_ids[0])

# read updated data
print(jb.read(MY_BOX_ID, record_ids[0]))

# delete records
jb.delete(MY_BOX_ID, record_ids)

Query Params

As supported (and documented) by https://github.com/vasanthv/jsonbox

You can query by constructing a query string and passing it to the query parameter:

name:arya%20stark,age:>13

The above sample will look for the name arya stark and age greater than 13.

You can filter on Number, String & Boolean values only.

Filters for Numeric values.

Sample
To filter values greater than or less than a specific value age:>10 or age:<10
To filter values greater (or less) than or equal to a specific value age:>=10 or age:<=10
To filter values that match a specific value. age:=10

Filters for String values.

Sample
Filter values that start with a specific string name:arya*
Filter values that end with a specific string name:*stark
Filter values where a specific string appears anywhere in a string name:*ya*
Filter values that match a specific string name:arya%20stark

You can combine multiple fields by separating them with commas as shown below:

name:arya%20stark,age:>13,isalive:true

License

MIT

jsonbox-python's People

Contributors

harlev avatar

Watchers

James Cloos 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.