Skip to main content

Python bindings to access native macOS APIs

Project description

Python bindings to access native macOS APIs

Specifics

I created this library to provide access to native macOS APIs to other Python code I’ve written. It uses ctypes to bind to the underlying C APIs, and generally just exposes the APIs ‘as is’ without attempting to Python-ify them.

It does, however, provide several facilities to make working with the APIs a little easier, but they are entirely optional. Several types (e.g. CFTypeRef, io_object_t) have an autorelease() method which will automatically call the appropriate function to release the object when the Python object holding the reference is destroyed.

Additionally, strings can be automatically converted to/from CFStringRef. The aforementioned autorelease method is used to ensure that the ephemeral CFStringRef does not leak.

There is an IOIterator class which can adapt an io_iterator_t into a Python iterator.

The bindings are NOT comprehensive and I generally just add stuff as I need it.

The code is tested with Python 2.7 and 3.6.

Examples

>>> from rh.osx import corefoundation
>>> string_copy = corefoundation.CFStringCreateCopy(None,
... """The Python string object is automatically converted to a CFStringRef.
... The returned CFStringRef copy will automatically be released.""").autorelease()
>>> print(str(string_copy))
The Python string object is automatically converted to a CFStringRef.
The returned CFStringRef copy will automatically be released.

License

This library is distributed under the MIT license, as described in the 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 Distribution

rh.osx-0.1.1.tar.gz (5.6 kB view details)

Uploaded Source

File details

Details for the file rh.osx-0.1.1.tar.gz.

File metadata

  • Download URL: rh.osx-0.1.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for rh.osx-0.1.1.tar.gz
Algorithm Hash digest
SHA256 67b305dcb6572b79dcb893d01c4f5bd6ef5b44c7a47cbe1590906dc8af4aac8f
MD5 8f833e2e2388b5a2bf4fa2015f66b644
BLAKE2b-256 9f610740058bce408bf7ed73d0ddf2b553e12b2d89c3060f29972a8c55904802

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