Skip to main content

Python 3 rewrite of userdefaults, a pure-Python interface to NSUserDefaults.

Project description

userdefaults3

Code style: black PyPI - Python Version PyPI - Wheel

Python 3 rewrite of userdefaults, a pure-Python interface to NSUserDefaults.

The singular 'UserDefaults' class provides the main interface, which should be used as a regular dictionary. Python types are converted to their Obj-C equivlents on writing to UserDefaults.

Usage

>>> with UserDefaults() as ud:
>>>     ud["key"] = value
>>>

Or, for more flexible access to the UserDefaults class:

>>> ud = UserDefaults()
>>> ud["key"] = value
>>> ...  # other operations here
>>> ud.sync()  # write back to plist file, does nothing on Obj-C backend

On supported platforms that have a Obj-C backend, the UserDefaults class acts as a shim for NSUserDefaults. Otherwise, a naive file handle is used to modify UserDefaults using plistlib.

Supported backends:

  • pyobjc (MacOS)
  • rubicon-objc (Darwin/Pyto)
  • objc_util (Pythonista)

If your platform does not have a Obj-C backend (unless you are on Libterm/a-Shell), you problably should not use this as directly writing to the plist file itself is discouraged (as quoted from Apple's docstring):

Don’t try to access the preferences subsystem directly. Modifying preference property list files may result in loss of changes, delay of reflecting changes, and app crashes.

The naive file method is kept to support platforms which do not have/cannot install a Obj-C backend (i.e Libterm, a-Shell).

Known bugs:

  • On Pyto, writing to the inputHistory key using the Obj-C backend results in a SIGKILL (crashes).

License

The MIT license (see LICENSE file)

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

userdefaults3-1.1.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file userdefaults3-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: userdefaults3-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.9

File hashes

Hashes for userdefaults3-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ac02a1847b183805d7e389395019642017a1b74002e7314ea467789722a7ccbb
MD5 e8b040d94e466d576bf352d36ff83ab8
BLAKE2b-256 ae0baea9a2742b2de145b702d3c545892faa6fca29c95b237cc687383ba7a07f

See more details on using hashes here.

Supported by

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