Registry / web-framework / rubicon-objc

rubicon-objc

JSON →
library0.5.6pypypi✓ verified 25d ago

Rubicon-ObjC is a robust bridge between the Python and Objective-C runtime environments, enabling Python code to instantiate, invoke methods on, and subclass Objective-C classes. It's a fundamental component of the BeeWare suite for building native applications with Python. The library is actively maintained, with its current version being 0.5.3, and follows a regular release cadence to support new Python versions and fix bugs.

pip install rubicon-objc
INSTALL
IMPORT
SIG · RUBICON-OBJC
R
rubicon-objc
web-frameworkpythonv0.5.6
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ObjCClass
from rubicon.objc import ObjCClass
from rubicon.objc import ObjCClass

This quickstart demonstrates how to access existing Objective-C classes like `NSURL`, create instances, call methods using Pythonic syntax (handling Objective-C selectors with colons), and access properties. It also shows how to define a new Objective-C class in Python by subclassing `NSObject`, including important considerations for interactive development environments regarding class redefinition.

from rubicon.objc import ObjCClass, NSObject import asyncio # Access an Objective-C class (e.g., NSURL from Foundation framework) NSURL = ObjCClass("NSURL") # Create an instance using a static constructor method. # Objective-C methods with ':' are mapped to Python keyword arguments or replaced with '_' in method name. # E.g., Objective-C's +URLWithString: becomes .URLWithString_() or .URLWithString(url_string). base_url = NSURL.URLWithString_("https://beeware.org/") print(f"Base URL: {base_url}") # Call another method with multiple arguments using keyword arguments full_url = NSURL.URLWithString_relativeToURL_("contributing/", relativeToURL=base_url) print(f"Full URL: {full_url}") # Access Objective-C properties using Python attribute syntax print(f"Full URL scheme: {full_url.scheme}") # --- Defining a new Objective-C class in Python --- # In interactive environments (like Pythonista) or when re-running code, # Objective-C class redefinition can cause errors. auto_rename avoids this. ObjCClass.auto_rename = True # Set globally or pass auto_rename=True to ObjCClass() constructor class MyPythonDelegate(NSObject): # Initialize the Objective-C object. Must call super().init() def init(self): self = super().init() if self: print("MyPythonDelegate initialized!") return self # Define an Objective-C method (e.g., a delegate callback) # Argument types should generally be annotated for clarity and correctness. def myDelegateMethod_withValue_(self, sender: 'id', value: int): print(f"Delegate method called by {sender} with value: {value}") return None # Objective-C methods often return `void` or `id` (None for Python) # Instantiate the Python-defined Objective-C class delegate_instance = MyPythonDelegate.alloc().init() # Example of calling its method (simulating an Objective-C call) delegate_instance.myDelegateMethod_withValue_(NSObject.alloc().init(), 42)
Debug
Known issues
breakingPython 3.9 support was dropped in `rubicon-objc` v0.5.3. Ensure your environment uses Python 3.10 or newer.
fix
Upgrade your Python environment to 3.10 or higher, or pin `rubicon-objc<0.5.3`.
affects: >=0.5.3
breakingStarting with Python 3.14, custom `asyncio` event loop policies were deprecated. `rubicon-objc` v0.5.1 introduced `RubiconEventLoop()` as the preferred way to integrate with asyncio, replacing the older `EventLoopPolicy` mechanism.
fix
Instead of `asyncio.set_event_loop_policy(EventLoopPolicy())` and `asyncio.new_event_loop()`, directly instantiate and use `loop = RubiconEventLoop()` for your event loop. This change is backward compatible for older Python versions too.
affects: >=0.5.1
gotchaObjective-C method selectors containing colons (`:`) are translated into Python method names using either underscores (`_`) or keyword arguments. For example, `+URLWithString:relativeToURL:` can be called as `URLWithString_relativeToURL_('...', relativeToURL=...)` or sometimes `URLWithString('...', relativeToURL='...')` depending on the method signature. The keyword argument style is generally more Pythonic.
fix
Familiarize yourself with `rubicon-objc`'s selector translation rules. When in doubt, check the method signature in Objective-C documentation and experiment with both `_` and keyword argument styles.
affects: all
gotchaIn environments where the Objective-C runtime persists (e.g., Pythonista, or repeatedly running scripts in a long-lived process), redefining an Objective-C class with the same name will cause an error. To mitigate this, set `ObjCClass.auto_rename = True` globally or pass `auto_rename=True` when defining your `ObjCClass` subclasses. This appends a unique suffix to the class name in the runtime.
fix
Add `ObjCClass.auto_rename = True` at the top of your script or pass `auto_rename=True` as a keyword argument when defining Objective-C classes in Python.
affects: all
deprecatedPrior to v0.5.0, developers often needed to manually manage memory of Objective-C objects using `retain`, `release`, or `autorelease` calls from Python. Since v0.5.0, `rubicon-objc` automatically retains Objective-C objects when wrapped and autoreleases them on Python garbage collection, greatly simplifying memory management.
fix
Upgrade to `rubicon-objc` v0.5.0 or newer to benefit from automatic memory management. If on older versions, ensure correct manual retain/release calls, especially for objects returned by methods starting with 'alloc', 'new', 'copy', or 'mutableCopy'.
affects: <0.5.0
gotchaWhile Rubicon-ObjC automatically converts basic Python types (like `str` to `NSString`, `bytes` to `NSData`) when passed as arguments, conversion of Objective-C return types back to native Python types (e.g., `NSString` to `str`) is not always automatic. You might need to explicitly use `py_from_ns()` for full Pythonic object conversion.
fix
For explicit conversion of Objective-C return values to their Python equivalents, use `rubicon.objc.api.py_from_ns(obj)`.
affects: all
Upgrade
Version history
0.5.6latest on PyPI · released Jul 2, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
14
Resources
rubicon-objc — pip install rubicon-objc · libregistry