Simple key-value database for my small projects!
Project description
nonbloat-db
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file nonbloat_db-0.1.1.tar.gz
.
File metadata
- Download URL: nonbloat_db-0.1.1.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39af28eee5f3037a574b6e2bd27f88cdb0c17136bb802ae0a575727bc43c44a6 |
|
MD5 | 43389968743943b7f8e010c24671ffd1 |
|
BLAKE2b-256 | e46bc89eb722e4f8525d03f64bba6a9b45b40ae8af3d41605aec638b56d5a7f6 |
File details
Details for the file nonbloat_db-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: nonbloat_db-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e80d1649c856d0ddaa2f676e90bcc7f62a722c753cbaacdf81c13251f7b245f |
|
MD5 | 43f8ba0bb095161f87d98c589026c6f5 |
|
BLAKE2b-256 | de439f5df51bca7b9ecb519fbd95426e2ff4f4957e62dc7f4ce02ed5a3ddf3a0 |