kv-deta


Namekv-deta JSON
Version 0.2.2.post1 PyPI version JSON
download
home_pagehttps://github.com/ablaternae/kv-deta
SummaryKey-Value Model for Detabase
upload_time2024-01-18 13:52:10
maintainer
docs_urlNone
authord;)
requires_python>=3.7
licenseGLWTPL
keywords deta detabase kv key value
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!-- ![Lines of code](https://img.shields.io/tokei/lines/github/ablaternae/py-kv-deta) -->
[![PyPI version](https://badge.fury.io/py/kv-deta.svg)](https://badge.fury.io/py/kv-deta)
![Downloads](https://img.shields.io/pypi/dm/kv-deta)
[![Statistic](https://pepy.tech/badge/kv-deta/week)](https://pepy.tech/project/kv-deta)
<!-- [![GitHub](https://img.shields.io/github/license/ablaternae/kv-deta)](https://github.com/ablaternae/kv-deta/blob/trunk/LICENSE.md) -->

# Key-Value Model for Detabase

## API
### constructor
`class KVModel(dict)`

example:
```
from kv_deta import KVModel 

class Example(KVModel):
  class Config(KVModel.Config):
    deta_key = DETA_BASE_KEY
    # or
    deta = Deta(DETA_BASE_KEY)

    table_name = "my_kv_table"	# optional

    time_to_live = None  #   int seconds from now(). takes precedence over expire!
    expire = None  #   ISO string or int unix timestamp

    hash = my_hash_function	# default lambda x: hashlib.sha256(str(x).encode('utf8')).hexdigest()
```
```
kv = Example({"key":"value"})
```

### update
```
kv.update({"k2":42})
```
as in dictionary

### save
```
kv.save()
```
commit **all** data to detabase

### get
mixed dict.get(key) & deta.get(key) & dict.setdefault(key, default)
```
kv.get(key="some key"[, default="default"])
```
returns value from `deta.get(key)` or set it by `default` if deta.get() returned `None` 

### delete
```
kv.delete(key) -> self
```
delete `key` from self & base

### keys
```
kv.keys(param=None) -> List
```
return list(key)

### incr, decr
based on Deta.Base.Util.incremental()
```
kv.incr(key="counter"[, quantity=1])
```
returns incremented value for `key`.
if detabase have not specific `key`, creates it and set `value=quantity`

### query
```
@classmethod
kv.query(param=criteria, limit=1000, last=None) -> Dict
```
* return dict(key:value)
* query param see also https://deta.space/docs/en/build/reference/deta-base/queries

### read
```
kv.read(param=criteria, limit=1000, last=None) -> self
```
* call query() and replaces **all** data in **current** model object



### Table Struct
field | description              |
----- | ------------------------ |
key   | hash(key) |
path  | origin key, hidden field |
value | data |

## News
* v0.2.1, v0.2.2 method delete(), refactor
* v0.1.23 TTL added
* v0.1.22 _bigint_ bug is [not a bug](https://github.com/deta/deta-python/issues/95)
  > Base currently supports **maximum 16 digit** numbers (integers and floating points), 
  > please [store larger numbers as a string](https://deta.space/docs/en/build/reference/deta-base#storing-numbers).
  * `@classmethod query() -> dict` by [rules](https://deta.space/docs/en/build/reference/deta-base/queries).
    you can search key(s) like an other ordinary fields
  * `read()` uses query() and replaces all data in current model without creating new dictionary object

* v0.1.20 methods implementation exchanged `incr2 <--> incr`
* bug detected: Deta.Base.Util.incremental() doesn't work with _bigint_
* v0.1.18 setup repaired
* v0.1.17 hotfix
* v0.1.16 `query(), keys()` 
* v0.1.15 `rename()`
* v0.1.13 backward compatibility broken
* v0.1.12 `incr()` rewritten with Deta.Base.Util.incremental()
* v0.1.11 `incr(key: str, quantity=1)`, `decr(key: str, quantity=1): return incr(key, -quantity)`
* v0.1.8 `get()` fix
* `get(key, default)`
* `save()`

## License
* It's opensource and free software, see the [LICENSE](LICENSE) for more details

## similar projects
* [csv-deta](https://pypi.org/project/csv-deta/) 
* [sql-deta](https://pypi.org/project/sql-deta/)

## TODO
* [ ] save() refactor
* [ ] del
* [ ] set()
* [x] TTL
* [x] `incr()`, `decr()`
* [x] `query()` return dict
* [x] `rename(key, new_key)`
* [x] `keys()` get keys list
* [x] `get(key)`

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ablaternae/kv-deta",
    "name": "kv-deta",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "deta,detabase,kv,key value",
    "author": "d;)",
    "author_email": "",
    "download_url": "",
    "platform": null,
    "description": "<!-- ![Lines of code](https://img.shields.io/tokei/lines/github/ablaternae/py-kv-deta) -->\r\n[![PyPI version](https://badge.fury.io/py/kv-deta.svg)](https://badge.fury.io/py/kv-deta)\r\n![Downloads](https://img.shields.io/pypi/dm/kv-deta)\r\n[![Statistic](https://pepy.tech/badge/kv-deta/week)](https://pepy.tech/project/kv-deta)\r\n<!-- [![GitHub](https://img.shields.io/github/license/ablaternae/kv-deta)](https://github.com/ablaternae/kv-deta/blob/trunk/LICENSE.md) -->\r\n\r\n# Key-Value Model for Detabase\r\n\r\n## API\r\n### constructor\r\n`class KVModel(dict)`\r\n\r\nexample:\r\n```\r\nfrom kv_deta import KVModel \r\n\r\nclass Example(KVModel):\r\n  class Config(KVModel.Config):\r\n    deta_key = DETA_BASE_KEY\r\n    # or\r\n    deta = Deta(DETA_BASE_KEY)\r\n\r\n    table_name = \"my_kv_table\"\t# optional\r\n\r\n    time_to_live = None  #   int seconds from now(). takes precedence over expire!\r\n    expire = None  #   ISO string or int unix timestamp\r\n\r\n    hash = my_hash_function\t# default lambda x: hashlib.sha256(str(x).encode('utf8')).hexdigest()\r\n```\r\n```\r\nkv = Example({\"key\":\"value\"})\r\n```\r\n\r\n### update\r\n```\r\nkv.update({\"k2\":42})\r\n```\r\nas in dictionary\r\n\r\n### save\r\n```\r\nkv.save()\r\n```\r\ncommit **all** data to detabase\r\n\r\n### get\r\nmixed dict.get(key) & deta.get(key) & dict.setdefault(key, default)\r\n```\r\nkv.get(key=\"some key\"[, default=\"default\"])\r\n```\r\nreturns value from `deta.get(key)` or set it by `default` if deta.get() returned `None` \r\n\r\n### delete\r\n```\r\nkv.delete(key) -> self\r\n```\r\ndelete `key` from self & base\r\n\r\n### keys\r\n```\r\nkv.keys(param=None) -> List\r\n```\r\nreturn list(key)\r\n\r\n### incr, decr\r\nbased on Deta.Base.Util.incremental()\r\n```\r\nkv.incr(key=\"counter\"[, quantity=1])\r\n```\r\nreturns incremented value for `key`.\r\nif detabase have not specific `key`, creates it and set `value=quantity`\r\n\r\n### query\r\n```\r\n@classmethod\r\nkv.query(param=criteria, limit=1000, last=None) -> Dict\r\n```\r\n* return dict(key:value)\r\n* query param see also https://deta.space/docs/en/build/reference/deta-base/queries\r\n\r\n### read\r\n```\r\nkv.read(param=criteria, limit=1000, last=None) -> self\r\n```\r\n* call query() and replaces **all** data in **current** model object\r\n\r\n\r\n\r\n### Table Struct\r\nfield | description              |\r\n----- | ------------------------ |\r\nkey   | hash(key) |\r\npath  | origin key, hidden field |\r\nvalue | data |\r\n\r\n## News\r\n* v0.2.1, v0.2.2 method delete(), refactor\r\n* v0.1.23 TTL added\r\n* v0.1.22 _bigint_ bug is [not a bug](https://github.com/deta/deta-python/issues/95)\r\n  > Base currently supports **maximum 16 digit** numbers (integers and floating points), \r\n  > please [store larger numbers as a string](https://deta.space/docs/en/build/reference/deta-base#storing-numbers).\r\n  * `@classmethod query() -> dict` by [rules](https://deta.space/docs/en/build/reference/deta-base/queries).\r\n    you can search key(s) like an other ordinary fields\r\n  * `read()` uses query() and replaces all data in current model without creating new dictionary object\r\n\r\n* v0.1.20 methods implementation exchanged `incr2 <--> incr`\r\n* bug detected: Deta.Base.Util.incremental() doesn't work with _bigint_\r\n* v0.1.18 setup repaired\r\n* v0.1.17 hotfix\r\n* v0.1.16 `query(), keys()` \r\n* v0.1.15 `rename()`\r\n* v0.1.13 backward compatibility broken\r\n* v0.1.12 `incr()` rewritten with Deta.Base.Util.incremental()\r\n* v0.1.11 `incr(key: str, quantity=1)`, `decr(key: str, quantity=1): return incr(key, -quantity)`\r\n* v0.1.8 `get()` fix\r\n* `get(key, default)`\r\n* `save()`\r\n\r\n## License\r\n* It's opensource and free software, see the [LICENSE](LICENSE) for more details\r\n\r\n## similar projects\r\n* [csv-deta](https://pypi.org/project/csv-deta/) \r\n* [sql-deta](https://pypi.org/project/sql-deta/)\r\n\r\n## TODO\r\n* [ ] save() refactor\r\n* [ ] del\r\n* [ ] set()\r\n* [x] TTL\r\n* [x] `incr()`, `decr()`\r\n* [x] `query()` return dict\r\n* [x] `rename(key, new_key)`\r\n* [x] `keys()` get keys list\r\n* [x] `get(key)`\r\n",
    "bugtrack_url": null,
    "license": "GLWTPL",
    "summary": "Key-Value Model for Detabase",
    "version": "0.2.2.post1",
    "project_urls": {
        "Homepage": "https://github.com/ablaternae/kv-deta"
    },
    "split_keywords": [
        "deta",
        "detabase",
        "kv",
        "key value"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2661dacf593c06524ad8ca0a44daf58710039a9255acb5b078af79c8c11c937c",
                "md5": "e5391dc7c538c99e9d4f72111cd2258e",
                "sha256": "769ee1262f9437855f830cc12b53511d1efb0c9078dbeb1b159c62d27460e4a2"
            },
            "downloads": -1,
            "filename": "kv_deta-0.2.2.post1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e5391dc7c538c99e9d4f72111cd2258e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 17453,
            "upload_time": "2024-01-18T13:52:10",
            "upload_time_iso_8601": "2024-01-18T13:52:10.796421Z",
            "url": "https://files.pythonhosted.org/packages/26/61/dacf593c06524ad8ca0a44daf58710039a9255acb5b078af79c8c11c937c/kv_deta-0.2.2.post1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-18 13:52:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ablaternae",
    "github_project": "kv-deta",
    "github_not_found": true,
    "lcname": "kv-deta"
}
        
d;)
Elapsed time: 0.16692s