Skip to content

feat: implement add_extension in Python binding#596

Merged
anakrish merged 10 commits intomicrosoft:mainfrom
paulolieuthier:python-add-extension
Feb 25, 2026
Merged

feat: implement add_extension in Python binding#596
anakrish merged 10 commits intomicrosoft:mainfrom
paulolieuthier:python-add-extension

Conversation

@paulolieuthier
Copy link
Contributor

That's my first PR to the project. Please, tell me if there is a better way to do it.

@paulolieuthier
Copy link
Contributor Author

@microsoft-github-policy-service agree

Copy link
Collaborator

@anakrish anakrish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @paulolieuthier, Thanks for the contribution.

This looks good. Some suggestions:

Add more tests. E.g:

  • Error propagation: What happens when the Python callable raises an exception?
  • Type diversity: Passing/returning dicts, lists, sets, numbers, booleans, None
  • Zero-arg extensions
  • Duplicate registration
  • Wrong arity
  • Passing a non-callable object

@paulolieuthier
Copy link
Contributor Author

@anakrish can you take another look?

Copy link
Collaborator

@anakrish anakrish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paulolieuthier I have a few more comments. Also we need to note somewhere the clone semantics. That is if an engine instance is cloned, it will share the same python instance and the builtin invocations themselves will be synchronized.

@paulolieuthier
Copy link
Contributor Author

Fixed!

@anakrish
Copy link
Collaborator

@paulolieuthier Looks very good. Can you also explain the clone semantics in the help for the extension method.

/// Note: When the engine is cloned, extensions share the same Python callable
/// reference rather than being deep-copied. Stateful callables will share
/// state across clones.

@paulolieuthier
Copy link
Contributor Author

Sorry, I had missed your request to improve the docs. I believe it's ready now.

Copy link
Collaborator

@anakrish anakrish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paulolieuthier LGTM. Thanks for the contribution!

Can you also share your usecase for this feature?

@anakrish anakrish merged commit 1c607dc into microsoft:main Feb 25, 2026
43 checks passed
@paulolieuthier
Copy link
Contributor Author

Sure! We are experimenting with Rego as a language for our feature pipeline (for a feature store). As our features are defined in Python, we need good Python support to run tests. On production, the features will be evaluated in a Go server, and Rego's Go API is feature complete. So we figured we could help fill in the gaps of the Python bindings.

@paulolieuthier paulolieuthier deleted the python-add-extension branch February 25, 2026 22:25
@paulolieuthier
Copy link
Contributor Author

BTW, are you planning to release a new version? Or should we just pull from main?

@anakrish
Copy link
Collaborator

BTW, are you planning to release a new version? Or should we just pull from main?

I will make a release next week once #582 also goes in.
Note that we are pivoting to a Rego Virtual Machine based evalution of different policy languages.
https://anakrish.github.io/rego-virtual-machine-playground/

The RVM is currently exposed to python; we will likely need to implement extension capability in the VM instances as well. So maybe it might be beneficial to maintaing a global table of extensions as opposed to per Engine/VM instance.

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