Skip to main content

persistent preferences store to local sqlite

Project description

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']

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pref-0.0.8-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file pref-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: pref-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.2

File hashes

Hashes for pref-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 793c2e794c26c39b42b720ed6dca27fdaaef584cbf436fb21ae021056bd78a0e
MD5 931f95a598cf5ccaa2b06b05b71be631
BLAKE2b-256 c33eeaebec0ea351344ffc37dba25f7abf8766192b11f7d5be183f875121775d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page