Skip to main content

PysonDB-V2

The new DB schema

{
    "version": 2,
    "keys" ["a", "b", "c"],
    "data": {
        "384753047545745": {
            "a": 1,
            "b": "something",
            "c": true
        }
    }
}

Quick walk through of all the methods

from pysondb import PysonDB


db = PysonDB('test.json')
!cat test.json
{
    "version": 2,
    "keys": [],
    "data": {}
}

add

id = db.add({
    'name': 'adwaith',
    'age': 4,
    'knows_python': True
})
print(id)
231541323453553701
!cat test.json
{
    "version": 2,
    "keys": [
        "age",
        "knows_python",
        "name"
    ],
    "data": {
        "231541323453553701": {
            "name": "adwaith",
            "age": 4,
            "knows_python": true
        }
    }
}

add_many

added_values = db.add_many([
    {
        'name': 'fredy',
        'age': 19,
        'knows_python': True
    },
    {
        'name': 'kenny',
        'age': 19,
        'knows_python': False
    }
])
print(added_values)
None
added_values = db.add_many([
    {
        'name': 'mathew',
        'age': 22,
        'knows_python': False
    },
    {
        'name': 'abi',
        'age': 19,
        'knows_python': True
    }
], json_response=True)
print(added_values)
{'330993934764646664': {'name': 'mathew', 'age': 22, 'knows_python': False}, '131457970736078364': {'name': 'abi', 'age': 19, 'knows_python': True}}
!cat test.json
{
    "version": 2,
    "keys": [
        "age",
        "knows_python",
        "name"
    ],
    "data": {
        "231541323453553701": {
            "name": "adwaith",
            "age": 4,
            "knows_python": true
        },
        "263597723557497291": {
            "name": "fredy",
            "age": 19,
            "knows_python": true
        },
        "299482429835276227": {
            "name": "kenny",
            "age": 19,
            "knows_python": false
        },
        "330993934764646664": {
            "name": "mathew",
            "age": 22,
            "knows_python": false
        },
        "131457970736078364": {
            "name": "abi",
            "age": 19,
            "knows_python": true
        }
    }
}

get_by_id

print(db.get_by_id('263597723557497291'))
{'name': 'fredy', 'age': 19, 'knows_python': True}

get_by_query

def age_divisible_by_2(data):
    if data['age'] % 2 == 0:
        return True

print(db.get_by_query(query=age_divisible_by_2))
{'231541323453553701': {'name': 'adwaith', 'age': 4, 'knows_python': True}, '330993934764646664': {'name': 'mathew', 'age': 22, 'knows_python': False}}

get_all

print(db.get_all())
{'231541323453553701': {'name': 'adwaith', 'age': 4, 'knows_python': True}, '263597723557497291': {'name': 'fredy', 'age': 19, 'knows_python': True}, '299482429835276227': {'name': 'kenny', 'age': 19, 'knows_python': False}, '330993934764646664': {'name': 'mathew', 'age': 22, 'knows_python': False}, '131457970736078364': {'name': 'abi', 'age': 19, 'knows_python': True}}

update_by_id

updated_data = db.update_by_id('231541323453553701', {
    'age': 18
})
print(updated_data)
{'name': 'adwaith', 'age': 18, 'knows_python': True}

update_by_query

updated_ids = db.update_by_query(
    query=lambda x: x['name'] == 'abi',
    new_data={'knows_python': False}
)
print(updated_ids)
['131457970736078364']
!cat test.json
{
    "version": 2,
    "keys": [
        "age",
        "knows_python",
        "name"
    ],
    "data": {
        "231541323453553701": {
            "name": "adwaith",
            "age": 18,
            "knows_python": true
        },
        "263597723557497291": {
            "name": "fredy",
            "age": 19,
            "knows_python": true
        },
        "299482429835276227": {
            "name": "kenny",
            "age": 19,
            "knows_python": false
        },
        "330993934764646664": {
            "name": "mathew",
            "age": 22,
            "knows_python": false
        },
        "131457970736078364": {
            "name": "abi",
            "age": 19,
            "knows_python": false
        }
    }
}

delete_by_id

db.delete_by_id('131457970736078364')  # delete abi
!cat test.json
{
    "version": 2,
    "keys": [
        "age",
        "knows_python",
        "name"
    ],
    "data": {
        "231541323453553701": {
            "name": "adwaith",
            "age": 18,
            "knows_python": true
        },
        "263597723557497291": {
            "name": "fredy",
            "age": 19,
            "knows_python": true
        },
        "299482429835276227": {
            "name": "kenny",
            "age": 19,
            "knows_python": false
        },
        "330993934764646664": {
            "name": "mathew",
            "age": 22,
            "knows_python": false
        }
    }
}

delete_by_query

ids = db.delete_by_query(lambda x: x['knows_python'] is False)
print(ids)
['299482429835276227', '330993934764646664']
!cat test.json
{
    "version": 2,
    "keys": [
        "age",
        "knows_python",
        "name"
    ],
    "data": {
        "231541323453553701": {
            "name": "adwaith",
            "age": 18,
            "knows_python": true
        },
        "263597723557497291": {
            "name": "fredy",
            "age": 19,
            "knows_python": true
        }
    }
}

purge

db.purge()
!cat test.json
{
    "version": 2,
    "keys": [],
    "data": {}
}

For more docs click here

Metadata

Release files for pysondb-v2 2.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pysondb-v2 2.2.0
File Size Uploaded Provenance
pysondb-v2-2.2.0.tar.gz 13.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pysondb-v2 2.2.0
File Interpreter ABI Platform
pysondb_v2-2.2.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 23.1 kB

Release files / pysondb-v2-2.2.0.tar.gz

Download URL pysondb-v2-2.2.0.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1f5d2d864e5f5d1334d639681199255526ab0c8aa0b4b324462e78aae0e08d10
BLAKE2b-256 checksum
How to use checksums
200c1850a1e6f9c80e275fd228ef26e1c56e8c1107f7bf45facfbbac0a8867a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / pysondb_v2-2.2.0-py2.py3-none-any.whl

Download URL pysondb_v2-2.2.0-py2.py3-none-any.whl
Size 9.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
3226ee94b7550e602f7061f68ae64b5d02812153d799b57aa74343f20ed0cd9b
BLAKE2b-256 checksum
How to use checksums
b53878575cfbaec7b8a1bc96d94ee4a2166b4957758b25f25bff80aa48e34764
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Security for pysondb-v2 2.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page