pyobjc / pyobjc-core / Doc / metadata / compiled.rst

Compiled metadata system

Starting with version 2.4 PyObjC provides a more efficient, lazy loading metadata system. This can greatly reduce the memory use and startup time for PyObjC based applications while still providing full access to Cocoa APIs.

Creating a framework wrapper

A framework wrapper with the new metadata system is always a python package. The package contains an "__init__.py" file that creates the lazy loader, a "_metadata.py" file with the compiled metadata and optionally other modules and extensions.

The general structure of the "__init__.py" file is:

import sys, objc
import Foundation
from . import _metadata

sys.modules['FrameworkName'] = objc.ObjCLazyModule('FrameworkName',
     "com.apple.FrameworkName',
     objc.pathForFramework("/System/Library/Frameworks/FrameworkName.framework"),
     _metadata.__dict__, None, {
         '__doc__': __doc__,
         'objc': objc,
         '__path__': __path__,
     }, (Foundation,))

The framework name, identifier and path should be replaced by the correct values for the wrapped framework. The import of "Foundation" can be replaced by imports of other framework this framework relies on (also add those to the last argument of :class:`objc.ObjCLazyModule`).

Contents of the "_metadata" module

The exact contents of the "_metadata" module will be described later.

Generating the "_metadata" module

The "objective-metadata" project contains a tool for collecting information about frameworks and compiling that information and manual additions into a "_metadata" module.

That project currently is not a stable as I'd like, this documentation will be updated with more information when that changes.

API description

A subclass of the built-in :class:`module` type that adds lazy-loading of values defined in PyObjC metadata.

param frameworkIdentifier:
 the bundle_identifier argument for a call to :func:`loadBundle`
param frameworkPath:
 the bundle_path argument for a call to :func:`loadBundle`
param metadict:the dictionary with metadata, usually the __dict__ of a module generated by the metadata compiler.
param inline_list:
 a capsule object with function definitions, see :func:`loadFunctionList` for more information.
param initial_dict:
 additional values to add to the module dictionary
param parents:a list of parent modules, the module behaves as if those modules were imported using from parent parent import *, but lazily fetches definitions on first access.

Note

This is the primary entry point for the framework wrappers shipped with PyObjC.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.