kvm-db
kvm-db is a Python library that provides a simple interface for both key-value storage and model-based data management using SQLite.
Features
- Key-Value Store: Simple API for key-value data operations.
- Model Database: Manage data using Python classes and objects.
Supported Backends
SQLite
pip install 'kvm-db'
from kvm_db import Sqlite
backend = Sqlite("db.sqlite")
DynamoDB
pip install 'kvm-db[dynamodb]'
from kvm_db import DynamoDB
backend = DynamoDB("table_name")
Terrform example for creating a DynamoDB table:
module "kv_table" {
source = "terraform-aws-modules/dynamodb-table/aws"
version = "4.0.1"
name = "example-keyval-table"
hash_key = "key"
attributes = [
{
name = "key"
type = "S"
},
{
name = "table"
type = "S"
},
]
global_secondary_indexes = [
{
name = "table-index"
hash_key = "table"
projection_type = "ALL"
}
]
# If you want to enable TTL
ttl_attribute_name = "ttl"
ttl_enabled = true
}
You can insert datum with ttl attribute like this:
kv_db.insert_datum(TABLE, KEY, VALUE, ttl=10) # 10 seconds
SQLs
TODO
JsonDB
TODO
Installation
Install kvm-db using pip:
pip install kvm-db
Quick Start
You can retrieve the value using this syntax
db[TABLE_NAME, KEY]
# Or
table_db = db[TABLE_NAME]
table_db[KEY]
Below is a quick example to get you started with kvm-db.
Key-Value Database Example
from kvm_db import KeyValDatabase, Sqlite
# Initialize the database with SQLite
kv_db = KeyValDatabase(Sqlite("kv.db"))
# Create a new table
kv_db.create_table("test_table")
# Adding and accessing data
kv_db["test_table", "key1"] = "value1"
kv_db["test_table"]["key2"] = "value2"
# Retrieve all items in the table
print(kv_db["test_table", :]) # Output: [('key1', 'value1'), ('key2', 'value2')]
# Update and delete data
kv_db["test_table", "key1"] = "updated_value"
del kv_db["test_table", "key1"]
# Check the table after deletion
print(kv_db["test_table", :]) # Output: []
Model(Pydantic) Database Example
TODO: Support native Python dataclasses and other data types.
from kvm_db import ModelDatabase, Sqlite, TableModel
class User(TableModel):
name: str
# Initialize Model Database with SQLite
model_db_backend = Sqlite("model.db")
model_db = ModelDatabase(model_db_backend)
# Register the model
model_db.register(User)
# Create and insert a new user
user1 = User(name="Alice")
model_db.insert(user1)
# Query users
all_users = model_db[User][:]
print(all_users[0].name) # Output: Alice
# Query user with id
alice_id = user1.id
alice = model_db[User][alice_id]
print(alice.name) # Output: Alice
# Update user information
alice.name = "Bob"
alice.commit()
# Confirm update
print(model_db[User, :][0].name) # Output: Bob
# Delete a user
user1.delete()
print(model_db[User, :]) # Output: []
Metadata
Release files for kvm-db 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kvm_db-0.1.6.tar.gz | 9.0 kB | Without provenance | Details for kvm_db-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kvm_db-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for kvm_db-0.1.6-py3-none-any.whl |
Total release size: 17.1 kB
Release files / kvm_db-0.1.6.tar.gz
| Download URL | kvm_db-0.1.6.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6bd42926355a05517b04406de5c76d95ef0e29f40aabe4b96cb11ff6c916b62e
|
|
BLAKE2b-256 checksum How to use checksums |
337302dae473b4dab2ae7908edf11b41f7054096b9ac4ae514d9c2780d96eec5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.3
|
Release files / kvm_db-0.1.6-py3-none-any.whl
| Download URL | kvm_db-0.1.6-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b81283218a9f47737a467fdc7e08c5b7a440a068938143bea984a26e5d6b1e92
|
|
BLAKE2b-256 checksum How to use checksums |
77a5487c9ae4d7e08de9717806c88af13bbd51946c41c72440c093aba493b592
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.3
|
Security for kvm-db 0.1.6
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.