Install & Compatibility
Where this runs
tested against v0.0.41 · 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
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 114MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 12.3s · import 0.000s · 112MB
115MB installed
● package 115MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
create_dynamic_rest_api_endpoint_from_json
✓ from nsj_rest_lib2 import create_dynamic_rest_api_endpoint_from_json
✗ from nsj_rest_lib2 import create_dynamic_rest_api_endpoint_from_json
This quickstart demonstrates how to define an Endpoint Definition Language (EDL) configuration in JSON, use `create_dynamic_rest_api_endpoint_from_json` to create a dynamic endpoint object, and then `register_route` to add it to a Flask application. It includes a minimal Flask app and a dynamically created mock module to make the example runnable and testable. To run, save as a Python file and execute `python your_file.py`. Then, access `http://127.0.0.1:5000/api/v1/dynamic-resource` in your browser or with `curl`.
import sys
from types import ModuleType
from flask import Flask
from nsj_rest_lib2.register import register_route
from nsj_rest_lib2.util import create_dynamic_rest_api_endpoint_from_json
import os
# --- Step 1: Define your endpoint logic ---
# In a real application, 'my_app_endpoints' would be a real .py file
# and MyEndpointClass would be a class defined within it.
class MyEndpointClass:
def my_dynamic_method(self):
"""A simple method to be called by the dynamic route."""
return {"message": "Hello from nsj-rest-lib2 dynamic endpoint!"}, 200
# Dynamically add this class to a mock module in sys.modules
# This allows create_dynamic_rest_api_endpoint_from_json to find it
# without needing an actual file on disk for this quickstart example.
mock_module_name = 'my_app_endpoints'
if mock_module_name not in sys.modules:
sys.modules[mock_module_name] = ModuleType(mock_module_name)
setattr(sys.modules[mock_module_name], 'MyEndpointClass', MyEndpointClass)
# --- Step 2: Initialize Flask application ---
app = Flask(__name__)
app.secret_key = os.environ.get('FLASK_SECRET_KEY', 'a_super_secret_key_for_dev') # Required for some Flask extensions
# --- Step 3: Define the declarative route configuration (EDL) ---
route_config_json = {
"uri": "/api/v1/dynamic-resource",
"http_method": "GET",
"endpoint_module": mock_module_name, # References the mock module
"endpoint_class_name": "MyEndpointClass", # Class containing the method
"endpoint_method_name": "my_dynamic_method", # Method to be called
"request_body_model_name": None,
"response_body_model_name": None,
"query_string_model_name": None,
"path_params_model_name": None,
"header_params_model_name": None,
"jwt_roles": [],
"jwt_allowed": False,
"jwt_required": False
}
# --- Step 4: Create and register the dynamic endpoint ---
dynamic_endpoint = create_dynamic_rest_api_endpoint_from_json(route_config_json)
register_route(app, dynamic_endpoint)
# --- Step 5: Run the Flask application (for demonstration) ---
# In a production environment, use a WSGI server like Gunicorn or Waitress.
if __name__ == '__main__':
print("\nFlask application running at http://127.0.0.1:5000")
print("Test with: curl http://127.0.0.1:5000/api/v1/dynamic-resource")
app.run(debug=True, port=5000)
Debug
Known issues
breakingThe library is in version `0.0.x`, indicating it's in early development. API interfaces, especially the structure of the declarative JSON (EDL), may change frequently and without major version bumps. Always review release notes when upgrading.fixPin your dependency to a specific patch version (`nsj-rest-lib2==0.0.41`) and thoroughly test after any upgrade. Consult the GitHub repository for the latest EDL schema documentation.
affects: All `0.0.x` versions
gotchaIncorrectly specified `endpoint_module`, `endpoint_class_name`, or `endpoint_method_name` in the EDL JSON will lead to runtime errors when the dynamic route is accessed, as the library won't be able to locate and invoke the specified Python code.fixEnsure the module is discoverable on `sys.path`, and the class/method names precisely match their definitions, including case sensitivity. Verify that the module can be `importlib.import_module`'d.
affects: All versions
gotchaThe declarative JSON (EDL) for defining routes is validated using Pydantic. Any deviation from the expected schema, such as missing required fields or incorrect data types, will result in `pydantic.error_wrappers.ValidationError` during endpoint creation.fixCarefully review the required fields and their types according to the library's internal `DynamicRouteConfigDTO` or official examples. Ensure all mandatory fields like `uri`, `http_method`, `endpoint_module`, `endpoint_class_name`, and `endpoint_method_name` are present and correctly formatted.
affects: All versions
Upgrade
Version history
0.0.41latest on PyPI · released Mar 13, 2026
Audit
Dependencies
nsj-processorrequiredRequired for processing Endpoint Definition Language (EDL) configurations.
FlaskrequiredCore web framework for handling HTTP requests.
Flask-CorsrequiredRequired for Cross-Origin Resource Sharing (CORS) support.
Flask-RESTfulrequiredExtension for quickly building REST APIs with Flask.
pydanticrequiredUsed for data validation of models and configurations.
nsj-web-toolsrequiredAnother internal Nasajon library providing web utilities.