Giter Club home page Giter Club logo

jsondb's Introduction

jsondb

Build Status PyPI version

This is a utility for managing content in a database which stores content in JSON format.

Installation

This package can be installed from PyPi by running:

pip install jsondatabase

Note, the package name and the import name are different. Import the package using import jsondb.

Usage

from jsondb.db import Database
db = Database("mydata.db")

The database has an attribute which works similar to jQuery's data attribute.

# Getting all data
db = Database("mydata.db")
print(db.data())
# Getting a stored value
db = Database("mydata.db")
print(db.data(key="user_count"))

It is important to note that a key will be created regardless of whether it exists as long as a value is provided. The database has the same functionality as a dictionary.

# Setting a value
db = Database("mydata.db")
db.data(key="user_count", value=241)
# Passing in a dictionary value
db = Database("mydata.db")
data = {
    "user_id": 234565,
    "user_name": "AwesomeUserName",
    "is_moderator": True,
}
db.data(dictionary=data)
# Deleting a value
db = Database("mydata.db")
db.delete("my_key")

The database also supports a dictionary-like syntax for retrieving, setting, and removing values.

db = Database("mydata.db")

# Retrieving a value
value = db["key"]

# Setting a value
db["key"] = value

# Removing a key
del db["key"]

# Checking if a key exists
"key" in db

Performance

If performance is an issue with large databases then the python-cjson module can be installed. jsondb will automatically detect this and use cjson instead.

jsondb's People

Contributors

gunthercox avatar kevin-brown 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.