Skip to content

Conversation

@AshokThangavel
Copy link
Contributor

Description:
This PR integrates the embeddedpy-bridge library as a core dependency. This addition significantly improves the Developer Experience when working with Embedded Python inside ObjectScript by providing high-level wrappers and a more intuitive syntax.

Key Changes:
Dependency Management: Added embeddedpy-bridge to module.xml.

  • $$$pyDict: Instantly creates a Python-wrapped Dictionary. No need to manage proxies manually.
  • $$$pyList: Instantly creates a Python-wrapped List (Note: Ensure your macro is mapped to pyList for consistency).
  • $$$pyJSON(obj): Converts a native IRIS Dynamic Object directly into a Python object.
    and it includes features such as create and iterate the python dictionary and list in iris syntax

Why this is beneficial:
Readability: Reduces boilerplate code by ~30% in typical Python-heavy ObjectScript classes.
Standardization: Provides a common "bridge" pattern that is easier for beginners to learn than raw proxy manipulation.

Community Post: https://community.intersystems.com/post/embeddedpy-bridge-toolkit-embedded-python

@evshvarov
Copy link
Member

@AshokThangavel thanks for the PR!
Need more examples on:
Readability: Reduces boilerplate code by ~30% in typical Python-heavy ObjectScript classes.

@AshokThangavel
Copy link
Contributor Author

AshokThangavel commented Dec 28, 2025

Hi @evshvarov

I implemented this logic today, so no other repositories currently using expect the actual implementation repository/application. These wrapper classes make it easy to integrate the embedded Python logic when handling python datatypes and Json
Hopefully, this dependency package stays lightweight and doesn’t add unnecessary bloat to the template

Idiomatic Iteration

In standard Embedded Python, looping through a list or dictionary requires manual handling of the Python StopIteration exception and the builtins library.
I implemented a native IRIS Iterator pattern that wraps the Python logic. This allows you to traverse Python collections using standard, idiomatic ObjectScript syntax, removing the need for Try/Catch blocks just to end a loop.

The "simplified" Way:

Set iter = pyList.%GetIterator()
While iter.%GetNext(.key, .val) { 
    // Secure, clean, and familiar syntax
}

Simplified Type Creation & Conversion

Creating Python types or converting data typically requires repeated imports of Python libraries like builtins or json. I have wrapped these into high-level macros to reduce visual noise and boilerplate.

Before (Verbose):

Set dict = ##class(%SYS.Python).Import("builtins").dict()
Set pyObj = ##class(%SYS.Python).Import("json").loads(dynObj.%ToJSON())

After (Concise):

Set dict = $$$pyDict
Set pyObj = $$$pyJSON(dynObj)

By hiding the manual imports and type-casting inside these macros, the code becomes much easier to maintain, read, and use by developers.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants