# pref - a simple local preferences store
Persistent storage of `attrs` attributes or an ordered set (like a list, but no duplicates) to
a local SQLite database file.
# Example
```
from attr import attrib, attrs
from ismain import is_main
from pref import Pref, PrefOrderedSet
application_name = "myapp"
author = "me"
@attrs
class MyPref(Pref):
first_name: str = attrib(default=None)
last_name: str = attrib(default=None)
has_subscription: bool = attrib(default=False) # start off with no subscription
def get_pref() -> MyPref:
return MyPref(application_name, author)
def get_ordered_set() -> PrefOrderedSet:
return PrefOrderedSet(application_name, author, "mylist")
if is_main():
# set a variable
preferences = get_pref()
preferences.first_name = "James"
preferences.last_name = "Abel"
# read it back
preferences = get_pref()
print(preferences.first_name) # James
print(preferences.last_name) # Abel
print(preferences.has_subscription) # evaluates as False (is actually int of 0)
# set an ordered set (list-like, but no duplicates)
my_list = get_ordered_set()
my_list.set(["a", "b", "c"])
# read the ordered set back in
my_list = get_ordered_set()
print(my_list.get()) # ['a', 'b', 'c']
```
Raw data
{
"_id": null,
"home_page": "https://github.com/jamesabel/pref",
"name": "pref",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "local,preferences,sqlite",
"author": "abel",
"author_email": "j@abel.co",
"download_url": "https://github.com/jamesabel/pref",
"platform": null,
"description": "\r\n# pref - a simple local preferences store\r\n\r\nPersistent storage of `attrs` attributes or an ordered set (like a list, but no duplicates) to \r\na local SQLite database file. \r\n\r\n# Example\r\n\r\n```\r\nfrom attr import attrib, attrs\r\nfrom ismain import is_main\r\n\r\nfrom pref import Pref, PrefOrderedSet\r\n\r\napplication_name = \"myapp\"\r\nauthor = \"me\"\r\n\r\n\r\n@attrs\r\nclass MyPref(Pref):\r\n first_name: str = attrib(default=None)\r\n last_name: str = attrib(default=None)\r\n has_subscription: bool = attrib(default=False) # start off with no subscription\r\n\r\n\r\ndef get_pref() -> MyPref:\r\n return MyPref(application_name, author)\r\n\r\n\r\ndef get_ordered_set() -> PrefOrderedSet:\r\n return PrefOrderedSet(application_name, author, \"mylist\")\r\n\r\n\r\nif is_main():\r\n\r\n # set a variable\r\n preferences = get_pref()\r\n preferences.first_name = \"James\"\r\n preferences.last_name = \"Abel\"\r\n\r\n # read it back\r\n preferences = get_pref()\r\n print(preferences.first_name) # James\r\n print(preferences.last_name) # Abel\r\n print(preferences.has_subscription) # evaluates as False (is actually int of 0)\r\n\r\n # set an ordered set (list-like, but no duplicates)\r\n my_list = get_ordered_set()\r\n my_list.set([\"a\", \"b\", \"c\"])\r\n\r\n # read the ordered set back in\r\n my_list = get_ordered_set()\r\n print(my_list.get()) # ['a', 'b', 'c']\r\n```\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "persistent preferences store to local sqlite",
"version": "0.2.0",
"split_keywords": [
"local",
"preferences",
"sqlite"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "445205fc360a6adae259e7b98b8d03250266a77aa8aee9506f7243eb633a6f05",
"md5": "e28711ad2d5de35498200d5b582f6a15",
"sha256": "5ceda0adc5e9534e22ecc23934c174b75f088de5ef56af5db69e5183ea9c0d30"
},
"downloads": -1,
"filename": "pref-0.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e28711ad2d5de35498200d5b582f6a15",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5551,
"upload_time": "2023-04-28T05:44:17",
"upload_time_iso_8601": "2023-04-28T05:44:17.261854Z",
"url": "https://files.pythonhosted.org/packages/44/52/05fc360a6adae259e7b98b8d03250266a77aa8aee9506f7243eb633a6f05/pref-0.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-28 05:44:17",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "jamesabel",
"github_project": "pref",
"travis_ci": false,
"coveralls": true,
"github_actions": false,
"lcname": "pref"
}