
Security News
Official Go SDK for MCP in Development, Stable Release Expected in August
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.
exposedfunctionality
Advanced tools
ExposedFunctionality is a Python library designed to facilitate the interaction between backend code and frontend interfaces. It enables developers to expose backend methods and variables in a structured and secure way, making it easier to integrate with front-end systems or API endpoints. This library is particularly useful in scenarios where backend logic needs to be accessed or manipulated from a front-end application or through web API calls.
To install ExposedFunctionality, use pip:
pip install exposedfunctionality
To expose a backend function, use the exposed_method
decorator. This allows you to specify metadata such as the method's name, input parameters, and output parameters.
from exposedfunctionality import exposed_method
@exposed_method(name="calculate_sum", inputs=[{"name": "a", "type": "int"}, {"name": "b", "type": "int"}], outputs=[{"name": "result", "type": "int"}])
def add(a, b):
"""Calculate the sum of two numbers."""
return a + b
To retrieve exposed methods from an object (either an instance or a class), you can use the get_exposed_methods
function provided by the exposedfunctionality
package. This function scans an object for methods that have been decorated with @exposed_method
and collects them into a dictionary, making it easy to access and utilize these methods programmatically, such as when dynamically generating API endpoints or interfaces.
Consider the following class with an exposed method:
from exposedfunctionality import exposed_method, get_exposed_methods
class MathOperations:
@exposed_method(name="add", inputs=[{"name": "a", "type": "int"}, {"name": "b", "type": "int"}], outputs=[{"name": "sum", "type": "int"}])
def add_numbers(self, a, b):
"""Add two numbers."""
return a + b
To retrieve the exposed methods from an instance of MathOperations
, you would do the following:
math_operations = MathOperations()
exposed_methods = get_exposed_methods(math_operations)
for method_name, (method, metadata) in exposed_methods.items():
print(f"Method Name: {method_name}")
print(f"Metadata: {metadata}")
print(f"Function: {method}")
print("-----")
This will output something like:
Method Name: add
Metadata: {'name': 'add', 'input_params': [{'name': 'a', 'type': 'int', 'positional': True}, {'name': 'b', 'type': 'int', 'positional': True}], 'output_params': [{'name': 'sum', 'type': 'int'}], 'docstring': {'summary': 'Add two numbers.', 'original': 'Add two numbers.', 'input_params': [], 'output_params': [], 'exceptions': {}}}
Function: <bound method MathOperations.add_numbers of <__main__.MathOperations object at 0x7fcd1830f1f0>>
-----
The get_exposed_methods
function is particularly useful for frameworks or libraries that need to dynamically discover which methods are available for external access, such as in web frameworks for automatically generating API routes or in GUI applications for dynamically creating user interface elements based on the backend logic.
Expose backend variables using the ExposedValue
descriptor. This enables type checking, default values, and change event handling.
from exposedfunctionality.variables import ExposedValue
class Calculator:
result = ExposedValue("result", default=0, type_=int)
calculator = Calculator()
calculator.result = 5 # Sets the result and enforces type checking
You can listen to changes on an exposed variable by attaching an OnChangeEvent
:
def on_result_change(new_value, old_value):
print(f"Result changed from {old_value} to {new_value}")
calculator.result.add_on_change_callback(on_result_change)
calculator.result = 10 # Triggers the on_result_change callback
Use middleware functions to process or validate variable values before they are set:
from exposedfunctionality.variables.middleware import min_max_clamp
class RestrictedCalculator:
result = ExposedValue("result", default=0, type_=int, valuechecker=[min_max_clamp],max=100)
restricted_calculator = RestrictedCalculator()
restricted_calculator.result = 150 # The value will be clamped to 100
Contributions are welcome! Please feel free to submit pull requests, report bugs, or suggest features.
This project is licensed under the MIT License. See the LICENSE file for details.
FAQs
tool to expose functionalities to multiple tools
We found that exposedfunctionality demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.
Security News
New research reveals that LLMs often fake understanding, passing benchmarks but failing to apply concepts or stay internally consistent.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.