Skip to main content

No project description provided

Project description

jsonsh

Disclaimer : This is quite slow for bunch inserts, Taking upto 0.0077 second for 1 file insert when 10000 files were inserted one by one

Note: I did the test on my laptop , which has i5-3337u

Installing

pip install -U jsonsh

if you are on Unix-like system, The performace can be increased by installing uvloop !

pip install -U uvloop

What is this !

This is a silly package , that uses pydantic to store data in different json files.

Data Fetched is in pydantic Model , which can be converted to dict using dict().

All examples below have data returned as a Pydantic Model !

Usage

Base Example

import asyncio
from jsonsh import Template,Instance

instance = Instance("Data") #this is your data folder

@instance.register
class Test(Template):
    id:int
    age:int
    name:str

async def main():
    idk = Test(id = 10,age = 13,name = "hello")
    await idk.save() #this saves the file in your current working directory

asyncio.run(main())

Finding and Updating Data

There are no advanced queries yet but you can find by id or particular value

import asyncio
from jsonsh import Template,Instance

instance = Instance("Data")

@instance.register
class Test(Template):
    id:int
    age:int
    name:str

async def main():
    data = await Test.find_one(id = 10)
    print(data) #prints the data we found
    data.name = "Unknown" #changing name
    await data.save() #updating data

asyncio.run(main())

Finding Multiple Data

import asyncio
from jsonsh import Template,Instance

instance = Instance("Data")

@instance.register
class Test(Template):
    id:int
    age:int
    name:str

async def main():
    data = await Test.find_many(age = 10) #finding all dict with age as 10
    print(data) #prints the lists of multiple dicts

asyncio.run(main())

Using Indexing

import asyncio
from jsonsh import Template,Instance

instance = Instance("Data")

@instance.register
class Test(Template):
    id:int
    age:int
    name:str

    class Meta:
        indexes = ["age","name"] 
    """
    this makes finding by age and name faster
    """

async def main():
    data = await Test.find_many(age = 10) #finding all dict with age as 10
    print(data) #prints the lists of multiple dicts

asyncio.run(main())

Deleting files / entries

import asyncio
from jsonsh import Template,Instance

instance = Instance("Data")

@instance.register
class Test(Template):
    id:int
    age:int
    name:str

    class Meta:
        indexes = ["age","name"] 
    """
    this makes finding by age and name faster
    """

async def main():
    data = await Test.delete_one(age = 10) #deleting a file entry with age as 10
    data = await Test.delete_one(id = 10) #deleting a file entry with id as 10
    print(data) #prints the lists of multiple dicts

asyncio.run(main())

Simple Caching

from jsonsh import Template,Instance

instance = Instance("Data",cache_state = True,capacity = 100) #this helps you to avoid reading files in finds

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jsonsh-0.1.6-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file jsonsh-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: jsonsh-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for jsonsh-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 46a42cde5b092ba55556549be76e887471dd7c299d493186e24d84544b50039b
MD5 40452dfa4a3c5c49b9b90ea11fadd8f4
BLAKE2b-256 2fb3ee207b0ed86c3aaf0be76c6e029ee2647827544c7571c8c9d041142f4956

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page