Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON-DB

json-db logo

Version Badge CI Coverage Badge Complexity Badge Maintainability Badge

An in-memory database using .json files, akin to MongoDB for lightweight, RAM-based data handling.

Overview

This package exports the JSONDatabase class which can be used to operate a database of JSON documents in memory.

Load a Database

Load a Database from a file by providing a mapping of collections to classes, and the path to the database file:

from pathlib import Path

from json_db import JSONDatabase

MAPPING = {
    "users": User,
    "projects": Project,
}
database_path = Path("path/to/database.json")


db = JSONDatabase.load(MAPPING, database_path)

Use the Database

Any of the collections defined in the mapping can be accessed as attributes of the Database object:

users = db.users

Access specific documents in a collection by their ID:

user_id = "someuserid

user = users.get(user_id)

Save the Database

Save a Database to a .json file by providing the path to the database file:

db.save(database_path)

Installation

Clone this repository, and set the current directory to the root of the repository:

git clone git@github.com:FreddyWordingham/json-db.git
cd json-db

Install the package and its dependencies:

poetry env use python3.10
poetry install

To ensure code quality and consistency, please set up Git hooks when you start working on the project:

sh ./ci/setup_hooks.sh

This will run the pre-commit checks before pushing your changes to GitHub.

About

An in-memory database using .json files, akin to MongoDB for lightweight, RAM-based data handling.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages