Name | kvm-db JSON |
Version |
0.1.3
JSON |
| download |
home_page | None |
Summary | Key-Value&Model Database |
upload_time | 2024-05-02 15:31:51 |
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.3)](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
TODO: Support for other backends like MySQL, jsondb, etc.
## 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/fe/2b/c69da850fcde2781257237e18f66bbd82b4a7719b3cc3055cbc946499c1b/kvm_db-0.1.3.tar.gz",
"platform": null,
"description": "# kvm-db\n\n[![Supported Python Versions](https://img.shields.io/pypi/pyversions/kvm-db/0.1.3)](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\nTODO: Support for other backends like MySQL, jsondb, etc.\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.3",
"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": "bd496c52bc1a70ba432451863927c6f8be427d4924eea2fe619b779d3b848fcc",
"md5": "2f512170ecff4bb1dc63edbe3408fb07",
"sha256": "47e5b8f52b2f5357e9663375fa295a435a154930307ff91576a0d36b0b2a7310"
},
"downloads": -1,
"filename": "kvm_db-0.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2f512170ecff4bb1dc63edbe3408fb07",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 5952,
"upload_time": "2024-05-02T15:31:50",
"upload_time_iso_8601": "2024-05-02T15:31:50.514743Z",
"url": "https://files.pythonhosted.org/packages/bd/49/6c52bc1a70ba432451863927c6f8be427d4924eea2fe619b779d3b848fcc/kvm_db-0.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "fe2bc69da850fcde2781257237e18f66bbd82b4a7719b3cc3055cbc946499c1b",
"md5": "e3f3968aeac995dac3a7512f735fc981",
"sha256": "18f8a9addfc5c1b0af2e905ff412aee9015bb86a913db044432ac790767cdfcd"
},
"downloads": -1,
"filename": "kvm_db-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "e3f3968aeac995dac3a7512f735fc981",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 7142,
"upload_time": "2024-05-02T15:31:51",
"upload_time_iso_8601": "2024-05-02T15:31:51.904182Z",
"url": "https://files.pythonhosted.org/packages/fe/2b/c69da850fcde2781257237e18f66bbd82b4a7719b3cc3055cbc946499c1b/kvm_db-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-02 15:31:51",
"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"
}