Name | kvm-db JSON |
Version |
0.1.6
JSON |
| download |
home_page | None |
Summary | Key-Value&Model Database |
upload_time | 2024-06-15 16:16:54 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | None |
keywords |
database
key-value
model
pydantic
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# kvm-db
[![Supported Python Versions](https://img.shields.io/pypi/pyversions/kvm-db/0.1.6)](https://pypi.org/project/kvm-db/) [![PyPI version](https://badge.fury.io/py/kvm-db.svg)](https://badge.fury.io/py/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
```sh
pip install 'kvm-db'
```
```python
from kvm_db import Sqlite
backend = Sqlite("db.sqlite")
```
#### DynamoDB
```sh
pip install 'kvm-db[dynamodb]'
```
```python
from kvm_db import DynamoDB
backend = DynamoDB("table_name")
```
Terrform example for creating a DynamoDB table:
```hcl
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:
```python
kv_db.insert_datum(TABLE, KEY, VALUE, ttl=10) # 10 seconds
```
#### SQLs
TODO
#### JsonDB
TODO
## Installation
Install kvm-db using pip:
```bash
pip install kvm-db
```
## Quick Start
You can retrieve the value using this syntax
```python
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
```python
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.
```python
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: []
```
Raw data
{
"_id": null,
"home_page": null,
"name": "kvm-db",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "database, key-value, model, pydantic",
"author": null,
"author_email": "Ja-sonYun <killa30867@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/33/73/02dae473b4dab2ae7908edf11b41f7054096b9ac4ae514d9c2780d96eec5/kvm_db-0.1.6.tar.gz",
"platform": null,
"description": "# kvm-db\n\n[![Supported Python Versions](https://img.shields.io/pypi/pyversions/kvm-db/0.1.6)](https://pypi.org/project/kvm-db/) [![PyPI version](https://badge.fury.io/py/kvm-db.svg)](https://badge.fury.io/py/kvm-db)\n\nkvm-db is a Python library that provides a simple interface for both key-value storage and model-based data management using SQLite.\n\n## Features\n\n- Key-Value Store: Simple API for key-value data operations.\n- Model Database: Manage data using Python classes and objects.\n\n### Supported Backends\n\n#### SQLite\n\n```sh\npip install 'kvm-db'\n```\n\n```python\nfrom kvm_db import Sqlite\n\nbackend = Sqlite(\"db.sqlite\")\n```\n\n#### DynamoDB\n\n```sh\npip install 'kvm-db[dynamodb]'\n```\n\n```python\nfrom kvm_db import DynamoDB\n\nbackend = DynamoDB(\"table_name\")\n```\n\nTerrform example for creating a DynamoDB table:\n\n```hcl\nmodule \"kv_table\" {\n source = \"terraform-aws-modules/dynamodb-table/aws\"\n version = \"4.0.1\"\n\n name = \"example-keyval-table\"\n hash_key = \"key\"\n\n attributes = [\n {\n name = \"key\"\n type = \"S\"\n },\n {\n name = \"table\"\n type = \"S\"\n },\n ]\n\n global_secondary_indexes = [\n {\n name = \"table-index\"\n hash_key = \"table\"\n projection_type = \"ALL\"\n }\n ]\n\n # If you want to enable TTL\n ttl_attribute_name = \"ttl\"\n ttl_enabled = true\n}\n\n```\n\nYou can insert datum with ttl attribute like this:\n\n```python\nkv_db.insert_datum(TABLE, KEY, VALUE, ttl=10) # 10 seconds\n```\n\n#### SQLs\n\nTODO\n\n#### JsonDB\n\nTODO\n\n## Installation\n\nInstall kvm-db using pip:\n\n```bash\npip install kvm-db\n```\n\n## Quick Start\n\nYou can retrieve the value using this syntax\n\n```python\ndb[TABLE_NAME, KEY]\n# Or\ntable_db = db[TABLE_NAME]\ntable_db[KEY]\n```\n\nBelow is a quick example to get you started with kvm-db.\n\n### Key-Value Database Example\n\n```python\nfrom kvm_db import KeyValDatabase, Sqlite\n\n# Initialize the database with SQLite\nkv_db = KeyValDatabase(Sqlite(\"kv.db\"))\n\n# Create a new table\nkv_db.create_table(\"test_table\")\n\n# Adding and accessing data\nkv_db[\"test_table\", \"key1\"] = \"value1\"\nkv_db[\"test_table\"][\"key2\"] = \"value2\"\n\n# Retrieve all items in the table\nprint(kv_db[\"test_table\", :]) # Output: [('key1', 'value1'), ('key2', 'value2')]\n\n# Update and delete data\nkv_db[\"test_table\", \"key1\"] = \"updated_value\"\ndel kv_db[\"test_table\", \"key1\"]\n\n# Check the table after deletion\nprint(kv_db[\"test_table\", :]) # Output: []\n```\n\n### Model(`Pydantic`) Database Example\n\nTODO: Support native Python dataclasses and other data types.\n\n```python\nfrom kvm_db import ModelDatabase, Sqlite, TableModel\n\nclass User(TableModel):\n name: str\n\n\n# Initialize Model Database with SQLite\nmodel_db_backend = Sqlite(\"model.db\")\nmodel_db = ModelDatabase(model_db_backend)\n\n# Register the model\nmodel_db.register(User)\n\n# Create and insert a new user\nuser1 = User(name=\"Alice\")\nmodel_db.insert(user1)\n\n# Query users\nall_users = model_db[User][:]\nprint(all_users[0].name) # Output: Alice\n\n# Query user with id\nalice_id = user1.id\nalice = model_db[User][alice_id]\nprint(alice.name) # Output: Alice\n\n# Update user information\nalice.name = \"Bob\"\nalice.commit()\n\n# Confirm update\nprint(model_db[User, :][0].name) # Output: Bob\n\n# Delete a user\nuser1.delete()\nprint(model_db[User, :]) # Output: []\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Key-Value&Model Database",
"version": "0.1.6",
"project_urls": {
"homepage": "https://github.com/Ja-sonYun/kvm-db",
"repository": "https://github.com/Ja-sonYun/kvm-db"
},
"split_keywords": [
"database",
" key-value",
" model",
" pydantic"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "77a5487c9ae4d7e08de9717806c88af13bbd51946c41c72440c093aba493b592",
"md5": "6d645bdd3c0d15aa08bed73a2edddbd9",
"sha256": "b81283218a9f47737a467fdc7e08c5b7a440a068938143bea984a26e5d6b1e92"
},
"downloads": -1,
"filename": "kvm_db-0.1.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6d645bdd3c0d15aa08bed73a2edddbd9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 8042,
"upload_time": "2024-06-15T16:16:53",
"upload_time_iso_8601": "2024-06-15T16:16:53.184377Z",
"url": "https://files.pythonhosted.org/packages/77/a5/487c9ae4d7e08de9717806c88af13bbd51946c41c72440c093aba493b592/kvm_db-0.1.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "337302dae473b4dab2ae7908edf11b41f7054096b9ac4ae514d9c2780d96eec5",
"md5": "9828d734dfc2e84526a3ed6586901b7b",
"sha256": "6bd42926355a05517b04406de5c76d95ef0e29f40aabe4b96cb11ff6c916b62e"
},
"downloads": -1,
"filename": "kvm_db-0.1.6.tar.gz",
"has_sig": false,
"md5_digest": "9828d734dfc2e84526a3ed6586901b7b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 9019,
"upload_time": "2024-06-15T16:16:54",
"upload_time_iso_8601": "2024-06-15T16:16:54.862993Z",
"url": "https://files.pythonhosted.org/packages/33/73/02dae473b4dab2ae7908edf11b41f7054096b9ac4ae514d9c2780d96eec5/kvm_db-0.1.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-15 16:16:54",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Ja-sonYun",
"github_project": "kvm-db",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "kvm-db"
}