A simple category-based key-value database using plain text files.
Project description
EasyDB
EasyDB is a simple, category-based key-value database that stores data in plain text files. It's designed to be lightweight and easy to use.
Features
- Simple key-value storage
- Stores data in plain text files
- Supports categories to organize data
Usage
# example.py
from easydb import Database
# Create an instance of the Database class
db = Database("example.db")
# --- Step 1: Store Data ---
# Store some user data under the "USER" category
db.storage("name: Alice", "age: 28", category="USER")
db.storage("admin: True", category="USER")
# Store server and channel data under "CHANNELS" category
db.storage("server_id: 9876", "channel_id: 1234", category="CHANNELS")
# --- Step 2: Load Data ---
# After storing the data, let's load it from the file
db.load()
# --- Step 3: Retrieve Data ---
# Retrieve specific data from the "USER" category
print("User Name:", db.get_data("name", category="USER")) # Alice
print("User Age:", db.get_data("age", category="USER")) # 28
print("Admin:", db.get_data("admin", category="USER")) # True
# Retrieve entire category data (all keys in "USER" category)
print("User Category Data:", db.get_data(category="USER"))
# Output: {'name': 'Alice', 'age': '28', 'admin': 'True'}
# Retrieve specific data from the "CHANNELS" category
print("Server ID:", db.get_data("server_id", category="CHANNELS")) # 9876
print("Channel ID:", db.get_data("channel_id", category="CHANNELS")) # 1234
# Retrieve entire category data (all keys in "CHANNELS" category)
print("Channels Category Data:", db.get_data(category="CHANNELS"))
# Output: {'server_id': '9876', 'channel_id': '1234'}
# --- Step 4: Delete Data ---
# Delete a key from a specific category ("USER" category)
db.del_data("age", category="USER")
print("After Deleting Age from USER:", db.get_data(category="USER"))
# Output: {'name': 'Alice', 'admin': 'True'}
# Delete the entire "USER" category
db.del_data(category="USER")
print("After Deleting USER category:", db.get_data(category="USER"))
# Output: None (since the category was deleted)
# --- Step 5: Store More Data and Delete from Flat Structure ---
# Store data without a category (flat structure)
db.storage("app_name: MyApp")
# Load and retrieve the flat data
db.load()
print("App Name:", db.get_data("app_name")) # MyApp
# Delete the flat data
db.del_data("app_name")
print("After Deleting app_name:", db.get_data("app_name"))
# Output: None (since the key was deleted)
# --- Step 6: Clean-up and Save Changes ---
# The data is automatically saved after each operation (storage and deletion).
# You can manually save it by calling db._save(), but it's not necessary.
Installation
You can install EasyDB via pip:
pip install easydb
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
easy_db3-1.1.0.tar.gz
(4.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file easy_db3-1.1.0.tar.gz.
File metadata
- Download URL: easy_db3-1.1.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23dee67eb19dad18ebf53f2de51f7cec2564ec8752fc000291c317db218ecddb
|
|
| MD5 |
e77bf999806addfae1002718a977e18a
|
|
| BLAKE2b-256 |
1117da9a763056bc7cde075c3d5034ec669825da9daa624a84359153caea8812
|
File details
Details for the file easy_db3-1.1.0-py3-none-any.whl.
File metadata
- Download URL: easy_db3-1.1.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc427c4e09b8d0f92b8eed88698885ea5d81e0c80991196f71f41bdee600d67f
|
|
| MD5 |
e20f15f729139b8605b1b5bcd677846d
|
|
| BLAKE2b-256 |
f65c92de44c049d890dc8a287708d81224b4ef7b0b6a9d4b6e939a97380380ef
|