# 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": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"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.3.1",
"project_urls": {
"Download": "https://github.com/jamesabel/pref",
"Homepage": "https://github.com/jamesabel/pref"
},
"split_keywords": [
"local",
" preferences",
" sqlite"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "6ae9ca4ad4169b9e8ef3aea6af84020e4d33482853c3667c912d51a8da399af0",
"md5": "9d06af148b522e157b51511a4d59b47d",
"sha256": "b745ab76aa2f76f100097c5332057ef1e96a4430f5185d8cdb1e7ceee761fce4"
},
"downloads": -1,
"filename": "pref-0.3.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9d06af148b522e157b51511a4d59b47d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5682,
"upload_time": "2025-02-14T19:11:49",
"upload_time_iso_8601": "2025-02-14T19:11:49.628511Z",
"url": "https://files.pythonhosted.org/packages/6a/e9/ca4ad4169b9e8ef3aea6af84020e4d33482853c3667c912d51a8da399af0/pref-0.3.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-14 19:11:49",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jamesabel",
"github_project": "pref",
"travis_ci": false,
"coveralls": true,
"github_actions": false,
"lcname": "pref"
}