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).

Building

Use flit to build/install:

$ flit build

Project details


Download files

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

Source Distribution

userdefaults3-1.1.8.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

userdefaults3-1.1.8-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file userdefaults3-1.1.8.tar.gz.

File metadata

  • Download URL: userdefaults3-1.1.8.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for userdefaults3-1.1.8.tar.gz
Algorithm Hash digest
SHA256 b7709384f0cad58758d5d8d9382a0206b2767cd7256c385fb9919cc83f133bb7
MD5 1136ad39e70061ff202f310e1dd555e3
BLAKE2b-256 ad80956b680febc6a75241e633cb2bfe01f7d6859ea3545a97bbc6ff185a3e98

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for userdefaults3-1.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 32eb2321b6e1bd751939facfa5155467b6e72ce41d30d0ebcf391ce513d3584a
MD5 fe1d5b5830f45ec601a8530ef61bc217
BLAKE2b-256 81db47bb0e0310a728b9509bf632f350377dc3928390d019e270d01bfa8fcb0b

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