Skip to main content

Simple key-value database for my small projects!

Project description

nonbloat-db

Support Ukraine

Build Status Documentation Build Status Code style: black Python support versions badge (from pypi)

Simple key-value database for my small projects!

The idea is to have a dead simple database, which doesn't require spinning up a server (like Redis), is not underwhelming with features (like SQLite or SQL in general), data inside can be easily manually reviewed and modified and it doesn't corrupt (if you just dump JSON into file using json.dump, if the program was forced to stop during write (e.g. because of power outage), the data will be corrupted).

The purpose of this project is to serve as a database library for my small projects. So obviously this solution doesn't scale to thousands of users, and it was never intended to. Use right tool for right job.

Also, do note, that everything is async. There is no synchronous version, because all of my projects are generally async. I maybe will add a synchronous wrapper, but I don't promise.

How does it work?

It is just a really simple key-value storage:

import asyncio
from nbdb.storage import Storage


async def main():
    # you need to provide a path to database
    my_db = await Storage.init("data/db.json")
    await my_db.set("abc", 123)

    value = await my_db.get("abc")
    print(value)  # 123

    await my_db.write()


if __name__ == "__main__":
    asyncio.run(main())

[!NOTE] Everything in this library is asynchronous, so you have to call it from async functions.

In the background, a lot of things are happening. For example, when you call .set, the db writes the operation to special AOF (Append Only File; this is what Redis uses to achieve data persistence).

And on every write, library renames db.json to db.json.temp and then writes to db.json new data. This is done to not corrupt data in case of power outage or force shutdown. If library during initial read finds a .temp file next to database, it will output a warning and read from temp file.

Installing

It is not yet published to PyPI, so good luck.

pip install nonbloat-db

Installing for local developing

git clone https://github.com/PerchunPak/nonbloat-db.git
cd nonbloat-db

Installing poetry

Next we need install poetry with recommended way.

If you use Linux, use command:

curl -sSL https://install.python-poetry.org | python -

If you use Windows, open PowerShell with admin privileges and use:

(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -

Installing dependencies

poetry install

If something is not clear

You can always write me!

Thanks

This project was generated with python-template.

Project details


Download files

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

Source Distribution

nonbloat_db-0.1.3.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

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

nonbloat_db-0.1.3-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file nonbloat_db-0.1.3.tar.gz.

File metadata

  • Download URL: nonbloat_db-0.1.3.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for nonbloat_db-0.1.3.tar.gz
Algorithm Hash digest
SHA256 26d1fae3c3e491280e1be6fa37c763eaede5ba0661751d22a577bf999b4aaa50
MD5 e77fcbd4074a35d7573e5bccb4024d16
BLAKE2b-256 266decd12ba338c33977181bb77442124ee18b4d44a59073815ad39f03007941

See more details on using hashes here.

Provenance

The following attestation bundles were made for nonbloat_db-0.1.3.tar.gz:

Publisher: deploy-pypi.yml on PerchunPak/nonbloat-db

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nonbloat_db-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: nonbloat_db-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for nonbloat_db-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4dff218b60aa113e9bb7d65e3d881319453d5998204e79b820a54b9bca3059e4
MD5 cf2b8323d2007eeffc00d3beb19e2133
BLAKE2b-256 da7b2374403241e67d24ca92c72318f55075cb9a3956c667356c8c417e792d86

See more details on using hashes here.

Provenance

The following attestation bundles were made for nonbloat_db-0.1.3-py3-none-any.whl:

Publisher: deploy-pypi.yml on PerchunPak/nonbloat-db

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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