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']
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pref-0.4.0.tar.gz
(5.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
pref-0.4.0-py3-none-any.whl
(6.4 kB
view details)
File details
Details for the file pref-0.4.0.tar.gz.
File metadata
- Download URL: pref-0.4.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee90bfbb73d93b34ddbd95dab0bde3caa61be1e1e918ba2e1b7a839481721932
|
|
| MD5 |
e8eb29ce051bb619c202fdf1c3608677
|
|
| BLAKE2b-256 |
825de547699d3599894d364fa22f895e30109974d95e98af16c20e5c287a7548
|
File details
Details for the file pref-0.4.0-py3-none-any.whl.
File metadata
- Download URL: pref-0.4.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a26298366c444371034b89ba5ff2b54734f1a8853a2fc0146dd0bb871e4b9d30
|
|
| MD5 |
42a795ec83b1f67dcda2083465ee02dc
|
|
| BLAKE2b-256 |
e9a5e49765c991d082cd1e032a0da9dba0a12afefc7c8893444c8f5e61bd385f
|